diff --git a/src/main/java/org/takes/servlet/RqFrom.java b/src/main/java/org/takes/servlet/RqFrom.java index ce0ea83b7..c357b1421 100644 --- a/src/main/java/org/takes/servlet/RqFrom.java +++ b/src/main/java/org/takes/servlet/RqFrom.java @@ -38,6 +38,12 @@ * @since 2.0 */ final class RqFrom implements Request { + + /** + * Host key. + */ + private static String HOST_KEY = "host"; + /** * Servlet request. */ @@ -58,17 +64,25 @@ public Iterable head() { final Collection names = Collections.list( this.sreq.getHeaderNames() ); - if (!names.stream().anyMatch("host"::equalsIgnoreCase)) { + if (names.stream().noneMatch(RqFrom.HOST_KEY::equalsIgnoreCase)) { head.add(new HttpHost(this.sreq).toString()); } names.forEach( - header -> head.add( - String.format( - "%s: %s", - header, - this.sreq.getHeader(header) - ) - ) + header -> { + final String cleanheader; + if (header.equals(RqFrom.HOST_KEY)) { + cleanheader = "Host"; + } else { + cleanheader = header; + } + head.add( + String.format( + "%s: %s", + cleanheader, + this.sreq.getHeader(header) + ) + ); + } ); head.add( String.format( diff --git a/src/test/java/org/takes/facets/hamcrest/HmHeaderTest.java b/src/test/java/org/takes/facets/hamcrest/HmHeaderTest.java index bc6f3a478..72945411d 100644 --- a/src/test/java/org/takes/facets/hamcrest/HmHeaderTest.java +++ b/src/test/java/org/takes/facets/hamcrest/HmHeaderTest.java @@ -162,8 +162,8 @@ void testMismatchMessage() { MatcherAssert.assertThat( description.toString(), Matchers.equalTo(new StringBuilder() - .append("header was: equalToIgnoringCase") - .append("(\"content-type\") -> values: <[image/png]>") + .append("header was: a string equal to ") + .append("\"content-type\" ignoring case -> values: <[image/png]>") .toString() ) ); diff --git a/src/test/java/org/takes/servlet/RqFromTest.java b/src/test/java/org/takes/servlet/RqFromTest.java index d7e5bbffa..783da5785 100644 --- a/src/test/java/org/takes/servlet/RqFromTest.java +++ b/src/test/java/org/takes/servlet/RqFromTest.java @@ -175,6 +175,7 @@ void containsHostAndPortInHeader() throws Exception { @Test void containsContentInRequestBody() throws IOException { + final String method = "POST /content-test"; final String content = "My name is neo!"; MatcherAssert.assertThat( "Can't add a body to servlet request", @@ -182,7 +183,7 @@ void containsContentInRequestBody() throws IOException { new RqFrom( new HttpServletRequestFake( new RqFake( - new ListOf<>(RqFromTest.EOL), + new ListOf<>(method), content ) )