From 54061127c419cdc5082b12a7ee506c39aefa7bbb Mon Sep 17 00:00:00 2001 From: "pangpang@hi-nginx.com" Date: Sun, 30 Dec 2018 07:49:10 +0800 Subject: [PATCH] update subrequest : support http any method --- ngx_http_hi_module/module_config.hpp | 2 +- ngx_http_hi_module/ngx_http_hi_module.cpp | 3 +- ngx_http_hi_module/utils.hpp | 21 +-- src/http/ngx_http_core_module.c | 186 +--------------------- src/http/ngx_http_core_module.h | 3 - 5 files changed, 5 insertions(+), 210 deletions(-) diff --git a/ngx_http_hi_module/module_config.hpp b/ngx_http_hi_module/module_config.hpp index 7f486287..cbb2062a 100644 --- a/ngx_http_hi_module/module_config.hpp +++ b/ngx_http_hi_module/module_config.hpp @@ -10,7 +10,7 @@ extern "C" { #include } -#define HI_NGINX_SERVER_VERSION "1.8.2.1" +#define HI_NGINX_SERVER_VERSION "1.8.2.2" #define HI_NGINX_SERVER_NAME "hi-nginx" #define SESSION_ID_NAME "SESSIONID" #define form_multipart_type "multipart/form-data" diff --git a/ngx_http_hi_module/ngx_http_hi_module.cpp b/ngx_http_hi_module/ngx_http_hi_module.cpp index fc41ffd0..5ae59dd0 100644 --- a/ngx_http_hi_module/ngx_http_hi_module.cpp +++ b/ngx_http_hi_module/ngx_http_hi_module.cpp @@ -918,9 +918,8 @@ static ngx_int_t ngx_http_hi_subrequest_handler(ngx_http_request_t *r) { psr->handler = ngx_http_hi_subrequest_post_handler; psr->data = conf; - ngx_http_request_t *sr; - ngx_int_t rc = ngx_http_subrequest_by_method(r, &conf->subrequest, &r->args, &sr, psr, NGX_HTTP_SUBREQUEST_IN_MEMORY, r->method); + ngx_int_t rc = ngx_http_subrequest(r, &conf->subrequest, &r->args, &sr, psr, NGX_HTTP_SUBREQUEST_IN_MEMORY); if (rc != NGX_OK) { return NGX_ERROR; diff --git a/ngx_http_hi_module/utils.hpp b/ngx_http_hi_module/utils.hpp index a29774ca..d88fdc2c 100644 --- a/ngx_http_hi_module/utils.hpp +++ b/ngx_http_hi_module/utils.hpp @@ -114,26 +114,7 @@ namespace hi { static void deserialize(const std::string& str, std::unordered_map& m) { msgpack::unpack(str.c_str(), str.size()).get().convert(m); } - - static void split(const std::string& s, const std::string& delim, std::vector& v) { - size_t last = 0; - size_t index = s.find_first_of(delim, last); - std::string tmp; - while (index != std::string::npos) { - tmp = std::move(s.substr(last, index - last)); - if (!tmp.empty()) { - v.push_back(std::move(tmp)); - } - last = index + 1; - index = s.find_first_of(delim, last); - } - if (index - last > 0) { - tmp = std::move(s.substr(last, index - last)); - if (!tmp.empty()) { - v.push_back(std::move(tmp)); - } - } - } + } #endif /* UTILS_HPP */ diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c index 7519fb95..81da3938 100644 --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -2298,7 +2298,7 @@ ngx_http_subrequest(ngx_http_request_t *r, sr->stream = r->stream; #endif - sr->method = NGX_HTTP_GET; + sr->method = r->method; sr->http_version = r->http_version; sr->request_line = r->request_line; @@ -2316,189 +2316,7 @@ ngx_http_subrequest(ngx_http_request_t *r, sr->background = (flags & NGX_HTTP_SUBREQUEST_BACKGROUND) != 0; sr->unparsed_uri = r->unparsed_uri; - sr->method_name = ngx_http_core_get_method; - sr->http_protocol = r->http_protocol; - sr->schema = r->schema; - - ngx_http_set_exten(sr); - - sr->main = r->main; - sr->parent = r; - sr->post_subrequest = ps; - sr->read_event_handler = ngx_http_request_empty_handler; - sr->write_event_handler = ngx_http_handler; - - sr->variables = r->variables; - - sr->log_handler = r->log_handler; - - if (sr->subrequest_in_memory) { - sr->filter_need_in_memory = 1; - } - - if (!sr->background) { - if (c->data == r && r->postponed == NULL) { - c->data = sr; - } - - pr = ngx_palloc(r->pool, sizeof(ngx_http_postponed_request_t)); - if (pr == NULL) { - return NGX_ERROR; - } - - pr->request = sr; - pr->out = NULL; - pr->next = NULL; - - if (r->postponed) { - for (p = r->postponed; p->next; p = p->next) { /* void */ } - p->next = pr; - - } else { - r->postponed = pr; - } - } - - sr->internal = 1; - - sr->discard_body = r->discard_body; - sr->expect_tested = 1; - sr->main_filter_need_in_memory = r->main_filter_need_in_memory; - - sr->uri_changes = NGX_HTTP_MAX_URI_CHANGES + 1; - sr->subrequests = r->subrequests - 1; - - tp = ngx_timeofday(); - sr->start_sec = tp->sec; - sr->start_msec = tp->msec; - - r->main->count++; - - *psr = sr; - - if (flags & NGX_HTTP_SUBREQUEST_CLONE) { - sr->method = r->method; - sr->method_name = r->method_name; - sr->loc_conf = r->loc_conf; - sr->valid_location = r->valid_location; - sr->valid_unparsed_uri = r->valid_unparsed_uri; - sr->content_handler = r->content_handler; - sr->phase_handler = r->phase_handler; - sr->write_event_handler = ngx_http_core_run_phases; - -#if (NGX_PCRE) - sr->ncaptures = r->ncaptures; - sr->captures = r->captures; - sr->captures_data = r->captures_data; - sr->realloc_captures = 1; - r->realloc_captures = 1; -#endif - - ngx_http_update_location_config(sr); - } - - return ngx_http_post_request(sr, NULL); -} - -ngx_int_t ngx_http_subrequest_by_method(ngx_http_request_t *r, - ngx_str_t *uri, ngx_str_t *args, ngx_http_request_t **psr, - ngx_http_post_subrequest_t *ps, ngx_uint_t flags,ngx_uint_t method) -{ - ngx_time_t *tp; - ngx_connection_t *c; - ngx_http_request_t *sr; - ngx_http_core_srv_conf_t *cscf; - ngx_http_postponed_request_t *pr, *p; - - if (r->subrequests == 0) { - ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "subrequests cycle while processing \"%V\"", uri); - return NGX_ERROR; - } - - /* - * 1000 is reserved for other purposes. - */ - if (r->main->count >= 65535 - 1000) { - ngx_log_error(NGX_LOG_CRIT, r->connection->log, 0, - "request reference counter overflow " - "while processing \"%V\"", uri); - return NGX_ERROR; - } - - if (r->subrequest_in_memory) { - ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "nested in-memory subrequest \"%V\"", uri); - return NGX_ERROR; - } - - sr = ngx_pcalloc(r->pool, sizeof(ngx_http_request_t)); - if (sr == NULL) { - return NGX_ERROR; - } - - sr->signature = NGX_HTTP_MODULE; - - c = r->connection; - sr->connection = c; - - sr->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module); - if (sr->ctx == NULL) { - return NGX_ERROR; - } - - if (ngx_list_init(&sr->headers_out.headers, r->pool, 20, - sizeof(ngx_table_elt_t)) - != NGX_OK) - { - return NGX_ERROR; - } - - if (ngx_list_init(&sr->headers_out.trailers, r->pool, 4, - sizeof(ngx_table_elt_t)) - != NGX_OK) - { - return NGX_ERROR; - } - - cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); - sr->main_conf = cscf->ctx->main_conf; - sr->srv_conf = cscf->ctx->srv_conf; - sr->loc_conf = cscf->ctx->loc_conf; - - sr->pool = r->pool; - - sr->headers_in = r->headers_in; - - ngx_http_clear_content_length(sr); - ngx_http_clear_accept_ranges(sr); - ngx_http_clear_last_modified(sr); - - sr->request_body = r->request_body; - -#if (NGX_HTTP_V2) - sr->stream = r->stream; -#endif - - sr->method = method; - sr->http_version = r->http_version; - - sr->request_line = r->request_line; - sr->uri = *uri; - - if (args) { - sr->args = *args; - } - - ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, - "http subrequest \"%V?%V\"", uri, &sr->args); - - sr->subrequest_in_memory = (flags & NGX_HTTP_SUBREQUEST_IN_MEMORY) != 0; - sr->waited = (flags & NGX_HTTP_SUBREQUEST_WAITED) != 0; - sr->background = (flags & NGX_HTTP_SUBREQUEST_BACKGROUND) != 0; - - sr->unparsed_uri = r->unparsed_uri; - sr->method_name = ngx_http_core_get_method; + sr->method_name = r->method_name; sr->http_protocol = r->http_protocol; sr->schema = r->schema; diff --git a/src/http/ngx_http_core_module.h b/src/http/ngx_http_core_module.h index 8fda092c..4c6da7c0 100644 --- a/src/http/ngx_http_core_module.h +++ b/src/http/ngx_http_core_module.h @@ -501,9 +501,6 @@ ngx_int_t ngx_http_gzip_ok(ngx_http_request_t *r); ngx_int_t ngx_http_subrequest(ngx_http_request_t *r, ngx_str_t *uri, ngx_str_t *args, ngx_http_request_t **sr, ngx_http_post_subrequest_t *psr, ngx_uint_t flags); -ngx_int_t ngx_http_subrequest_by_method(ngx_http_request_t *r, - ngx_str_t *uri, ngx_str_t *args, ngx_http_request_t **sr, - ngx_http_post_subrequest_t *psr, ngx_uint_t flags,ngx_uint_t method); ngx_int_t ngx_http_internal_redirect(ngx_http_request_t *r, ngx_str_t *uri, ngx_str_t *args); ngx_int_t ngx_http_named_location(ngx_http_request_t *r, ngx_str_t *name);