Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions lib/acid/httpclient.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
38 changes: 38 additions & 0 deletions t/httpclient_test.t
Original file line number Diff line number Diff line change
Expand Up @@ -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]