Skip to content

Commit

Permalink
Fix "Connection: Upgrade" case, close #3606
Browse files Browse the repository at this point in the history
This is a temporary workaround.
The proper fix would have to be in Netty.
  • Loading branch information
slandelle committed Nov 15, 2018
1 parent 99e4178 commit 50c97d9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2011-2018 GatlingCorp (https://gatling.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.gatling.http.client.impl;

import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker13;
import io.netty.handler.codec.http.websocketx.WebSocketVersion;
import io.netty.util.AsciiString;

import java.net.URI;

public class FixedWebSocketClientHandshaker13 extends WebSocketClientHandshaker13 {

private static final AsciiString WS_UPGRADE = new AsciiString("Upgrade");

public FixedWebSocketClientHandshaker13(URI webSocketURL, String subprotocol, boolean allowExtensions, HttpHeaders customHeaders, int maxFramePayloadLength) {
super(webSocketURL, WebSocketVersion.V13, subprotocol, allowExtensions, customHeaders, maxFramePayloadLength);
}

@Override
protected FullHttpRequest newHandshakeRequest() {
FullHttpRequest handshakeRequest = super.newHandshakeRequest();
handshakeRequest.headers().set(HttpHeaderNames.CONNECTION, WS_UPGRADE);
return handshakeRequest;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package io.gatling.http.client.impl;

import java.io.IOException;

import io.gatling.http.client.HttpClientConfig;
import io.gatling.http.client.WebSocketListener;
import io.gatling.http.client.impl.request.WritableRequest;
Expand All @@ -29,8 +31,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

public class WebSocketHandler extends ChannelDuplexHandler {

private static final Logger LOGGER = LoggerFactory.getLogger(WebSocketHandler.class);
Expand Down Expand Up @@ -86,9 +86,8 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)
WritableRequest request = WritableRequestBuilder.buildRequest(tx.request, ctx.alloc(), config, false);

handshaker =
WebSocketClientHandshakerFactory.newHandshaker(
new FixedWebSocketClientHandshaker13(
tx.request.getUri().toJavaNetURI(),
WebSocketVersion.V13,
tx.request.getWsSubprotocol(),
true,
request.getRequest().headers(),
Expand Down

0 comments on commit 50c97d9

Please sign in to comment.