Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: process form and body params for all methods except GET #799

Merged
merged 3 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading