create virtual web folder /currentyacypeer/ which always points to local

peer, even when using the urlproxy

Conflicts:
	source/de/anomic/http/server/HTTPDProxyHandler.java
pull/1/head
cominch 13 years ago committed by Michael Peter Christen
parent bde07ed7a8
commit 8e80894812

@ -279,6 +279,10 @@ public final class HTTPDFileHandler {
return; return;
} }
// allow proper access to current peer via virtual directory
if (path.startsWith("/currentyacypeer/")) {
path = path.substring(16);
}
// cache settings // cache settings
boolean nocache = path.contains("?") || body != null; boolean nocache = path.contains("?") || body != null;

@ -448,7 +448,7 @@ public final class HTTPDProxyHandler {
final int reqID = requestHeader.hashCode(); final int reqID = requestHeader.hashCode();
String host = (String) conProp.get(HeaderFramework.CONNECTION_PROP_HOST); String host = (String) conProp.get(HeaderFramework.CONNECTION_PROP_HOST);
final String path = (String) conProp.get(HeaderFramework.CONNECTION_PROP_PATH); // always starts with leading '/' String path = (String) conProp.get(HeaderFramework.CONNECTION_PROP_PATH); // always starts with leading '/'
final String args = (String) conProp.get(HeaderFramework.CONNECTION_PROP_ARGS); // may be null if no args were given final String args = (String) conProp.get(HeaderFramework.CONNECTION_PROP_ARGS); // may be null if no args were given
final String ip = (String) conProp.get(HeaderFramework.CONNECTION_PROP_CLIENTIP); // the ip from the connecting peer final String ip = (String) conProp.get(HeaderFramework.CONNECTION_PROP_CLIENTIP); // the ip from the connecting peer
final String httpVer = (String) conProp.get(HeaderFramework.CONNECTION_PROP_HTTP_VER); // the ip from the connecting peer final String httpVer = (String) conProp.get(HeaderFramework.CONNECTION_PROP_HTTP_VER); // the ip from the connecting peer
@ -461,6 +461,13 @@ public final class HTTPDProxyHandler {
host = host.substring(0, pos); host = host.substring(0, pos);
} }
// 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);
@ -478,8 +485,6 @@ 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);
// send request // send request
@ -494,14 +499,7 @@ public final class HTTPDProxyHandler {
throw new Exception(client.getHttpResponse().getStatusLine().toString()); throw new Exception(client.getHttpResponse().getStatusLine().toString());
} }
if(AugmentedHtmlStream.supportsMime(responseHeader.mime())) { final ChunkedOutputStream chunkedOut = setTransferEncoding(conProp, responseHeader, client.getHttpResponse().getStatusLine().getStatusCode(), respond);
// enable chunk encoding, because we don't know the length after annotating
responseHeader.remove(HeaderFramework.CONTENT_LENGTH);
responseHeader.put(HeaderFramework.TRANSFER_ENCODING, "chunked");
}
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;
@ -536,8 +534,8 @@ 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())) { // sending the respond header back to the client
// chunked encoding disables somewhere, add it again if (chunkedOut != null) {
responseHeader.put(HeaderFramework.TRANSFER_ENCODING, "chunked"); responseHeader.put(HeaderFramework.TRANSFER_ENCODING, "chunked");
} }
@ -552,7 +550,7 @@ public final class HTTPDProxyHandler {
if (hasBody(client.getHttpResponse().getStatusLine().getStatusCode())) { if (hasBody(client.getHttpResponse().getStatusLine().getStatusCode())) {
OutputStream outStream = chunkedOut != null ? chunkedOut : respond; final OutputStream outStream = chunkedOut != null ? chunkedOut : respond;
final Response response = new Response( final Response response = new Response(
request, request,
requestHeader, requestHeader,
@ -564,10 +562,6 @@ 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
@ -636,7 +630,6 @@ 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();
chunkedOut.flush(); chunkedOut.flush();
@ -686,7 +679,7 @@ public final class HTTPDProxyHandler {
final RequestHeader requestHeader, final RequestHeader requestHeader,
final ResponseHeader cachedResponseHeader, final ResponseHeader cachedResponseHeader,
final byte[] cacheEntry, final byte[] cacheEntry,
OutputStream respond final 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);
@ -723,10 +716,6 @@ 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);
@ -1103,7 +1092,6 @@ public final class HTTPDProxyHandler {
forceConnectionClose(conProp); forceConnectionClose(conProp);
} else { } else {
chunkedOut = new ChunkedOutputStream(respond); chunkedOut = new ChunkedOutputStream(respond);
responseHeader.put(HeaderFramework.TRANSFER_ENCODING, "chunked");
} }
responseHeader.remove(HeaderFramework.CONTENT_LENGTH); responseHeader.remove(HeaderFramework.CONTENT_LENGTH);
} }
@ -1173,7 +1161,7 @@ public final class HTTPDProxyHandler {
headers.remove(RequestHeader.X_CACHE_LOOKUP); headers.remove(RequestHeader.X_CACHE_LOOKUP);
// remove transfer encoding header // remove transfer encoding header
// headers.remove(HeaderFramework.TRANSFER_ENCODING); headers.remove(HeaderFramework.TRANSFER_ENCODING);
//removing yacy status headers //removing yacy status headers
headers.remove(HeaderFramework.X_YACY_KEEP_ALIVE_REQUEST_COUNT); headers.remove(HeaderFramework.X_YACY_KEEP_ALIVE_REQUEST_COUNT);

Loading…
Cancel
Save