Skip to content
Open
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 @@ -178,7 +178,7 @@ private void writeMultipartEnd(PrintWriter writer) {

private boolean requiresFormEncodingContentTypeHeader(OperationRequest request) {
return request.getHeaders().get(HttpHeaders.CONTENT_TYPE) == null && isPutPostOrPatch(request)
&& !includeParametersInUri(request);
&& request.getContent().length > 0 && !includeParametersInUri(request);
}

private Map<String, String> header(String name, String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,22 @@ void deleteWithQueryString(OperationBuilder operationBuilder, AssertableSnippets
.isHttpRequest((request) -> request.delete("/foo?a=alpha&b=bravo").header("Host", "localhost"));
}

@RenderedSnippetTest
void postFormUrlEncodedRequestIsDocumentedWhenContentTypeIsExplicit(OperationBuilder operationBuilder,
AssertableSnippets snippets) throws IOException {
String body = "a=alpha&b=bravo";
new HttpRequestSnippet().document(operationBuilder.request("http://localhost/foo")
.method("POST")
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE)
.content(body)
.build());
assertThat(snippets.httpRequest()).isHttpRequest((request) -> request.post("/foo")
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE)
.header(HttpHeaders.HOST, "localhost")
.header(HttpHeaders.CONTENT_LENGTH, body.getBytes().length)
.content(body));
}

private String createPart(String content) {
return this.createPart(content, true);
}
Expand Down
Loading