From f856edecb6ce74acc858d224467b7e9ea6de4581 Mon Sep 17 00:00:00 2001 From: reger Date: Tue, 23 Dec 2014 02:01:03 +0100 Subject: [PATCH] fix proxy redirect (http status 302) response fixes http://mantis.tokeek.de/view.php?id=517 The url given in bug report uses a gzip input stream which causes the HTTPClient.writeto() throw an IOException due to incomplete input stream. This in turn prevents the 302 reponse to the client browser. By limiting to serve target content just on httpstatus=200 will proxy the header reponse and client browsers redirect settings can be honored. --- source/net/yacy/http/ProxyHandler.java | 27 ++++++++++--------- .../yacy/server/http/HTTPDProxyHandler.java | 6 +++-- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/source/net/yacy/http/ProxyHandler.java b/source/net/yacy/http/ProxyHandler.java index b55754b92..871bcf162 100644 --- a/source/net/yacy/http/ProxyHandler.java +++ b/source/net/yacy/http/ProxyHandler.java @@ -219,19 +219,22 @@ public class ProxyHandler extends AbstractRemoteHandler implements Handler { } else { // no caching /*if (log.isFine()) log.logFine(reqID +" "+ url.toString() + " not cached." + - " StoreError=" + ((storeError==null)?"None":storeError) + - " StoreHTCache=" + storeHTCache + - " SupportError=" + supportError);*/ - convertHeaderToJetty(clientresponse, response); - response.setStatus(statusCode); - - client.writeTo(response.getOutputStream()); + " StoreError=" + ((storeError==null)?"None":storeError) + + " StoreHTCache=" + storeHTCache + + " SupportError=" + supportError);*/ + convertHeaderToJetty(clientresponse, response); + response.setStatus(statusCode); + + if (statusCode == HttpServletResponse.SC_OK) { // continue to serve header to client e.g. HttpStatus = 302 (while skiping content) + client.writeTo(response.getOutputStream()); // may throw exception on httpStatus=302 while gzip encoded inputstream + } + + } + } catch (final SocketException se) { + throw new ServletException("Socket Exception: " + se.getMessage()); + } finally { + client.finish(); } - } catch(final SocketException se) { - throw new ServletException("Socket Exception: " + se.getMessage()); - } finally { - client.finish(); - } // we handled this request, break out of handler chain logProxyAccess(request); diff --git a/source/net/yacy/server/http/HTTPDProxyHandler.java b/source/net/yacy/server/http/HTTPDProxyHandler.java index bdcc2b734..3463a0552 100644 --- a/source/net/yacy/server/http/HTTPDProxyHandler.java +++ b/source/net/yacy/server/http/HTTPDProxyHandler.java @@ -66,6 +66,7 @@ import java.util.logging.FileHandler; import java.util.logging.Level; import java.util.logging.LogManager; import java.util.logging.Logger; +import javax.servlet.http.HttpServletResponse; import net.yacy.cora.document.id.DigestURL; import net.yacy.cora.protocol.ClientIdentification; @@ -572,8 +573,9 @@ public final class HTTPDProxyHandler { " StoreHTCache=" + storeHTCache + " SupportError=" + supportError); -// FileUtils.copy(res.getDataAsStream(), outStream); - client.writeTo(outStream); + if (statusCode == HttpServletResponse.SC_OK) { // continue to serve header to client e.g. HttpStatus = 302 (while skiping content) + client.writeTo(outStream); // may throw exception on httpStatus=302 while gzip encoded inputstream + } conProp.put(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_CODE,"TCP_MISS"); }