Skip to content

Commit

Permalink
Preliminary experimental support for SPDY draft 2.
Browse files Browse the repository at this point in the history
  • Loading branch information
vbart committed Mar 20, 2013
1 parent 46a6b99 commit fab658f
Show file tree
Hide file tree
Showing 18 changed files with 4,852 additions and 16 deletions.
19 changes: 17 additions & 2 deletions auto/modules
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ fi
# ngx_http_write_filter
# ngx_http_header_filter
# ngx_http_chunked_filter
# ngx_http_spdy_filter
# ngx_http_range_header_filter
# ngx_http_gzip_filter
# ngx_http_postpone_filter
Expand All @@ -118,8 +119,13 @@ fi

HTTP_FILTER_MODULES="$HTTP_WRITE_FILTER_MODULE \
$HTTP_HEADER_FILTER_MODULE \
$HTTP_CHUNKED_FILTER_MODULE \
$HTTP_RANGE_HEADER_FILTER_MODULE"
$HTTP_CHUNKED_FILTER_MODULE"

if [ $HTTP_SPDY = YES ]; then
HTTP_FILTER_MODULES="$HTTP_FILTER_MODULES $HTTP_SPDY_FILTER_MODULE"
fi

HTTP_FILTER_MODULES="$HTTP_FILTER_MODULES $HTTP_RANGE_HEADER_FILTER_MODULE"

if [ $HTTP_GZIP = YES ]; then
have=NGX_HTTP_GZIP . auto/have
Expand Down Expand Up @@ -179,6 +185,15 @@ if [ $HTTP_USERID = YES ]; then
HTTP_SRCS="$HTTP_SRCS $HTTP_USERID_SRCS"
fi


if [ $HTTP_SPDY = YES ]; then
have=NGX_HTTP_SPDY . auto/have
USE_ZLIB=YES
HTTP_MODULES="$HTTP_MODULES $HTTP_SPDY_MODULE"
HTTP_DEPS="$HTTP_DEPS $HTTP_SPDY_DEPS"
HTTP_SRCS="$HTTP_SRCS $HTTP_SPDY_SRCS"
fi

HTTP_MODULES="$HTTP_MODULES $HTTP_STATIC_MODULE"

if [ $HTTP_GZIP_STATIC = YES ]; then
Expand Down
3 changes: 3 additions & 0 deletions auto/options
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ HTTP_CACHE=YES
HTTP_CHARSET=YES
HTTP_GZIP=YES
HTTP_SSL=NO
HTTP_SPDY=NO
HTTP_SSI=YES
HTTP_POSTPONE=NO
HTTP_REALIP=NO
Expand Down Expand Up @@ -202,6 +203,7 @@ do
--http-scgi-temp-path=*) NGX_HTTP_SCGI_TEMP_PATH="$value" ;;

--with-http_ssl_module) HTTP_SSL=YES ;;
--with-http_spdy_module) HTTP_SPDY=YES ;;
--with-http_realip_module) HTTP_REALIP=YES ;;
--with-http_addition_module) HTTP_ADDITION=YES ;;
--with-http_xslt_module) HTTP_XSLT=YES ;;
Expand Down Expand Up @@ -349,6 +351,7 @@ cat << END
--with-ipv6 enable IPv6 support

--with-http_ssl_module enable ngx_http_ssl_module
--with-http_spdy_module enable ngx_http_spdy_module
--with-http_realip_module enable ngx_http_realip_module
--with-http_addition_module enable ngx_http_addition_module
--with-http_xslt_module enable ngx_http_xslt_module
Expand Down
9 changes: 9 additions & 0 deletions auto/sources
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,15 @@ HTTP_POSTPONE_FILTER_SRCS=src/http/ngx_http_postpone_filter_module.c
HTTP_FILE_CACHE_SRCS=src/http/ngx_http_file_cache.c


HTTP_SPDY_MODULE=ngx_http_spdy_module
HTTP_SPDY_FILTER_MODULE=ngx_http_spdy_filter_module
HTTP_SPDY_DEPS="src/http/ngx_http_spdy.h \
src/http/ngx_http_spdy_module.h"
HTTP_SPDY_SRCS="src/http/ngx_http_spdy.c \
src/http/ngx_http_spdy_module.c \
src/http/ngx_http_spdy_filter_module.c"


HTTP_CHARSET_FILTER_MODULE=ngx_http_charset_filter_module
HTTP_CHARSET_SRCS=src/http/modules/ngx_http_charset_filter_module.c

Expand Down
17 changes: 16 additions & 1 deletion src/http/modules/ngx_http_ssl_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,28 @@ static int
ngx_http_ssl_npn_advertised(ngx_ssl_conn_t *ssl_conn,
const unsigned char **out, unsigned int *outlen, void *arg)
{
#if (NGX_DEBUG)
#if (NGX_HTTP_SPDY || NGX_DEBUG)
ngx_connection_t *c;

c = ngx_ssl_get_connection(ssl_conn);
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "SSL NPN advertised");
#endif

#if (NGX_HTTP_SPDY)
{
ngx_http_connection_t *hc;

hc = c->data;

if (hc->addr_conf->spdy) {
*out = (unsigned char *) NGX_SPDY_NPN_ADVERTISE NGX_HTTP_NPN_ADVERTISE;
*outlen = sizeof(NGX_SPDY_NPN_ADVERTISE NGX_HTTP_NPN_ADVERTISE) - 1;

return SSL_TLSEXT_ERR_OK;
}
}
#endif

*out = (unsigned char *) NGX_HTTP_NPN_ADVERTISE;
*outlen = sizeof(NGX_HTTP_NPN_ADVERTISE) - 1;

Expand Down
23 changes: 23 additions & 0 deletions src/http/ngx_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,9 @@ ngx_http_add_addresses(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf,
#if (NGX_HTTP_SSL)
ngx_uint_t ssl;
#endif
#if (NGX_HTTP_SPDY)
ngx_uint_t spdy;
#endif

/*
* we cannot compare whole sockaddr struct's as kernel
Expand Down Expand Up @@ -1277,6 +1280,9 @@ ngx_http_add_addresses(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf,
#if (NGX_HTTP_SSL)
ssl = lsopt->ssl || addr[i].opt.ssl;
#endif
#if (NGX_HTTP_SPDY)
spdy = lsopt->spdy || addr[i].opt.spdy;
#endif

if (lsopt->set) {

Expand Down Expand Up @@ -1307,6 +1313,9 @@ ngx_http_add_addresses(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf,
#if (NGX_HTTP_SSL)
addr[i].opt.ssl = ssl;
#endif
#if (NGX_HTTP_SPDY)
addr[i].opt.spdy = spdy;
#endif

return NGX_OK;
}
Expand Down Expand Up @@ -1337,6 +1346,14 @@ ngx_http_add_address(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf,
}
}

#if (NGX_HTTP_SPDY && NGX_HTTP_SSL && !defined TLSEXT_TYPE_next_proto_neg)
if (lsopt->spdy && lsopt->ssl) {
ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
"nginx was built without OpenSSL NPN support, "
"SPDY is not enabled for %s", lsopt->addr);
}
#endif

addr = ngx_array_push(&port->addrs);
if (addr == NULL) {
return NGX_ERROR;
Expand Down Expand Up @@ -1820,6 +1837,9 @@ ngx_http_add_addrs(ngx_conf_t *cf, ngx_http_port_t *hport,
#if (NGX_HTTP_SSL)
addrs[i].conf.ssl = addr[i].opt.ssl;
#endif
#if (NGX_HTTP_SPDY)
addrs[i].conf.spdy = addr[i].opt.spdy;
#endif

if (addr[i].hash.buckets == NULL
&& (addr[i].wc_head == NULL
Expand Down Expand Up @@ -1881,6 +1901,9 @@ ngx_http_add_addrs6(ngx_conf_t *cf, ngx_http_port_t *hport,
#if (NGX_HTTP_SSL)
addrs6[i].conf.ssl = addr[i].opt.ssl;
#endif
#if (NGX_HTTP_SPDY)
addrs6[i].conf.spdy = addr[i].opt.spdy;
#endif

if (addr[i].hash.buckets == NULL
&& (addr[i].wc_head == NULL
Expand Down
14 changes: 14 additions & 0 deletions src/http/ngx_http.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ typedef struct ngx_http_file_cache_s ngx_http_file_cache_t;
typedef struct ngx_http_log_ctx_s ngx_http_log_ctx_t;
typedef struct ngx_http_chunked_s ngx_http_chunked_t;

#if (NGX_HTTP_SPDY)
typedef struct ngx_http_spdy_stream_s ngx_http_spdy_stream_t;
#endif

typedef ngx_int_t (*ngx_http_header_handler_pt)(ngx_http_request_t *r,
ngx_table_elt_t *h, ngx_uint_t offset);
typedef u_char *(*ngx_http_log_handler_pt)(ngx_http_request_t *r,
Expand All @@ -35,6 +39,9 @@ typedef u_char *(*ngx_http_log_handler_pt)(ngx_http_request_t *r,
#include <ngx_http_busy_lock.h>
#include <ngx_http_core_module.h>

#if (NGX_HTTP_SPDY)
#include <ngx_http_spdy.h>
#endif
#if (NGX_HTTP_CACHE)
#include <ngx_http_cache.h>
#endif
Expand Down Expand Up @@ -80,12 +87,14 @@ ngx_int_t ngx_http_add_listen(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf,


void ngx_http_init_connection(ngx_connection_t *c);
void ngx_http_close_connection(ngx_connection_t *c);

#ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
int ngx_http_ssl_servername(ngx_ssl_conn_t *ssl_conn, int *ad, void *arg);
#endif

ngx_int_t ngx_http_parse_request_line(ngx_http_request_t *r, ngx_buf_t *b);
ngx_int_t ngx_http_parse_uri(ngx_http_request_t *r);
ngx_int_t ngx_http_parse_complex_uri(ngx_http_request_t *r,
ngx_uint_t merge_slashes);
ngx_int_t ngx_http_parse_status_line(ngx_http_request_t *r, ngx_buf_t *b,
Expand All @@ -104,12 +113,17 @@ ngx_int_t ngx_http_parse_chunked(ngx_http_request_t *r, ngx_buf_t *b,
ngx_http_chunked_t *ctx);


ngx_http_request_t *ngx_http_create_request(ngx_connection_t *c);
ngx_int_t ngx_http_process_request_uri(ngx_http_request_t *r);
ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r);
void ngx_http_process_request(ngx_http_request_t *r);
void ngx_http_update_location_config(ngx_http_request_t *r);
void ngx_http_handler(ngx_http_request_t *r);
void ngx_http_run_posted_requests(ngx_connection_t *c);
ngx_int_t ngx_http_post_request(ngx_http_request_t *r,
ngx_http_posted_request_t *pr);
void ngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc);
void ngx_http_free_request(ngx_http_request_t *r, ngx_int_t rc);

void ngx_http_empty_handler(ngx_event_t *wev);
void ngx_http_request_empty_handler(ngx_http_request_t *r);
Expand Down
23 changes: 23 additions & 0 deletions src/http/ngx_http_core_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -2130,6 +2130,13 @@ ngx_http_gzip_ok(ngx_http_request_t *r)
return NGX_DECLINED;
}

#if (NGX_HTTP_SPDY)
if (r->spdy_stream) {
r->gzip_ok = 1;
return NGX_OK;
}
#endif

ae = r->headers_in.accept_encoding;
if (ae == NULL) {
return NGX_DECLINED;
Expand Down Expand Up @@ -2464,6 +2471,10 @@ ngx_http_subrequest(ngx_http_request_t *r,

sr->request_body = r->request_body;

#if (NGX_HTTP_SPDY)
sr->spdy_stream = r->spdy_stream;
#endif

sr->method = NGX_HTTP_GET;
sr->http_version = r->http_version;

Expand Down Expand Up @@ -4130,6 +4141,18 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
#endif
}

if (ngx_strcmp(value[n].data, "spdy") == 0) {
#if (NGX_HTTP_SPDY)
lsopt.spdy = 1;
continue;
#else
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"the \"spdy\" parameter requires "
"ngx_http_spdy_module");
return NGX_CONF_ERROR;
#endif
}

if (ngx_strncmp(value[n].data, "so_keepalive=", 13) == 0) {

if (ngx_strcmp(&value[n].data[13], "on") == 0) {
Expand Down
8 changes: 7 additions & 1 deletion src/http/ngx_http_core_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ typedef struct {
#if (NGX_HTTP_SSL)
unsigned ssl:1;
#endif
#if (NGX_HTTP_SPDY)
unsigned spdy:1;
#endif
#if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
unsigned ipv6only:1;
#endif
Expand Down Expand Up @@ -232,7 +235,10 @@ struct ngx_http_addr_conf_s {
ngx_http_virtual_names_t *virtual_names;

#if (NGX_HTTP_SSL)
ngx_uint_t ssl; /* unsigned ssl:1; */
unsigned ssl:1;
#endif
#if (NGX_HTTP_SPDY)
unsigned spdy:1;
#endif
};

Expand Down
Loading

0 comments on commit fab658f

Please sign in to comment.