Permalink
Browse files

fix crash on routing by Path using websockets (fix #21)

  • Loading branch information...
1 parent e4e48da commit acde8515362c230b8c96e9b861284d465b0c4c85 @tailhook committed Nov 20, 2012
Showing with 56 additions and 4 deletions.
  1. +6 −2 src/http.c
  2. +1 −0 src/http.h
  3. +1 −0 src/websocket.c
  4. +27 −2 test/crash.py
  5. +21 −0 test/crash2.yaml
View
@@ -364,8 +364,7 @@ static void request_timeout(struct ev_loop *loop, struct ev_timer *tm, int rev){
}
}
-int http_headers(request_t *req) {
- req->incoming_time = ev_now(root.loop);
+void http_dissect_path(request_t *req) {
char *query = strchr(req->ws.uri, '?');
if(query) {
int len = query - req->ws.uri;
@@ -375,6 +374,11 @@ int http_headers(request_t *req) {
} else {
req->path = req->ws.uri;
}
+}
+
+int http_headers(request_t *req) {
+ req->incoming_time = ev_now(root.loop);
+ http_dissect_path(req);
config_Route_t *route = preliminary_resolve(req);
if(route && req->ws.bodylen > route->limits.max_body_size) {
TWARN("Request size too big");
View
@@ -6,6 +6,7 @@
int http_headers(request_t *req);
int http_request(request_t *req);
+void http_dissect_path(request_t *req);
int http_request_finish(request_t *req);
void http_static_response(request_t *req, config_StaticResponse_t *resp);
int prepare_http(config_main_t *config, config_Route_t *root);
View
@@ -758,6 +758,7 @@ void websock_process(struct ev_loop *loop, struct ev_io *watch, int revents) {
int start_websocket(request_t *req) {
request_init(req);
+ http_dissect_path(req);
config_Route_t *route = preliminary_resolve(req);
if(!route
|| !route->websocket.subscribe.value_len
View
@@ -1,10 +1,9 @@
import unittest
from .simple import Base
-CONFIG='test/crash1.yaml'
class CrashTest(Base):
- config = CONFIG
+ config = 'test/crash1.yaml'
def testBadRequest(self):
conn = self.http()
@@ -20,5 +19,31 @@ def testGoodRequest(self):
self.assertTrue(b'Not Found' not in resp.read())
conn.close()
+
+class CrashTest2(Base):
+ config = 'test/crash2.yaml'
+
+ def testBadRequest(self):
+ conn = self.http()
+ conn.request('GET', '/test?something', headers={
+ 'Host': 'example.com',
+ 'Upgrade': 'websocket',
+ 'Connection': 'Upgrade',
+ 'Sec-WebSocket-Key': 'dGhlIHNhbXBsZSBub25jZQ==',
+ 'Sec-WebSocket-Origin': 'http://example.com',
+ 'Sec-WebSocket-Version': '13',
+ })
+ resp = conn.getresponse()
+ assert resp.code == 101, resp.code
+ conn.close()
+
+ def testGoodRequest(self):
+ conn = self.http('hello')
+ conn.request('GET', '/')
+ resp = conn.getresponse()
+ self.assertTrue(b'Not Found' in resp.read())
+ conn.close()
+
+
if __name__ == '__main__':
unittest.main()
View
@@ -0,0 +1,21 @@
+# vim: sw=2:ts=2:et
+Server:
+ zmq-io-threads: 1
+ disk-io-threads: 1
+ listen:
+ - unix-socket: /tmp/zerogw-test
+ error-log:
+ level: 1
+ warning-timeout: 300
+
+Routing:
+ routing: !Prefix
+ routing-by: !Path
+ map:
+ "/test":
+ websocket:
+ enabled: yes
+ forward:
+ - !zmq.Connect ipc:///tmp/test/zerogw-test-fw
+ subscribe:
+ - !zmq.Connect ipc:///tmp/test/zerogw-test-sub

0 comments on commit acde851

Please sign in to comment.