Commit c5d95ca8 by Jin Zhang Committed by Spencer Gibb

SendErrorFilter: put response code into RequestContext, keep consistent with normal cases (#2004)

parent 9e180b8b
......@@ -87,6 +87,7 @@ public class SendErrorFilter extends ZuulFilter {
if (dispatcher != null) {
ctx.set(SEND_ERROR_FILTER_RAN, true);
if (!ctx.getResponse().isCommitted()) {
ctx.setResponseStatusCode(exception.nStatusCode);
dispatcher.forward(request, ctx.getResponse());
}
}
......
......@@ -29,6 +29,7 @@ import org.springframework.mock.web.MockHttpServletResponse;
import com.netflix.zuul.context.RequestContext;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
......@@ -82,4 +83,17 @@ public class SendErrorFilterTests {
filter.run();
assertFalse("shouldFilter returned true", filter.shouldFilter());
}
@Test
public void setResponseCode() {
SendErrorFilter filter = createSendErrorFilter(new MockHttpServletRequest());
filter.run();
RequestContext ctx = RequestContext.getCurrentContext();
int resCode = ctx.getResponse().getStatus();
int ctxCode = ctx.getResponseStatusCode();
assertEquals("invalid response code: " + resCode, HttpStatus.NOT_FOUND.value(), resCode);
assertEquals("invalid response code in RequestContext: " + ctxCode, resCode, ctxCode);
}
}
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