Skip to content

Removing body on GET requests #1130

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

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private DefaultSdkHttpFullRequest(Builder builder) {
this.queryParameters = deepUnmodifiableMap(builder.queryParameters, () -> new LinkedHashMap<>());
this.httpMethod = Validate.paramNotNull(builder.httpMethod, "method");
this.headers = deepUnmodifiableMap(builder.headers, () -> new TreeMap<>(String.CASE_INSENSITIVE_ORDER));
this.contentStreamProvider = builder.contentStreamProvider;
this.contentStreamProvider = standardizeBody(builder.contentStreamProvider);
}

private String standardizeProtocol(String protocol) {
Expand Down Expand Up @@ -97,6 +97,14 @@ private Integer standardizePort(Integer port) {
return port;
}

private ContentStreamProvider standardizeBody(ContentStreamProvider contentStreamProvider) {
if (httpMethod.equals(SdkHttpMethod.GET)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also apply to DELETE and HEAD?

return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we warn or throw an exception if there was some body that got ignored because of the method?

}

return contentStreamProvider;
}

@Override
public String protocol() {
return protocol;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

import java.io.ByteArrayInputStream;
import java.util.AbstractMap;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -34,6 +35,16 @@
* interfaces.
*/
public class SdkHttpRequestResponseTest {

@Test
public void contentStreamProviderNullOnGets() {
assertThat(validRequestBuilder().contentStreamProvider(() -> new ByteArrayInputStream("test".getBytes()))
.method(SdkHttpMethod.GET)
.build()
.contentStreamProvider())
.isNotPresent();
}

@Test
public void optionalValuesAreOptional() {
assertThat(validRequest().contentStreamProvider()).isNotPresent();
Expand Down