Skip to content

Commit f15619a

Browse files
author
Willi Schönborn
committed
Added curl request formatter
Fixes zalando#160
1 parent eeb8cd7 commit f15619a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,25 @@ public void shouldLogRequestWithoutBody() throws IOException {
4545
assertThat(curl, is("curl -v -X GET -H 'Accept: application/json' 'http://localhost/test'"));
4646
}
4747

48+
@Test
49+
public void shouldEscape() throws IOException {
50+
final String correlationId = "c9408eaa-677d-11e5-9457-10ddb1ee7671";
51+
final HttpRequest request = MockHttpRequest.create()
52+
.withProtocolVersion("HTTP/1.0")
53+
.withOrigin(Origin.REMOTE)
54+
.withPath("/test")
55+
.withQuery("char='")
56+
.withHeaders(MockHeaders.of(
57+
"Foo'Bar", "Baz"
58+
))
59+
.withBodyAsString("Hello, 'world'!");
60+
61+
final HttpLogFormatter unit = new CurlHttpLogFormatter();
62+
final String curl = unit.format(new SimplePrecorrelation<>(correlationId, request));
63+
64+
assertThat(curl, is("curl -v -X GET -H 'Foo\\'Bar: Baz' -d 'Hello, \\'world\\'!' 'http://localhost/test?char=\\''"));
65+
}
66+
4867
@Test
4968
public void shouldDelegateLogResponse() throws IOException {
5069
final HttpLogFormatter fallback = mock(HttpLogFormatter.class);

0 commit comments

Comments
 (0)