Include query string in curl request snippets
This commit is contained in:
@@ -120,7 +120,7 @@ public abstract class CurlDocumentation {
|
||||
MockHttpServletRequest request = this.result.getRequest();
|
||||
this.writer.print(String.format("curl %s://%s:%d%s", request.getScheme(),
|
||||
request.getRemoteHost(), request.getRemotePort(),
|
||||
request.getRequestURI()));
|
||||
getRequestUriWithQueryString(request)));
|
||||
|
||||
if (this.curlConfiguration.isIncludeResponseHeaders()) {
|
||||
this.writer.print(" -i");
|
||||
@@ -145,6 +145,11 @@ public abstract class CurlDocumentation {
|
||||
this.writer.println();
|
||||
}
|
||||
|
||||
private String getRequestUriWithQueryString(MockHttpServletRequest request) {
|
||||
return request.getQueryString() != null ? request.getRequestURI() + "?"
|
||||
+ request.getQueryString() : request.getRequestURI();
|
||||
}
|
||||
|
||||
private String getContent(MockHttpServletRequest request) throws IOException {
|
||||
StringWriter bodyWriter = new StringWriter();
|
||||
FileCopyUtils.copy(request.getReader(), bodyWriter);
|
||||
|
||||
@@ -95,6 +95,25 @@ public class CurlDocumentationTests {
|
||||
hasItem("$ curl http://localhost:80/foo -i -d 'content'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestWitUriQueryString() throws IOException {
|
||||
documentCurlRequest("request-with-uri-query-string").handle(
|
||||
new StubMvcResult(new MockHttpServletRequest("GET", "/foo?param=value"),
|
||||
null));
|
||||
assertThat(requestSnippetLines("request-with-uri-query-string"),
|
||||
hasItem("$ curl http://localhost:80/foo?param=value -i"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestWithQueryString() throws IOException {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
|
||||
request.setQueryString("param=value");
|
||||
documentCurlRequest("request-with-query-string").handle(
|
||||
new StubMvcResult(request, null));
|
||||
assertThat(requestSnippetLines("request-with-query-string"),
|
||||
hasItem("$ curl http://localhost:80/foo?param=value -i"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestWithHeaders() throws IOException {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
|
||||
|
||||
Reference in New Issue
Block a user