Commit 4a1e637b by Dave Syer

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
parent d19a6f26
...@@ -258,7 +258,8 @@ public class SimpleHostRoutingFilter extends ZuulFilter { ...@@ -258,7 +258,8 @@ public class SimpleHostRoutingFilter extends ZuulFilter {
HttpRequest httpRequest; HttpRequest httpRequest;
int contentLength = request.getContentLength(); int contentLength = request.getContentLength();
InputStreamEntity entity = new InputStreamEntity(requestEntity, contentLength, InputStreamEntity entity = new InputStreamEntity(requestEntity, contentLength,
ContentType.create(request.getContentType())); request.getContentType() != null
? ContentType.create(request.getContentType()) : null);
switch (verb.toUpperCase()) { switch (verb.toUpperCase()) {
case "POST": case "POST":
HttpPost httpPost = new HttpPost(uri + this.helper.getQueryString(params)); HttpPost httpPost = new HttpPost(uri + this.helper.getQueryString(params));
......
...@@ -158,6 +158,17 @@ public class SampleZuulProxyApplicationTests extends ZuulProxyTestBase { ...@@ -158,6 +158,17 @@ public class SampleZuulProxyApplicationTests extends ZuulProxyTestBase {
} }
@Test @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() { public void ribbonCommandForbidden() {
ResponseEntity<String> result = new TestRestTemplate().exchange( ResponseEntity<String> result = new TestRestTemplate().exchange(
"http://localhost:" + this.port + "/simple/throwexception/403", "http://localhost:" + this.port + "/simple/throwexception/403",
...@@ -223,6 +234,12 @@ class SampleZuulProxyApplication extends ZuulProxyTestBase.AbstractZuulProxyAppl ...@@ -223,6 +234,12 @@ class SampleZuulProxyApplication extends ZuulProxyTestBase.AbstractZuulProxyAppl
return request.getRequestURI(); 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") @RequestMapping("/add-header")
public ResponseEntity<String> addHeader(HttpServletRequest request) { public ResponseEntity<String> addHeader(HttpServletRequest request) {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment