Issue #222. Remove WebSocketHttpResponseDecoder hack.
This commit is contained in:
parent
279d859c7e
commit
afcd033123
@ -84,7 +84,7 @@ public class WebSocketClient {
|
|||||||
HashMap<String, String> customHeaders = new HashMap<String, String>();
|
HashMap<String, String> customHeaders = new HashMap<String, String>();
|
||||||
customHeaders.put("MyHeader", "MyValue");
|
customHeaders.put("MyHeader", "MyValue");
|
||||||
|
|
||||||
// Connect with V13 (RFC 6455). You can change it to V08 or V00.
|
// Connect with V13 (RFC 6455 aka HyBi-17). You can change it to V08 or V00.
|
||||||
// If you change it to V00, ping is not supported and remember to change
|
// If you change it to V00, ping is not supported and remember to change
|
||||||
// HttpResponseDecoder to WebSocketHttpResponseDecoder in the pipeline.
|
// HttpResponseDecoder to WebSocketHttpResponseDecoder in the pipeline.
|
||||||
final WebSocketClientHandshaker handshaker =
|
final WebSocketClientHandshaker handshaker =
|
||||||
@ -94,12 +94,7 @@ public class WebSocketClient {
|
|||||||
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
|
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
|
||||||
public ChannelPipeline getPipeline() throws Exception {
|
public ChannelPipeline getPipeline() throws Exception {
|
||||||
ChannelPipeline pipeline = Channels.pipeline();
|
ChannelPipeline pipeline = Channels.pipeline();
|
||||||
|
|
||||||
// If you wish to support HyBi V00, you need to use
|
|
||||||
// WebSocketHttpResponseDecoder instead for
|
|
||||||
// HttpResponseDecoder.
|
|
||||||
pipeline.addLast("decoder", new HttpResponseDecoder());
|
pipeline.addLast("decoder", new HttpResponseDecoder());
|
||||||
|
|
||||||
pipeline.addLast("encoder", new HttpRequestEncoder());
|
pipeline.addLast("encoder", new HttpRequestEncoder());
|
||||||
pipeline.addLast("ws-handler", new WebSocketClientHandler(handshaker));
|
pipeline.addLast("ws-handler", new WebSocketClientHandler(handshaker));
|
||||||
return pipeline;
|
return pipeline;
|
||||||
|
@ -1,51 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2011 The Netty Project
|
|
||||||
*
|
|
||||||
* The Netty Project licenses this file to you 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.netty.example.http.websocketx.client;
|
|
||||||
|
|
||||||
import io.netty.handler.codec.http.HttpMessage;
|
|
||||||
import io.netty.handler.codec.http.HttpResponse;
|
|
||||||
import io.netty.handler.codec.http.HttpResponseDecoder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fix bug in standard HttpResponseDecoder for web socket clients. When status 101 is received for Hybi00, there are 16
|
|
||||||
* bytes of contents expected
|
|
||||||
*/
|
|
||||||
public class WebSocketHttpResponseDecoder extends HttpResponseDecoder {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean isContentAlwaysEmpty(HttpMessage msg) {
|
|
||||||
if (msg instanceof HttpResponse) {
|
|
||||||
HttpResponse res = (HttpResponse) msg;
|
|
||||||
int code = res.getStatus().getCode();
|
|
||||||
|
|
||||||
// FIX force reading of protocol upgrade challenge data into the content buffer
|
|
||||||
if (code == 101) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (code < 200) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
switch (code) {
|
|
||||||
case 204:
|
|
||||||
case 205:
|
|
||||||
case 304:
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user