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.
pull/1/head
reger 10 years ago
parent cc090bcb01
commit f856edecb6

@ -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);

@ -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");
}

Loading…
Cancel
Save