Skip to content

Commit

Permalink
Merge pull request #294 from joseapontesPrisma/feature/httpQueryDelete
Browse files Browse the repository at this point in the history
HttpQuery: Allow using http method DELETE.
  • Loading branch information
ar authored Jan 3, 2024
2 parents ed7c9b1 + 429a83b commit cfaaf2a
Showing 1 changed file with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.*;
import java.util.function.Consumer;

import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
Expand Down Expand Up @@ -357,23 +358,31 @@ private String getURL (Context ctx) {
}

private HttpRequestBase getHttpRequest(Context ctx) {
Consumer<HttpEntityEnclosingRequestBase> setBody = (HttpEntityEnclosingRequestBase request) -> {
String payload = ctx.getString(requestName);
if (payload != null) {
request.setEntity(new StringEntity(payload, getContentType(ctx)));
}
};
String url = getURL(ctx);
String payload;
switch (ctx.getString(methodName)) {
case "POST":
HttpPost post = new HttpPost(url);
payload = ctx.getString(requestName);
if (payload != null)
post.setEntity(new StringEntity(payload, getContentType(ctx)));
setBody.accept(post);
return post;
case "PUT":
HttpPut put = new HttpPut(url);
payload = ctx.getString(requestName);
if (payload != null)
put.setEntity(new StringEntity(payload, getContentType(ctx)));
setBody.accept(put);
return put;
case "GET":
return new HttpGet(url);
case "DELETE":
return new HttpDelete(url);
case "PATCH":
HttpPatch patch = new HttpPatch(url);
setBody.accept(patch);
return patch;
}
ctx.log ("Invalid request method");
return null;
Expand Down

0 comments on commit cfaaf2a

Please # to comment.