HTTP: Disable automatic cookie parsing and resetting, allow to enable it, closes #1177.
This commit is contained in:
parent
b104c19e7a
commit
b07d9d56b4
|
@ -258,6 +258,7 @@ public class HttpDownloadHelper {
|
||||||
if (connection instanceof HttpURLConnection) {
|
if (connection instanceof HttpURLConnection) {
|
||||||
((HttpURLConnection) connection).setInstanceFollowRedirects(false);
|
((HttpURLConnection) connection).setInstanceFollowRedirects(false);
|
||||||
((HttpURLConnection) connection).setUseCaches(true);
|
((HttpURLConnection) connection).setUseCaches(true);
|
||||||
|
((HttpURLConnection) connection).setConnectTimeout(5000);
|
||||||
}
|
}
|
||||||
// connect to the remote site (may take some time)
|
// connect to the remote site (may take some time)
|
||||||
connection.connect();
|
connection.connect();
|
||||||
|
|
|
@ -19,7 +19,11 @@
|
||||||
|
|
||||||
package org.elasticsearch.http.netty;
|
package org.elasticsearch.http.netty;
|
||||||
|
|
||||||
import org.elasticsearch.common.netty.channel.*;
|
import org.elasticsearch.common.netty.channel.ChannelHandler;
|
||||||
|
import org.elasticsearch.common.netty.channel.ChannelHandlerContext;
|
||||||
|
import org.elasticsearch.common.netty.channel.ExceptionEvent;
|
||||||
|
import org.elasticsearch.common.netty.channel.MessageEvent;
|
||||||
|
import org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler;
|
||||||
import org.elasticsearch.common.netty.handler.codec.http.HttpRequest;
|
import org.elasticsearch.common.netty.handler.codec.http.HttpRequest;
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,7 +41,7 @@ public class HttpRequestHandler extends SimpleChannelUpstreamHandler {
|
||||||
|
|
||||||
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
|
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
|
||||||
HttpRequest request = (HttpRequest) e.getMessage();
|
HttpRequest request = (HttpRequest) e.getMessage();
|
||||||
serverTransport.dispatchRequest(new NettyHttpRequest(request), new NettyHttpChannel(e.getChannel(), request));
|
serverTransport.dispatchRequest(new NettyHttpRequest(request), new NettyHttpChannel(serverTransport, e.getChannel(), request));
|
||||||
super.messageReceived(ctx, e);
|
super.messageReceived(ctx, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,10 +48,12 @@ import java.util.Set;
|
||||||
* @author kimchy (shay.banon)
|
* @author kimchy (shay.banon)
|
||||||
*/
|
*/
|
||||||
public class NettyHttpChannel implements HttpChannel {
|
public class NettyHttpChannel implements HttpChannel {
|
||||||
|
private final NettyHttpServerTransport transport;
|
||||||
private final Channel channel;
|
private final Channel channel;
|
||||||
private final org.elasticsearch.common.netty.handler.codec.http.HttpRequest request;
|
private final org.elasticsearch.common.netty.handler.codec.http.HttpRequest request;
|
||||||
|
|
||||||
public NettyHttpChannel(Channel channel, org.elasticsearch.common.netty.handler.codec.http.HttpRequest request) {
|
public NettyHttpChannel(NettyHttpServerTransport transport, Channel channel, org.elasticsearch.common.netty.handler.codec.http.HttpRequest request) {
|
||||||
|
this.transport = transport;
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
this.request = request;
|
this.request = request;
|
||||||
}
|
}
|
||||||
|
@ -126,17 +128,19 @@ public class NettyHttpChannel implements HttpChannel {
|
||||||
|
|
||||||
resp.setHeader(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(buf.readableBytes()));
|
resp.setHeader(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(buf.readableBytes()));
|
||||||
|
|
||||||
String cookieString = request.getHeader(HttpHeaders.Names.COOKIE);
|
if (transport.resetCookies) {
|
||||||
if (cookieString != null) {
|
String cookieString = request.getHeader(HttpHeaders.Names.COOKIE);
|
||||||
CookieDecoder cookieDecoder = new CookieDecoder();
|
if (cookieString != null) {
|
||||||
Set<Cookie> cookies = cookieDecoder.decode(cookieString);
|
CookieDecoder cookieDecoder = new CookieDecoder();
|
||||||
if (!cookies.isEmpty()) {
|
Set<Cookie> cookies = cookieDecoder.decode(cookieString);
|
||||||
// Reset the cookies if necessary.
|
if (!cookies.isEmpty()) {
|
||||||
CookieEncoder cookieEncoder = new CookieEncoder(true);
|
// Reset the cookies if necessary.
|
||||||
for (Cookie cookie : cookies) {
|
CookieEncoder cookieEncoder = new CookieEncoder(true);
|
||||||
cookieEncoder.addCookie(cookie);
|
for (Cookie cookie : cookies) {
|
||||||
|
cookieEncoder.addCookie(cookie);
|
||||||
|
}
|
||||||
|
resp.addHeader(HttpHeaders.Names.SET_COOKIE, cookieEncoder.encode());
|
||||||
}
|
}
|
||||||
resp.addHeader(HttpHeaders.Names.SET_COOKIE, cookieEncoder.encode());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,6 +95,8 @@ public class NettyHttpServerTransport extends AbstractLifecycleComponent<HttpSer
|
||||||
|
|
||||||
private final int compressionLevel;
|
private final int compressionLevel;
|
||||||
|
|
||||||
|
final boolean resetCookies;
|
||||||
|
|
||||||
private final String port;
|
private final String port;
|
||||||
|
|
||||||
private final String bindHost;
|
private final String bindHost;
|
||||||
|
@ -128,6 +130,9 @@ public class NettyHttpServerTransport extends AbstractLifecycleComponent<HttpSer
|
||||||
this.maxChunkSize = componentSettings.getAsBytesSize("max_chunk_size", settings.getAsBytesSize("http.max_chunk_size", new ByteSizeValue(8, ByteSizeUnit.KB)));
|
this.maxChunkSize = componentSettings.getAsBytesSize("max_chunk_size", settings.getAsBytesSize("http.max_chunk_size", new ByteSizeValue(8, ByteSizeUnit.KB)));
|
||||||
this.maxHeaderSize = componentSettings.getAsBytesSize("max_header_size", settings.getAsBytesSize("http.max_header_size", new ByteSizeValue(8, ByteSizeUnit.KB)));
|
this.maxHeaderSize = componentSettings.getAsBytesSize("max_header_size", settings.getAsBytesSize("http.max_header_size", new ByteSizeValue(8, ByteSizeUnit.KB)));
|
||||||
this.maxInitialLineLength = componentSettings.getAsBytesSize("max_initial_line_length", settings.getAsBytesSize("http.max_initial_line_length", new ByteSizeValue(4, ByteSizeUnit.KB)));
|
this.maxInitialLineLength = componentSettings.getAsBytesSize("max_initial_line_length", settings.getAsBytesSize("http.max_initial_line_length", new ByteSizeValue(4, ByteSizeUnit.KB)));
|
||||||
|
// don't reset cookies by default, since I don't think we really need to, and parsing of cookies with netty is slow
|
||||||
|
// and requires a large stack allocation because of the use of regex
|
||||||
|
this.resetCookies = componentSettings.getAsBoolean("reset_cookies", settings.getAsBoolean("http.reset_cookies", false));
|
||||||
this.workerCount = componentSettings.getAsInt("worker_count", Runtime.getRuntime().availableProcessors() * 2);
|
this.workerCount = componentSettings.getAsInt("worker_count", Runtime.getRuntime().availableProcessors() * 2);
|
||||||
this.blockingServer = settings.getAsBoolean("http.blocking_server", settings.getAsBoolean(TCP_BLOCKING_SERVER, settings.getAsBoolean(TCP_BLOCKING, false)));
|
this.blockingServer = settings.getAsBoolean("http.blocking_server", settings.getAsBoolean(TCP_BLOCKING_SERVER, settings.getAsBoolean(TCP_BLOCKING, false)));
|
||||||
this.port = componentSettings.get("port", settings.get("http.port", "9200-9300"));
|
this.port = componentSettings.get("port", settings.get("http.port", "9200-9300"));
|
||||||
|
|
Loading…
Reference in New Issue