final byte[] buffer = new byte[4096]; // TODO avoid this!
String uri=request.getRequestURI();
if (request.getQueryString()!=null)
uri+="?"+request.getQueryString();
HttpURI url=proxyHttpURI(request.getScheme(),
request.getServerName(),
request.getServerPort(),
uri);
if (url==null)
{
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
HttpExchange exchange = new HttpExchange()
{
protected void onRequestCommitted() throws IOException
{
}
protected void onRequestComplete() throws IOException
{
}
protected void onResponseComplete() throws IOException
{
continuation.resume();
}
protected void onResponseContent(Buffer content) throws IOException
{
// TODO Avoid this copy
while (content.hasContent())
{
int len=content.get(buffer,0,buffer.length);
out.write(buffer,0,len); // May block here for a little bit!
}
}
protected void onResponseHeaderComplete() throws IOException
{
}
protected void onResponseStatus(Buffer version, int status, Buffer reason) throws IOException
{
if (reason!=null && reason.length()>0)
response.setStatus(status,reason.toString());
else
response.setStatus(status);
}
protected void onResponseHeader(Buffer name, Buffer value) throws IOException
{
String s = name.toString().toLowerCase();
if (!_DontProxyHeaders.contains(s))
response.addHeader(name.toString(),value.toString());
}
};
exchange.setVersion(request.getProtocol());
exchange.setMethod(request.getMethod());
exchange.setURL(url.toString());
// check connection header
String connectionHdr = request.getHeader("Connection");
if (connectionHdr!=null)
{