I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit e20a6a96 authored by zzz's avatar zzz
Browse files

i2ptunnel: Fix HTTP websockets by passing through

Connection headers containing "upgrade" (ticket #2422)
Client-side change only. Server-side todo.
parent 0e710f87
No related branches found
No related tags found
No related merge requests found
...@@ -174,7 +174,13 @@ class HTTPResponseOutputStream extends FilterOutputStream { ...@@ -174,7 +174,13 @@ class HTTPResponseOutputStream extends FilterOutputStream {
String lcKey = key.toLowerCase(Locale.US); String lcKey = key.toLowerCase(Locale.US);
if ("connection".equals(lcKey)) { if ("connection".equals(lcKey)) {
out.write(DataHelper.getASCII("Connection: close\r\n")); if (val.toLowerCase(Locale.US).contains("upgrade")) {
// pass through for websocket
out.write(DataHelper.getASCII("Connection: " + val + "\r\n"));
proxyConnectionSent = true;
} else {
out.write(DataHelper.getASCII("Connection: close\r\n"));
}
connectionSent = true; connectionSent = true;
} else if ("proxy-connection".equals(lcKey)) { } else if ("proxy-connection".equals(lcKey)) {
out.write(DataHelper.getASCII("Proxy-Connection: close\r\n")); out.write(DataHelper.getASCII("Proxy-Connection: close\r\n"));
......
...@@ -414,6 +414,7 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn ...@@ -414,6 +414,7 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn
int remotePort = 0; int remotePort = 0;
String referer = null; String referer = null;
URI origRequestURI = null; URI origRequestURI = null;
boolean preserveConnectionHeader = false;
while((line = reader.readLine(method)) != null) { while((line = reader.readLine(method)) != null) {
line = line.trim(); line = line.trim();
if(_log.shouldLog(Log.DEBUG)) { if(_log.shouldLog(Log.DEBUG)) {
...@@ -421,11 +422,6 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn ...@@ -421,11 +422,6 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn
} }
String lowercaseLine = line.toLowerCase(Locale.US); String lowercaseLine = line.toLowerCase(Locale.US);
if(lowercaseLine.startsWith("connection: ") ||
lowercaseLine.startsWith("keep-alive: ") ||
lowercaseLine.startsWith("proxy-connection: ")) {
continue;
}
if(method == null) { // first line (GET /base64/realaddr) if(method == null) { // first line (GET /base64/realaddr)
if(_log.shouldLog(Log.DEBUG)) { if(_log.shouldLog(Log.DEBUG)) {
...@@ -940,7 +936,17 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn ...@@ -940,7 +936,17 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn
// end first line processing // end first line processing
} else { } else {
if(lowercaseLine.startsWith("host: ") && !usingWWWProxy && !usingInternalOutproxy) { if (lowercaseLine.startsWith("connection: ")) {
if (lowercaseLine.contains("upgrade")) {
// pass through for websocket
preserveConnectionHeader = true;
} else {
continue;
}
} else if (lowercaseLine.startsWith("keep-alive: ") ||
lowercaseLine.startsWith("proxy-connection: ")) {
continue;
} else if (lowercaseLine.startsWith("host: ") && !usingWWWProxy && !usingInternalOutproxy) {
// Note that we only pass the original Host: line through to the outproxy // Note that we only pass the original Host: line through to the outproxy
// But we don't create a Host: line if it wasn't sent to us // But we don't create a Host: line if it wasn't sent to us
line = "Host: " + host; line = "Host: " + host;
...@@ -1081,7 +1087,10 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn ...@@ -1081,7 +1087,10 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn
.append("\r\n"); .append("\r\n");
} }
} }
newRequest.append("Connection: close\r\n\r\n"); if (preserveConnectionHeader)
newRequest.append("\r\n");
else
newRequest.append("Connection: close\r\n\r\n");
s.setSoTimeout(0); s.setSoTimeout(0);
break; break;
} else { } else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment