11local format = string.format
22local tostring = tostring
3+ local ngx = ngx
34local ngx_get_method = ngx .req .get_method
45local ngx_http_version = ngx .req .http_version
6+ local ngx_req_get_headers = ngx .req .get_headers
57
68local resty_url = require " resty.url"
79local url_helper = require (' resty.url_helper' )
@@ -12,7 +14,6 @@ local file_size = require("resty.file").file_size
1214local client_body_reader = require (" resty.http.request_reader" ).get_client_body_reader
1315local send_response = require (" resty.http.response_writer" ).send_response
1416local proxy_response = require (" resty.http.response_writer" ).proxy_response
15- local concat = table.concat
1617
1718local _M = { }
1819
@@ -50,9 +51,11 @@ local function forward_https_request(proxy_uri, uri, proxy_opts)
5051 local sock
5152 local opts = proxy_opts or {}
5253 local req_method = ngx_get_method ()
53- local encoding = ngx .req .get_headers ()[" Transfer-Encoding" ]
54+ local headers = ngx_req_get_headers (0 , true )
55+
56+ local encoding = headers [" Transfer-Encoding" ]
5457 local is_chunked = encoding and encoding :lower () == " chunked"
55- local content_type = ngx . req . get_headers () [" Content-Type" ]
58+ local content_type = headers [" Content-Type" ]
5659 local content_type_is_urlencoded = content_type and content_type :lower () == " application/x-www-form-urlencoded"
5760 local raw = false
5861
@@ -123,7 +126,7 @@ local function forward_https_request(proxy_uri, uri, proxy_opts)
123126 ngx .exit (ngx .HTTP_INTERNAL_SERVER_ERROR )
124127 end
125128
126- ngx . req . set_header ( " Content-Length" , tostring (contentLength ) )
129+ headers [ " Content-Length" ] = tostring (contentLength )
127130 end
128131 end
129132 end
@@ -132,16 +135,16 @@ local function forward_https_request(proxy_uri, uri, proxy_opts)
132135 -- header, otherwise the upstream won't be able to read the body as it expected chunk encoded
133136 -- body
134137 if is_chunked then
135- ngx . req . set_header ( " Transfer-Encoding " , nil )
138+ headers [ " Content-Length " ] = nil
136139 end
137140 end
138141 end
139142
140143 local request = {
141144 uri = uri ,
142- method = ngx . req . get_method () ,
143- headers = ngx . req . get_headers ( 0 , true ) ,
144- path = format ( ' %s%s%s ' , ngx .var .uri , ngx .var .is_args , ngx .var .query_string or ' ' ),
145+ method = req_method ,
146+ headers = headers ,
147+ path = ngx .var .uri .. ngx .var .is_args .. ( ngx .var .query_string or ' ' ),
145148 body = body ,
146149 proxy_uri = proxy_uri ,
147150 proxy_options = opts
@@ -199,7 +202,7 @@ function _M.request(upstream, proxy_uri)
199202 local proxy_auth
200203
201204 if proxy_uri .user or proxy_uri .password then
202- proxy_auth = " Basic " .. ngx .encode_base64 (concat ({ proxy_uri .user or ' ' , proxy_uri .password or ' ' }, ' : ' ))
205+ proxy_auth = " Basic " .. ngx .encode_base64 (( proxy_uri .user or ' ' ) .. " : " .. ( proxy_uri .password or ' ' ))
203206 end
204207
205208 if uri .scheme == ' http' then -- rewrite the request to use http_proxy
0 commit comments