Fix content type when missing from incoming request

If there is no content type incoming, then it should be
absent in the outgoing request (not "null").

Fixes gh-1037
This commit is contained in:
Dave Syer
2016-05-24 09:01:34 +01:00
parent d19a6f2615
commit 4a1e637b83
2 changed files with 19 additions and 1 deletions

View File

@@ -258,7 +258,8 @@ public class SimpleHostRoutingFilter extends ZuulFilter {
HttpRequest httpRequest;
int contentLength = request.getContentLength();
InputStreamEntity entity = new InputStreamEntity(requestEntity, contentLength,
ContentType.create(request.getContentType()));
request.getContentType() != null
? ContentType.create(request.getContentType()) : null);
switch (verb.toUpperCase()) {
case "POST":
HttpPost httpPost = new HttpPost(uri + this.helper.getQueryString(params));

View File

@@ -157,6 +157,17 @@ public class SampleZuulProxyApplicationTests extends ZuulProxyTestBase {
assertEquals("/query?foo=weird#chars", result.getBody());
}
@Test
public void simpleHostRouteWithContentType() {
this.routes.addRoute("/self/**", "http://localhost:" + this.port + "/");
this.endpoint.reset();
ResponseEntity<String> result = new TestRestTemplate().exchange(
"http://localhost:" + this.port + "/self/content-type", HttpMethod.POST,
new HttpEntity<>((Void) null), String.class);
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals("<NONE>", result.getBody());
}
@Test
public void ribbonCommandForbidden() {
ResponseEntity<String> result = new TestRestTemplate().exchange(
@@ -223,6 +234,12 @@ class SampleZuulProxyApplication extends ZuulProxyTestBase.AbstractZuulProxyAppl
return request.getRequestURI();
}
@RequestMapping("/content-type")
public String contentType(HttpServletRequest request) {
String header = request.getHeader("Content-Type");
return header == null ? "<NONE>" : header;
}
@RequestMapping("/add-header")
public ResponseEntity<String> addHeader(HttpServletRequest request) {
HttpHeaders headers = new HttpHeaders();