Commit 658f29ed by Ryan Baxter

Merge remote-tracking branch 'Upstream/1.2.x' into feign-retry

parents fad2c5d4 19556dc2
......@@ -16,17 +16,16 @@
package org.springframework.cloud.netflix.zuul.filters.post;
import lombok.extern.apachecommons.CommonsLog;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import java.util.zip.GZIPInputStream;
import javax.servlet.http.HttpServletResponse;
import org.springframework.util.ReflectionUtils;
import com.netflix.config.DynamicBooleanProperty;
import com.netflix.config.DynamicIntProperty;
import com.netflix.config.DynamicPropertyFactory;
......@@ -37,8 +36,6 @@ import com.netflix.zuul.constants.ZuulHeaders;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.util.HTTPRequestUtils;
import lombok.extern.apachecommons.CommonsLog;
/**
* @author Spencer Gibb
*/
......@@ -56,6 +53,17 @@ public class SendResponseFilter extends ZuulFilter {
private static DynamicBooleanProperty SET_CONTENT_LENGTH = DynamicPropertyFactory
.getInstance()
.getBooleanProperty(ZuulConstants.ZUUL_SET_CONTENT_LENGTH, false);
private boolean useServlet31 = true;
public SendResponseFilter() {
super();
// To support Servlet API 3.0.1 we need to check if setcontentLengthLong exists
try {
HttpServletResponse.class.getMethod("setContentLengthLong");
} catch(NoSuchMethodException e) {
useServlet31 = false;
}
}
@Override
public String filterType() {
......@@ -210,10 +218,21 @@ public class SendResponseFilter extends ZuulFilter {
// Only inserts Content-Length if origin provides it and origin response is not
// gzipped
if (SET_CONTENT_LENGTH.get()) {
if (contentLength != null && !ctx.getResponseGZipped()) {
servletResponse.setContentLengthLong(contentLength);
if ( contentLength != null && !ctx.getResponseGZipped()) {
if(useServlet31) {
servletResponse.setContentLengthLong(contentLength);
} else {
//Try and set some kind of content length if we can safely convert the Long to an int
if (isLongSafe(contentLength)) {
servletResponse.setContentLength(contentLength.intValue());
}
}
}
}
}
private boolean isLongSafe(long value) {
return value <= Integer.MAX_VALUE && value >= Integer.MIN_VALUE;
}
}
......@@ -170,7 +170,6 @@ public class FormBodyWrapperFilter extends ZuulFilter {
return this.contentLength;
}
@Override
public long getContentLengthLong() {
return getContentLength();
}
......
......@@ -16,28 +16,25 @@
package org.springframework.cloud.netflix.zuul.filters.route;
import lombok.extern.apachecommons.CommonsLog;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.cloud.netflix.ribbon.support.RibbonRequestCustomizer;
import org.springframework.cloud.netflix.zuul.filters.ProxyRequestHelper;
import org.springframework.http.HttpStatus;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.util.MultiValueMap;
import com.netflix.client.ClientException;
import com.netflix.hystrix.exception.HystrixRuntimeException;
import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import lombok.extern.apachecommons.CommonsLog;
@CommonsLog
public class RibbonRoutingFilter extends ZuulFilter {
......@@ -45,6 +42,7 @@ public class RibbonRoutingFilter extends ZuulFilter {
protected ProxyRequestHelper helper;
protected RibbonCommandFactory<?> ribbonCommandFactory;
protected List<RibbonRequestCustomizer> requestCustomizers;
private boolean useServlet31 = true;
public RibbonRoutingFilter(ProxyRequestHelper helper,
RibbonCommandFactory<?> ribbonCommandFactory,
......@@ -52,6 +50,12 @@ public class RibbonRoutingFilter extends ZuulFilter {
this.helper = helper;
this.ribbonCommandFactory = ribbonCommandFactory;
this.requestCustomizers = requestCustomizers;
// To support Servlet API 3.0.1 we need to check if getcontentLengthLong exists
try {
HttpServletResponse.class.getMethod("getContentLengthLong");
} catch(NoSuchMethodException e) {
useServlet31 = false;
}
}
public RibbonRoutingFilter(RibbonCommandFactory<?> ribbonCommandFactory) {
......@@ -119,8 +123,10 @@ public class RibbonRoutingFilter extends ZuulFilter {
// remove double slashes
uri = uri.replace("//", "/");
long contentLength = useServlet31 ? request.getContentLengthLong(): request.getContentLength();
return new RibbonCommandContext(serviceId, verb, uri, retryable, headers, params,
requestEntity, this.requestCustomizers, request.getContentLengthLong());
requestEntity, this.requestCustomizers, contentLength);
}
protected ClientHttpResponse forward(RibbonCommandContext context) throws Exception {
......
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