Improve handling of Host header so a preprocessor can remove it

Previously, the Host header was treated specially in the HTTP request
snippet. If no Host header was specified, one would always be added
prior to producing the snippet. This ensured that the snippet was
valid (an HTTP 1.1 request must include a Host header), but came at
the cost of some confusion about why a preprocessor could not remove
it.

This commit updates the special treatment of the Host header so that
it's now performed in a central location so that all of the snippets
can benefit from a Host header being added if one isn't provided.
The handling of the Content-Length header has also been reworked so
that it's performed in the same location. The curl request snippet
has been updated so that it doesn't include setting the Host header
on the command line; it's unnecessary as curl will automatically
include a Host header in the request. The documentation of the
Host header's special treatment (made in 2fc0420) that noted that it
was unaffected by preprocessing has been reverted.

Closes gh-134
This commit is contained in:
Andy Wilkinson
2015-09-28 15:16:20 +01:00
parent 5da4bee3c6
commit 535bea24f9
23 changed files with 466 additions and 139 deletions

View File

@@ -77,10 +77,6 @@ different replacement can also be specified if you wish.
`removeHeaders` on `Preprocessors` removes any occurrences of the named headers
from the request or response.
NOTE: For an HTTP 1.1 request to be valid it must contain a `Host` header. Therefore,
irrespective of any preprocessing, the default HTTP request snippet will always contain a
`Host` header.
[[customizing-requests-and-responses-preprocessors-replace-patterns]]

View File

@@ -388,8 +388,7 @@ call that is being documented
| `http-request.adoc`
| Contains the HTTP request that is equivalent to the `MockMvc` call that is being
documented. HTTP 1.1 requires a `Host` header. If you do not provide one via the
`MockMvc` API the snippet will add one automatically.
documented
| `http-response.adoc`
| Contains the HTTP response that was returned