本地请求头正常
字段处理直接复制
https://github.com/jie123108/lua-resty-s3
--判断method操作
local function get_method()
-- OUT Headers 由 NGINX 代理发送到外网
local out_headers = ngx.req.get_headers()
-- In Headers 由 客户机 发送到 NGINX
-- 需要重新组包 并加入 CanonicalHeaders
--local req_headers{}
local req_str = out_headers
-- 遍历头部参数
local req = parse_req(req_str)
-- ngx.log(ngx.ERR, "method: ", req.method, ", body:[", req.body, "]")
local cjson = require("cjson")
-- ngx.log(ngx.ERR, "req:::[", cjson.encode(req), "]")
--local auth, sign, extinfo = self.s3_auth:authorization_v4_4test(req.method, req.url, req.headers, req.body)
local req_uri = proc_uri(req.url)
--- POST
--PUT test$file.text HTTP/1.1
--Host: examplebucket.s3.amazonaws.com
--Date: Fri, 24 May 2013 00:00:00 GMT
--Authorization: SignatureToBeCalculated
--x-amz-date: 20130524T000000Z
--x-amz-storage-class: REDUCED_REDUNDANCY
--x-amz-content-sha256: 44ce7dd67c959e0d3524ffac1771dfbba87d2b6b4b4e99e42034a8b803f8b072
--<Payload>
--req.headers
if req.method == "POST" and req.headers["service"] == "dynamodb"
end
--- DELETE
if req.method == "DELETE"
end
--- GET OBJECT
--GET /test.txt HTTP/1.1
--Host: examplebucket.s3.amazonaws.com
--x-amz-date:20130524T000000Z
--Authorization: SignatureToBeCalculated
--Range: bytes=0-9
--x-amz-content-sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
--x-amz-date: 20130524T000000Z
if req.method == "GET" and req.headers["Range"] == "bytes=0-9"
local auth, sign = s3_auth:authorization_v4("GET", req.url, req.headers, "")
end
--- PUT OBJECT
--PUT test$file.text HTTP/1.1
--Host: examplebucket.s3.amazonaws.com
--Date: Fri, 24 May 2013 00:00:00 GMT
--Authorization: SignatureToBeCalculated
--x-amz-date: 20130524T000000Z
--x-amz-storage-class: REDUCED_REDUNDANCY
--x-amz-content-sha256: 44ce7dd67c959e0d3524ffac1771dfbba87d2b6b4b4e99e42034a8b803f8b072
if req.method == "GET" and req.headers["x-amz-storage-class"] == "REDUCED_REDUNDANCY"
local auth, sign = s3_auth:authorization_v4("GET", req.url, req.headers, "")
end
--- GET LIFECYCLE
--GET ?lifecycle HTTP/1.1
--Host: examplebucket.s3.amazonaws.com
--Authorization: SignatureToBeCalculated
--x-amz-date: 20130524T000000Z
--x-amz-content-sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
if(req.method == "GET" and req.url == "?lifecycle")
local auth, sign = s3_auth:authorization_v4("GET", "?lifecycle", req.headers, "")
end
--- Get Bucket
--GET ?max-keys=2&prefix=J HTTP/1.1
--Host: examplebucket.s3.amazonaws.com
--Authorization: SignatureToBeCalculated
--x-amz-date: 20130524T000000Z
--x-amz-content-sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
if req.method == "GET" and req.url == "?max-keys=2&prefix=J"
local auth, sign = s3_auth:authorization_v4("GET", "?max-keys=2&prefix=J", req.headers, "")
end
-- 生成 AUTH
--tb:init()
local s3_auth = awss3auth:new(AWSAccessKeyId, AWSSecretAccessKey, aws_bucket, aws_region, aws_service, req.headers["x-amz-date"])
-- CanonicalHeaders 组包完成
-- 执行 set_header 替换
end