diff --git a/lib/acid/httpclient.lua b/lib/acid/httpclient.lua index c280fd8..f372da8 100644 --- a/lib/acid/httpclient.lua +++ b/lib/acid/httpclient.lua @@ -322,8 +322,21 @@ function _M.send_request( self, uri, opts ) local body = opts.body or '' local headers = opts.headers or {} - headers.Host = headers.Host or self.ip - if #body > 0 and headers['Content-Length'] == nil then + local host = headers['Host'] + local content_length = headers['Content-Length'] + local range = headers['Range'] + + if opts.header_case_sensitive then + host = headers['host'] or host + content_length = headers['content-length'] or content_length + range = headers['range'] or range + end + + if host == nil then + headers['Host'] = self.ip + end + + if content_length == nil and #body > 0 then headers['Content-Length'] = #body end @@ -342,8 +355,8 @@ function _M.send_request( self, uri, opts ) uri = self.uri, }) - if headers['Range'] ~= nil then - local r, err, _ = _M.parse_request_range(headers['Range'], nil) + if range ~= nil then + local r, err, _ = _M.parse_request_range(range, nil) if err == nil then self.log.range = {from = r.start, to = r['end']} end diff --git a/t/httpclient_test.t b/t/httpclient_test.t index 70bf498..44e3176 100644 --- a/t/httpclient_test.t +++ b/t/httpclient_test.t @@ -473,3 +473,41 @@ keep-alive 1 --- no_error_log [error] + + +=== TEST 12: test request option header case sensitive +--- http_config eval: $::HttpConfig +--- config + location /t { + content_by_lua ' + local httpclient = require("acid.httpclient") + + local cli = httpclient:new( "127.0.0.1", ngx.var.server_port) + local err, errmes = cli:request( "/b", {headers = {host = "partition.bscstorage.com"}, + header_case_sensitive = true}) + if err ~= nil then + ngx.log(ngx.ERR, "requset error") + return + end + + ngx.say(cli.status) + return + '; + } + + location /b { + content_by_lua ' + local hdr = ngx.req.get_headers(0) + if hdr["host"] ~= "partition.bscstorage.com" then + ngx.status = 400 + else + ngx.status = 200 + end + '; + } +--- request +GET /t +--- response_body +200 +--- no_error_log +[error]