Skip to content

Commit a6e7a84

Browse files
author
Willi Schönborn
committed
Incorporated feedback
1 parent f15619a commit a6e7a84

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

logbook-core/src/main/java/org/zalando/logbook/CurlHttpLogFormatter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public String format(final Precorrelation<HttpRequest> precorrelation) throws IO
3232
command.add("-X");
3333
command.add(request.getMethod());
3434

35+
command.add(quote(request.getRequestUri()));
36+
3537
request.getHeaders().forEach((header, values) -> {
3638
values.forEach(value -> {
3739
command.add("-H");
@@ -42,12 +44,10 @@ public String format(final Precorrelation<HttpRequest> precorrelation) throws IO
4244
final String body = request.getBodyAsString();
4345

4446
if (!body.isEmpty()) {
45-
command.add("-d");
47+
command.add("--data-binary");
4648
command.add(quote(body));
4749
}
4850

49-
command.add(quote(request.getRequestUri()));
50-
5151
return command.stream().collect(joining(" "));
5252
}
5353

logbook-core/src/test/java/org/zalando/logbook/CurlHttpLogFormatterTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void shouldLogRequest() throws IOException {
2929
final HttpLogFormatter unit = new CurlHttpLogFormatter();
3030
final String curl = unit.format(new SimplePrecorrelation<>(correlationId, request));
3131

32-
assertThat(curl, is("curl -v -X GET -H 'Accept: application/json' -H 'Content-Type: text/plain' -d 'Hello, world!' 'http://localhost/test?limit=1'"));
32+
assertThat(curl, is("curl -v -X GET 'http://localhost/test?limit=1' -H 'Accept: application/json' -H 'Content-Type: text/plain' --data-binary 'Hello, world!'"));
3333
}
3434

3535
@Test
@@ -42,7 +42,7 @@ public void shouldLogRequestWithoutBody() throws IOException {
4242
final HttpLogFormatter unit = new CurlHttpLogFormatter();
4343
final String curl = unit.format(new SimplePrecorrelation<>(correlationId, request));
4444

45-
assertThat(curl, is("curl -v -X GET -H 'Accept: application/json' 'http://localhost/test'"));
45+
assertThat(curl, is("curl -v -X GET 'http://localhost/test' -H 'Accept: application/json'"));
4646
}
4747

4848
@Test
@@ -56,12 +56,12 @@ public void shouldEscape() throws IOException {
5656
.withHeaders(MockHeaders.of(
5757
"Foo'Bar", "Baz"
5858
))
59-
.withBodyAsString("Hello, 'world'!");
59+
.withBodyAsString("{\"message\":\"Hello, 'world'!\"}");
6060

6161
final HttpLogFormatter unit = new CurlHttpLogFormatter();
6262
final String curl = unit.format(new SimplePrecorrelation<>(correlationId, request));
6363

64-
assertThat(curl, is("curl -v -X GET -H 'Foo\\'Bar: Baz' -d 'Hello, \\'world\\'!' 'http://localhost/test?char=\\''"));
64+
assertThat(curl, is("curl -v -X GET 'http://localhost/test?char=\\'' -H 'Foo\\'Bar: Baz' --data-binary '{\"message\":\"Hello, \\'world\\'!\"}'"));
6565
}
6666

6767
@Test

0 commit comments

Comments
 (0)