diff mod_storage_s3/mod_storage_s3.lua @ 5670:2c9d72ef829e

mod_storage_s3: Handle signing of request ?query part
author Kim Alvefur <zash@zash.se>
date Sat, 14 Oct 2023 21:40:20 +0200
parents 30f91daa40b4
children c8322c64a548
line wrap: on
line diff
--- a/mod_storage_s3/mod_storage_s3.lua	Sat Oct 14 17:31:06 2023 +0200
+++ b/mod_storage_s3/mod_storage_s3.lua	Sat Oct 14 21:40:20 2023 +0200
@@ -35,7 +35,7 @@
 
 local aws4_format = "AWS4-HMAC-SHA256 Credential=%s/%s, SignedHeaders=%s, Signature=%s";
 
-local function new_request(method, path, payload)
+local function new_request(method, path, query, payload)
 	local request = url.parse(base_uri);
 	request.path = path;
 
@@ -69,6 +69,16 @@
 	local canonical_headers = array();
 	local signed_headers = array()
 
+	if query then
+		local sorted_query = array();
+		for name, value in it.sorted_pairs(query) do
+			sorted_query:push({ name = name; value = value });
+		end
+		sorted_query:sort(function (a,b) return a.name < b.name end)
+		canonical_query = httputil.formencode(sorted_query):gsub("%%%x%x", string.upper);
+		request.query = canonical_query;
+	end
+
 	for header_name, header_value in it.sorted_pairs(headers) do
 		header_name = header_name:lower();
 		canonical_headers:push(header_name .. ":" .. header_value .. "\n");