|
|
@ -467,6 +467,14 @@ public final class HTTPDProxyHandler {
|
|
|
|
port = sb.peers.myPort();
|
|
|
|
port = sb.peers.myPort();
|
|
|
|
path = path.substring(16);
|
|
|
|
path = path.substring(16);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// point virtual directory to my peer
|
|
|
|
|
|
|
|
if (path.startsWith("/currentyacypeer/")) {
|
|
|
|
|
|
|
|
host = sb.peers.myIP();
|
|
|
|
|
|
|
|
port = sb.peers.myPort();
|
|
|
|
|
|
|
|
path = path.substring(16);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// resolve yacy and yacyh domains
|
|
|
|
// resolve yacy and yacyh domains
|
|
|
|
String yAddress = resolveYacyDomains(host);
|
|
|
|
String yAddress = resolveYacyDomains(host);
|
|
|
@ -484,6 +492,8 @@ public final class HTTPDProxyHandler {
|
|
|
|
|
|
|
|
|
|
|
|
final String connectHost = hostPart(host, port, yAddress);
|
|
|
|
final String connectHost = hostPart(host, port, yAddress);
|
|
|
|
final String getUrl = "http://"+ connectHost + remotePath;
|
|
|
|
final String getUrl = "http://"+ connectHost + remotePath;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requestHeader.remove(HeaderFramework.HOST);
|
|
|
|
|
|
|
|
|
|
|
|
final HTTPClient client = setupHttpClient(requestHeader, connectHost);
|
|
|
|
final HTTPClient client = setupHttpClient(requestHeader, connectHost);
|
|
|
|
|
|
|
|
|
|
|
@ -498,8 +508,15 @@ public final class HTTPDProxyHandler {
|
|
|
|
if (responseHeader.isEmpty()) {
|
|
|
|
if (responseHeader.isEmpty()) {
|
|
|
|
throw new Exception(client.getHttpResponse().getStatusLine().toString());
|
|
|
|
throw new Exception(client.getHttpResponse().getStatusLine().toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(AugmentedHtmlStream.supportsMime(responseHeader.mime())) {
|
|
|
|
|
|
|
|
// enable chunk encoding, because we don't know the length after annotating
|
|
|
|
|
|
|
|
responseHeader.remove(HeaderFramework.CONTENT_LENGTH);
|
|
|
|
|
|
|
|
responseHeader.put(HeaderFramework.TRANSFER_ENCODING, "chunked");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
final ChunkedOutputStream chunkedOut = setTransferEncoding(conProp, responseHeader, client.getHttpResponse().getStatusLine().getStatusCode(), respond);
|
|
|
|
ChunkedOutputStream chunkedOut = setTransferEncoding(conProp, responseHeader, client.getHttpResponse().getStatusLine().getStatusCode(), respond);
|
|
|
|
|
|
|
|
|
|
|
|
// the cache does either not exist or is (supposed to be) stale
|
|
|
|
// the cache does either not exist or is (supposed to be) stale
|
|
|
|
long sizeBeforeDelete = -1;
|
|
|
|
long sizeBeforeDelete = -1;
|
|
|
@ -534,6 +551,11 @@ public final class HTTPDProxyHandler {
|
|
|
|
// prepareResponseHeader(responseHeader, res.getHttpVer());
|
|
|
|
// prepareResponseHeader(responseHeader, res.getHttpVer());
|
|
|
|
prepareResponseHeader(responseHeader, client.getHttpResponse().getProtocolVersion().toString());
|
|
|
|
prepareResponseHeader(responseHeader, client.getHttpResponse().getProtocolVersion().toString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(AugmentedHtmlStream.supportsMime(responseHeader.mime())) {
|
|
|
|
|
|
|
|
// chunked encoding disables somewhere, add it again
|
|
|
|
|
|
|
|
responseHeader.put(HeaderFramework.TRANSFER_ENCODING, "chunked");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// sending the respond header back to the client
|
|
|
|
// sending the respond header back to the client
|
|
|
|
if (chunkedOut != null) {
|
|
|
|
if (chunkedOut != null) {
|
|
|
|
responseHeader.put(HeaderFramework.TRANSFER_ENCODING, "chunked");
|
|
|
|
responseHeader.put(HeaderFramework.TRANSFER_ENCODING, "chunked");
|
|
|
@ -550,7 +572,7 @@ public final class HTTPDProxyHandler {
|
|
|
|
|
|
|
|
|
|
|
|
if (hasBody(client.getHttpResponse().getStatusLine().getStatusCode())) {
|
|
|
|
if (hasBody(client.getHttpResponse().getStatusLine().getStatusCode())) {
|
|
|
|
|
|
|
|
|
|
|
|
final OutputStream outStream = chunkedOut != null ? chunkedOut : respond;
|
|
|
|
OutputStream outStream = chunkedOut != null ? chunkedOut : respond;
|
|
|
|
final Response response = new Response(
|
|
|
|
final Response response = new Response(
|
|
|
|
request,
|
|
|
|
request,
|
|
|
|
requestHeader,
|
|
|
|
requestHeader,
|
|
|
@ -562,6 +584,10 @@ public final class HTTPDProxyHandler {
|
|
|
|
final String storeError = response.shallStoreCacheForProxy();
|
|
|
|
final String storeError = response.shallStoreCacheForProxy();
|
|
|
|
final boolean storeHTCache = response.profile().storeHTCache();
|
|
|
|
final boolean storeHTCache = response.profile().storeHTCache();
|
|
|
|
final String supportError = TextParser.supports(response.url(), response.getMimeType());
|
|
|
|
final String supportError = TextParser.supports(response.url(), response.getMimeType());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(AugmentedHtmlStream.supportsMime(responseHeader.mime())) {
|
|
|
|
|
|
|
|
outStream = new AugmentedHtmlStream(outStream, responseHeader.getCharSet(), url, url.hash(), requestHeader);
|
|
|
|
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
if (
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Now we store the response into the htcache directory if
|
|
|
|
* Now we store the response into the htcache directory if
|
|
|
@ -629,6 +655,8 @@ public final class HTTPDProxyHandler {
|
|
|
|
|
|
|
|
|
|
|
|
conProp.put(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_CODE,"TCP_MISS");
|
|
|
|
conProp.put(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_CODE,"TCP_MISS");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
outStream.close();
|
|
|
|
|
|
|
|
|
|
|
|
if (chunkedOut != null) {
|
|
|
|
if (chunkedOut != null) {
|
|
|
|
chunkedOut.finish();
|
|
|
|
chunkedOut.finish();
|
|
|
@ -679,7 +707,7 @@ public final class HTTPDProxyHandler {
|
|
|
|
final RequestHeader requestHeader,
|
|
|
|
final RequestHeader requestHeader,
|
|
|
|
final ResponseHeader cachedResponseHeader,
|
|
|
|
final ResponseHeader cachedResponseHeader,
|
|
|
|
final byte[] cacheEntry,
|
|
|
|
final byte[] cacheEntry,
|
|
|
|
final OutputStream respond
|
|
|
|
OutputStream respond
|
|
|
|
) throws IOException {
|
|
|
|
) throws IOException {
|
|
|
|
|
|
|
|
|
|
|
|
final String httpVer = (String) conProp.get(HeaderFramework.CONNECTION_PROP_HTTP_VER);
|
|
|
|
final String httpVer = (String) conProp.get(HeaderFramework.CONNECTION_PROP_HTTP_VER);
|
|
|
@ -716,6 +744,10 @@ public final class HTTPDProxyHandler {
|
|
|
|
HTTPDemon.sendRespondHeader(conProp,respond,httpVer,203,cachedResponseHeader);
|
|
|
|
HTTPDemon.sendRespondHeader(conProp,respond,httpVer,203,cachedResponseHeader);
|
|
|
|
//respondHeader(respond, "203 OK", cachedResponseHeader); // respond with 'non-authoritative'
|
|
|
|
//respondHeader(respond, "203 OK", cachedResponseHeader); // respond with 'non-authoritative'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(AugmentedHtmlStream.supportsMime(cachedResponseHeader.mime())) {
|
|
|
|
|
|
|
|
respond = new AugmentedHtmlStream(respond, cachedResponseHeader.getCharSet(), url, url.hash(), requestHeader);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// send also the complete body now from the cache
|
|
|
|
// send also the complete body now from the cache
|
|
|
|
// simply read the file and transfer to out socket
|
|
|
|
// simply read the file and transfer to out socket
|
|
|
|
FileUtils.copy(cacheEntry, respond);
|
|
|
|
FileUtils.copy(cacheEntry, respond);
|
|
|
|