| |
---|
| | static ngx_int_t ngx_header_inspect_from_header(ngx_header_inspect_loc_conf_t *conf, ngx_log_t *log, ngx_str_t value); |
---|
| | static ngx_int_t ngx_header_inspect_ifrange_header(ngx_header_inspect_loc_conf_t *conf, ngx_log_t *log, ngx_str_t value); |
---|
| | static ngx_int_t ngx_header_inspect_pragma_header(ngx_header_inspect_loc_conf_t *conf, ngx_log_t *log, ngx_str_t value); |
---|
| | static ngx_int_t ngx_header_inspect_contenttype_header(ngx_header_inspect_loc_conf_t *conf, ngx_log_t *log, ngx_str_t value); |
---|
| | static ngx_int_t ngx_header_inspect_contentmd5_header(ngx_header_inspect_loc_conf_t *conf, ngx_log_t *log, ngx_str_t value); |
---|
| | static ngx_int_t ngx_header_inspect_date_header(ngx_header_inspect_loc_conf_t *conf, ngx_log_t *log, char *header, ngx_str_t value); |
---|
| | static ngx_int_t ngx_header_inspect_process_request(ngx_http_request_t *r); |
---|
| | |
---|
| | static void *ngx_header_inspect_create_conf(ngx_conf_t *cf); |
---|
| |
---|
| | |
---|
| | return rc; |
---|
| | } |
---|
| | |
---|
| | static ngx_int_t ngx_header_inspect_contentmd5_header(ngx_header_inspect_loc_conf_t *conf, ngx_log_t *log, ngx_str_t value) { |
---|
| | ngx_uint_t i; |
---|
| | u_char d; |
---|
| | |
---|
| | if ( value.len == 0 ) { |
---|
| | if ( conf->log ) { |
---|
| | ngx_log_error(NGX_LOG_ALERT, log, 0, "header_inspect: empty Content-MD5 header"); |
---|
| | } |
---|
| | return NGX_ERROR; |
---|
| | } |
---|
| | |
---|
| | for ( i = 0; i < value.len; i++ ) { |
---|
| | d = value.data[i]; |
---|
| | |
---|
| | if ( (d >= '0') && (d <= '9') ) { |
---|
| | continue; |
---|
| | } |
---|
| | if ( (d >= 'a') && (d <= 'z') ) { |
---|
| | continue; |
---|
| | } |
---|
| | if ( (d >= 'A') && (d <= 'Z') ) { |
---|
| | continue; |
---|
| | } |
---|
| | if ( (d == '+') || (d == '/') ) { |
---|
| | continue; |
---|
| | } |
---|
| | if ( d == '=' ) { |
---|
| | i++; |
---|
| | while ( i < value.len ) { |
---|
| | if ( value.data[i] != '=' ) { |
---|
| | if ( conf->log ) { |
---|
| | ngx_log_error(NGX_LOG_ALERT, log, 0, "header_inspect: trailing characters at position %d in Content-MD5 header \"%s\"", i, value.data); |
---|
| | } |
---|
| | return NGX_ERROR; |
---|
| | } |
---|
| | i++; |
---|
| | } |
---|
| | break; |
---|
| | } |
---|
| | if ( conf->log ) { |
---|
| | ngx_log_error(NGX_LOG_ALERT, log, 0, "header_inspect: illegal character at position %d in Content-MD5 header \"%s\"", i, value.data); |
---|
| | } |
---|
| | return NGX_ERROR; |
---|
| | } |
---|
| | |
---|
| | return NGX_OK; |
---|
| | } |
---|
| | |
---|
| | static ngx_int_t ngx_header_inspect_contenttype_header(ngx_header_inspect_loc_conf_t *conf, ngx_log_t *log, ngx_str_t value) { |
---|
| | ngx_uint_t v; |
---|
| | |
---|
| | if ( value.len < 3 ) { |
---|
| |
---|
| | rc = ngx_header_inspect_contenttype_header(conf, r->connection->log, h[i].value); |
---|
| | if ((rc != NGX_OK) && conf->block) { |
---|
| | return NGX_HTTP_BAD_REQUEST; |
---|
| | } |
---|
| | } else if ((h[i].key.len == 11) && (ngx_strcmp("Content-MD5", h[i].key.data) == 0) ) { |
---|
| | rc = ngx_header_inspect_contentmd5_header(conf, r->connection->log, h[i].value); |
---|
| | if ((rc != NGX_OK) && conf->block) { |
---|
| | return NGX_HTTP_BAD_REQUEST; |
---|
| | } |
---|
| | } else { |
---|
| | /* TODO: support for other headers */ |
---|
| | if (conf->log_uninspected) { |
---|
| | ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, "header_inspect: uninspected header \"%s: %s\"", h[i].key.data, h[i].value.data); |
---|
| |
---|
| | |