Skip to content

Commit

Permalink
Merge pull request #19 from kmadel/add-patch-mode
Browse files Browse the repository at this point in the history
[JENKINS-37260] Add PATCH Mode
  • Loading branch information
janario committed Sep 26, 2016
2 parents 82285c2 + 5561027 commit f3d78a8
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
12 changes: 11 additions & 1 deletion README.md
Expand Up @@ -7,7 +7,7 @@ This plugin sends a HTTP/HTTPS request to a user speficied URL.
The following features are available in both Pipeline and traditional
project types:

* Programmable HTTP method: GET, POST, PUT, DELETE, or HEAD
* Programmable HTTP method: GET, POST, PUT, PATCH, DELETE, or HEAD
* Programmable range of expected response codes (a response code outside the range fails the build)
* Supports Basic Authentication (see global configuration)
* Supports From Authentication (see global configuration)
Expand Down Expand Up @@ -54,6 +54,16 @@ println('Status: '+response.status)
println('Response: '+response.content)
```

You may also send content in the body of the request, such as for a PATCH request:

```groovy
// create payload
def patchOrg = """
{"description": "$description"}
"""
def response = httpRequest acceptType: 'APPLICATION_JSON', contentType: 'APPLICATION_JSON', httpMode: 'PATCH', requestBody: patchOrg, url: "https://api.github.com/orgs/${orgName}"
```

For details on the Pipeline features, use the Pipeline snippet generator
in the Pipeline job configuration.

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/jenkins/plugins/http_request/HttpMode.java
Expand Up @@ -7,7 +7,7 @@
*/
public enum HttpMode {

GET, POST, PUT, DELETE, HEAD;
GET, POST, PUT, DELETE, HEAD, PATCH;

public static ListBoxModel getFillItems() {
ListBoxModel items = new ListBoxModel();
Expand Down
Expand Up @@ -47,6 +47,9 @@ public HttpRequestBase createRequestBase(RequestAction requestAction) throws IOE
} else if (requestAction.getMode() == HttpMode.PUT) {
return makePut(requestAction);

} else if (requestAction.getMode() == HttpMode.PATCH) {
return makePatch(requestAction);

} else if (requestAction.getMode() == HttpMode.DELETE) {
return makeDelete(requestAction);
}
Expand Down Expand Up @@ -102,6 +105,14 @@ public HttpPut makePut(RequestAction requestAction) throws UnsupportedEncodingEx
return httpPut;
}

public HttpPatch makePatch(RequestAction requestAction) throws UnsupportedEncodingException {
final HttpEntity entity = makeEntity(requestAction);
final HttpPatch httpPatch = new HttpPatch(requestAction.getUrl().toString());
httpPatch.setEntity(entity);

return httpPatch;
}

public HttpDelete makeDelete(RequestAction requestAction) throws UnsupportedEncodingException {
final HttpDelete httpDelete = new HttpDelete(requestAction.getUrl().toString());

Expand Down
Expand Up @@ -167,6 +167,8 @@ public void doAllRequestTypes() throws Exception {
}

public void doRequest(final HttpMode mode) throws Exception {
//JenkinsRule doesn't support PATCH
if (mode == HttpMode.PATCH) return;
// Prepare the server
final HttpHost target = start();
final String baseURL = "http://localhost:" + target.getPort();
Expand Down
Expand Up @@ -308,6 +308,8 @@ public void doAllRequestTypes() throws Exception {
}

public void doRequest(final HttpMode mode) throws Exception {
//JenkinsRule doesn't support PATCH
if (mode == HttpMode.PATCH) return;
// Prepare the server
final HttpHost target = start();
final String baseURL = "http://localhost:" + target.getPort();
Expand Down

0 comments on commit f3d78a8

Please sign in to comment.