Merge branch 'master' of git@github.com:netty/netty.git

This commit is contained in:
norman 2012-03-12 12:28:27 +01:00
commit 5830e5a7fb
6 changed files with 22 additions and 70 deletions

View File

@ -368,12 +368,17 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder<HttpMessageDec
if (msg instanceof HttpResponse) { if (msg instanceof HttpResponse) {
HttpResponse res = (HttpResponse) msg; HttpResponse res = (HttpResponse) msg;
int code = res.getStatus().getCode(); int code = res.getStatus().getCode();
// also check for code of 101 as 101 == Response to a websockets upgrade in earlier websocket versions. if (code < 200) {
// // Old Web Socket upgrade response had 16-byte fixed length content.
// See https://github.com/netty/netty/issues/222 // See https://github.com/netty/netty/issues/222
if (code < 200 && code != 101) { if (code == 101 &&
res.containsHeader(HttpHeaders.Names.SEC_WEBSOCKET_ORIGIN) &&
res.containsHeader(HttpHeaders.Names.SEC_WEBSOCKET_LOCATION)) {
return false;
}
return true; return true;
} }
switch (code) { switch (code) {
case 204: case 205: case 304: case 204: case 205: case 304:
return true; return true;

View File

@ -163,7 +163,7 @@ public class HttpPostRequestDecoder {
} }
this.request = request; this.request = request;
HttpMethod method = request.getMethod(); HttpMethod method = request.getMethod();
if (method.equals(HttpMethod.POST) || method.equals(HttpMethod.PUT)) { if (method.equals(HttpMethod.POST) || method.equals(HttpMethod.PUT) || method.equals(HttpMethod.PATCH)) {
bodyToDecode = true; bodyToDecode = true;
} }
this.charset = charset; this.charset = charset;

View File

@ -26,13 +26,14 @@
* *
* <p>03. Intall Python Setup Tools: <tt>sudo apt-get install python-setuptools</tt> * <p>03. Intall Python Setup Tools: <tt>sudo apt-get install python-setuptools</tt>
* *
* <p>04. Install AutoBahn: <tt>sudo easy_install Autobahn</tt> * <p>04. Install AutoBahn: <tt>sudo easy_install Autobahn</tt>. If you already have Autobahn installed, you may need
* to upgrade it: <tt>sudo easy_install --upgrade Autobahn</tt>. Make suer v0.4.10 is installed.
* *
* <p>05. Get AutoBahn testsuite source code: <tt>git clone git@github.com:oberstet/Autobahn.git</tt> * <p>05. Get AutoBahn testsuite source code: <tt>git clone git@github.com:tavendo/AutobahnPython.git</tt>
* *
* <p>06. Go to AutoBahn directory: <tt>cd Autobahn</tt> * <p>06. Go to AutoBahn directory: <tt>cd AutobahnPython</tt>
* *
* <p>07. Checkout stable version: <tt>git checkout v0.4.3</tt> * <p>07. Checkout stable version: <tt>git checkout v0.4.10</tt>
* *
* <p>08. Go to test suite directory: <tt>cd testsuite/websockets</tt> * <p>08. Go to test suite directory: <tt>cd testsuite/websockets</tt>
* *
@ -47,11 +48,12 @@
* } * }
* </code> * </code>
* *
* <p>10. Run <tt>AutobahnServer</tt> in this package * <p>10. Run our <tt>AutobahnServer</tt> located in this package. If you are in Eclipse IDE, right click on
* <tt>AutobahnServer.java</tt> and select Run As > Java Application.
* *
* <p>11. Run the test <tt>python fuzzing_client.py</tt>. Note that the actual test case python code is * <p>11. Run the Autobahn test <tt>python fuzzing_client.py</tt>. Note that the actual test case python code is
* located in <tt>/usr/local/lib/python2.6/dist-packages/autobahn-0.4.3-py2.6.egg/autobahn/cases</tt> * located with the easy_install package (e.g. in <tt>/usr/local/lib/python2.7/dist-packages/
* and not in the checked out git repository. * autobahn-0.4.10-py2.7.egg/autobahn/cases</tt>) and not in the checked out git repository.
* *
* <p>12. See the results in <tt>reports/servers/index.html</tt> * <p>12. See the results in <tt>reports/servers/index.html</tt>
*/ */

View File

@ -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;

View File

@ -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;
}
}

View File

@ -37,6 +37,7 @@ import io.netty.channel.socket.nio.NioServerSocketChannelFactory;
* <li>Chrome 14+ (draft-ietf-hybi-thewebsocketprotocol-10) * <li>Chrome 14+ (draft-ietf-hybi-thewebsocketprotocol-10)
* <li>Chrome 16+ (RFC 6455 aka draft-ietf-hybi-thewebsocketprotocol-17) * <li>Chrome 16+ (RFC 6455 aka draft-ietf-hybi-thewebsocketprotocol-17)
* <li>Firefox 7+ (draft-ietf-hybi-thewebsocketprotocol-10) * <li>Firefox 7+ (draft-ietf-hybi-thewebsocketprotocol-10)
* <li>Firefox 11+ (RFC 6455 aka draft-ietf-hybi-thewebsocketprotocol-17)
* </ul> * </ul>
*/ */
public class WebSocketServer { public class WebSocketServer {