Permalink
Browse files

add the support of virtual names with websocket protocol

  • Loading branch information...
yaoweibin committed Oct 26, 2011
1 parent f0245d9 commit 4406771b7dd6486a63d2a1001076dcb08a4d3d8d
Showing with 58 additions and 8 deletions.
  1. +50 −5 modules/ngx_tcp_websocket_proxy_module.c
  2. +2 −1 ngx_tcp.c
  3. +1 −1 ngx_tcp_core_module.c
  4. +4 −0 parsers/gen.shell
  5. +1 −1 test/lib/Test/Nginx/Util.pm
@@ -35,6 +35,8 @@ typedef struct ngx_tcp_websocket_conf_s {
static void ngx_tcp_websocket_init_session(ngx_tcp_session_t *s);
+static ngx_tcp_virtual_server_t * ngx_tcp_websocket_find_virtual_server(
+ ngx_tcp_session_t *s, ngx_tcp_websocket_ctx_t *ctx);
static void ngx_tcp_websocket_init_upstream(ngx_connection_t *c,
ngx_tcp_session_t *s);
static void ngx_tcp_upstream_websocket_proxy_init_handler(ngx_tcp_session_t *s,
@@ -589,13 +591,21 @@ ngx_tcp_websocket_init_upstream(ngx_connection_t *c, ngx_tcp_session_t *s)
ngx_tcp_upstream_t *u;
ngx_tcp_websocket_ctx_t *wctx;
ngx_tcp_websocket_conf_t *wcf;
+ ngx_tcp_virtual_server_t *vs;
s->connection->log->action = "ngx_tcp_websocket_init_upstream";
- wcf = ngx_tcp_get_module_srv_conf(s, ngx_tcp_websocket_module);
-
wctx = ngx_tcp_get_module_ctx(s, ngx_tcp_websocket_module);
+ vs = ngx_tcp_websocket_find_virtual_server(s, wctx);
+
+ if (vs) {
+ s->main_conf = vs->ctx->main_conf;
+ s->srv_conf = vs->ctx->srv_conf;
+ }
+
+ wcf = ngx_tcp_get_module_srv_conf(s, ngx_tcp_websocket_module);
+
ngx_log_debug3(NGX_LOG_DEBUG_TCP, s->connection->log, 0,
"tcp websocket init upstream, scheme: \"%V\" location: \"%V\", host: \"%V\"",
&wcf->scheme, &wctx->location, &wctx->host);
@@ -636,16 +646,51 @@ ngx_tcp_websocket_init_upstream(ngx_connection_t *c, ngx_tcp_session_t *s)
}
+static ngx_tcp_virtual_server_t *
+ngx_tcp_websocket_find_virtual_server(ngx_tcp_session_t *s,
+ ngx_tcp_websocket_ctx_t *ctx)
+{
+ ngx_uint_t hash, i;
+ ngx_connection_t *c;
+ ngx_tcp_core_main_conf_t *cmcf;
+ ngx_tcp_virtual_server_t *vs;
+
+ cmcf = ngx_tcp_get_module_main_conf(s, ngx_tcp_core_module);
+
+ if (ctx->host.len == 0) {
+ return NULL;
+ }
+
+ hash = ngx_hash_key(ctx->host.data, ctx->host.len);
+
+ c = s->connection;
+
+ vs = cmcf->virtual_servers.elts;
+ for (i = 0; i < cmcf->virtual_servers.nelts; i++) {
+
+ if (vs[i].hash != hash) {
+ continue;
+ }
+
+ if (vs[i].name.len != ctx->host.len
+ || ngx_memcmp(vs[i].name.data, ctx->host.data, ctx->host.len) != 0){
+ continue;
+ }
+
+ return &vs[i];
+ }
+
+ return NULL;
+}
+
+
static void
ngx_tcp_upstream_websocket_proxy_init_handler(ngx_tcp_session_t *s, ngx_tcp_upstream_t *u)
{
ngx_connection_t *c;
- ngx_tcp_core_srv_conf_t *cscf;
ngx_tcp_websocket_ctx_t *wctx;
ngx_tcp_websocket_conf_t *wcf;
- cscf = ngx_tcp_get_module_srv_conf(s, ngx_tcp_core_module);
-
c = s->connection;
c->log->action = "ngx_tcp_upstream_websocket_proxy_init_handler";
View
@@ -328,7 +328,8 @@ ngx_tcp_add_virtual_servers(ngx_conf_t *cf, ngx_tcp_core_main_conf_t *cmcf,
return NGX_ERROR;
}
- vs->name = cscf->server_name;
+ vs->name.len = cscf->server_name.len;
+ vs->name.data = cscf->server_name.data;
vs->hash = ngx_hash_key(vs->name.data, vs->name.len);
vs->listen = listen;
vs->ctx = listen->ctx;
View
@@ -182,7 +182,7 @@ ngx_tcp_core_create_main_conf(ngx_conf_t *cf)
}
if (ngx_array_init(&cmcf->virtual_servers, cf->pool, 4,
- sizeof(ngx_tcp_conf_port_t)) != NGX_OK)
+ sizeof(ngx_tcp_virtual_server_t)) != NGX_OK)
{
return NULL;
}
View
@@ -0,0 +1,4 @@
+
+ragel -G2 http_request_parser.rl
+ragel -G2 http_response_parser.rl
+ragel -G2 smtp_response_parser.rl
@@ -467,7 +467,7 @@ start_nginx:
}
}
- sleep 6;
+ sleep 10;
}
}

0 comments on commit 4406771

Please sign in to comment.