Skip to content

Commit

Permalink
chore: process form and body params for all methods except GET (#799)
Browse files Browse the repository at this point in the history
* chore: process form and body params for all methods except GET

* chore: setting contentType in ValidationClientTest

* chore: check contentType only for put and post
  • Loading branch information
tiwarishubham635 committed Jun 18, 2024
1 parent f8ffa76 commit cc196de
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
4 changes: 1 addition & 3 deletions src/main/java/com/twilio/http/NetworkHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ public Response makeRequest(final Request request) {
}
}

if (method == HttpMethod.POST) {
// TODO: It will be removed after one RC Release.
if (request.getContentType() == null) request.setContentType(EnumConstants.ContentType.FORM_URLENCODED);
if (method == HttpMethod.POST || method == HttpMethod.PUT) {
if (EnumConstants.ContentType.JSON.getValue().equals(request.getContentType().getValue())) {
HttpEntity entity = new StringEntity(request.getBody(), ContentType.APPLICATION_JSON);
builder.setEntity(entity);
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/com/twilio/http/ValidationClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public ValidationClient(final String accountSid,

final PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
connectionManager.setDefaultSocketConfig(socketConfig);
/*
/*
* Example: Lets say client has one server.
* There are 4 servers on edge handling client request.
* Each request takes on an average 500ms (2 request per second)
Expand Down Expand Up @@ -178,9 +178,7 @@ public Response makeRequest(Request request) {
}

HttpMethod method = request.getMethod();
if (method == HttpMethod.POST) {
// TODO: It will be removed after one RC Release.
if (request.getContentType() == null) request.setContentType(EnumConstants.ContentType.FORM_URLENCODED);
if (method == HttpMethod.POST || method == HttpMethod.PUT) {
if (EnumConstants.ContentType.JSON.getValue().equals(request.getContentType().getValue())) {
HttpEntity entity = new StringEntity(request.getBody(), ContentType.APPLICATION_JSON);
builder.setEntity(entity);
Expand Down
1 change: 1 addition & 0 deletions src/test/java/com/twilio/http/ValidationClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ private void exerciseHttpMethod(final HttpMethod httpMethod) throws Exception {
final HttpUrl url = server.url(path);
final ValidationClient client = new ValidationClient("dummy-sid1", "dummy-sid2", "dummy-signing-key", keyPair.getPrivate());
final Request request = new Request(httpMethod, url.url().toString());
request.setContentType(EnumConstants.ContentType.FORM_URLENCODED);
final Response response = client.makeRequest(request);
assertEquals(200, response.getStatusCode());
final RecordedRequest recordedRequest = server.takeRequest();
Expand Down

0 comments on commit cc196de

Please sign in to comment.