comparison s3/s3_uploader.c @ 206:240337164a80

[Seobeo] SSL should be used for large file as well lol.
author MrJuneJune <me@mrjunejune.com>
date Sun, 15 Feb 2026 11:41:53 -0800
parents 6cdee35a7ba9
children
comparison
equal deleted inserted replaced
205:e07b4b5a66bb 206:240337164a80
151 uri_path = Dowa_Arena_Allocate(p_arena, uri_len); 151 uri_path = Dowa_Arena_Allocate(p_arena, uri_len);
152 snprintf(uri_path, uri_len, "/%s", encoded_key); 152 snprintf(uri_path, uri_len, "/%s", encoded_key);
153 } 153 }
154 154
155 // Build canonical headers (must be sorted alphabetically) 155 // Build canonical headers (must be sorted alphabetically)
156 char content_length_str[32]; 156 // Note: Content-Length is NOT signed for S3 PUT requests (it's sent but not in signature)
157 snprintf(content_length_str, sizeof(content_length_str), "%zu", data_length); 157 size_t headers_len = 512 + strlen(host) + strlen(content_type);
158
159 size_t headers_len = 512 + strlen(host) + strlen(content_type) + strlen(content_length_str);
160 char *canonical_headers = Dowa_Arena_Allocate(p_arena, headers_len); 158 char *canonical_headers = Dowa_Arena_Allocate(p_arena, headers_len);
161 snprintf(canonical_headers, headers_len, 159 snprintf(canonical_headers, headers_len,
162 "content-length:%s\n"
163 "content-type:%s\n" 160 "content-type:%s\n"
164 "host:%s\n" 161 "host:%s\n"
165 "x-amz-content-sha256:%s\n" 162 "x-amz-content-sha256:%s\n"
166 "x-amz-date:%s\n", 163 "x-amz-date:%s\n",
167 content_length_str,
168 content_type, 164 content_type,
169 host, 165 host,
170 payload_hash, 166 payload_hash,
171 ts.datetime); 167 ts.datetime);
172 168
173 const char *signed_headers = "content-length;content-type;host;x-amz-content-sha256;x-amz-date"; 169 const char *signed_headers = "content-type;host;x-amz-content-sha256;x-amz-date";
174 170
175 // Build canonical request 171 // Build canonical request
176 char *canonical_request = s3__build_canonical_request("PUT", 172 char *canonical_request = s3__build_canonical_request("PUT",
177 uri_path, 173 uri_path,
178 "", // No query string 174 "", // No query string
211 207
212 // Execute request using seobeo 208 // Execute request using seobeo
213 Seobeo_Client_Request *p_req = Seobeo_Client_Request_Create(url); 209 Seobeo_Client_Request *p_req = Seobeo_Client_Request_Create(url);
214 Seobeo_Client_Request_Set_Method(p_req, "PUT"); 210 Seobeo_Client_Request_Set_Method(p_req, "PUT");
215 Seobeo_Client_Request_Set_Body(p_req, (const char *)data, data_length); 211 Seobeo_Client_Request_Set_Body(p_req, (const char *)data, data_length);
212 Seobeo_Client_Request_Add_Header_Map(p_req, "Connection", "keep-alive");
216 Seobeo_Client_Request_Add_Header_Map(p_req, "Content-Type", content_type); 213 Seobeo_Client_Request_Add_Header_Map(p_req, "Content-Type", content_type);
217 Seobeo_Client_Request_Add_Header_Map(p_req, "x-amz-date", ts.datetime); 214 Seobeo_Client_Request_Add_Header_Map(p_req, "x-amz-date", ts.datetime);
218 Seobeo_Client_Request_Add_Header_Map(p_req, "x-amz-content-sha256", payload_hash); 215 Seobeo_Client_Request_Add_Header_Map(p_req, "x-amz-content-sha256", payload_hash);
219 Seobeo_Client_Request_Add_Header_Map(p_req, "Authorization", auth_header); 216 Seobeo_Client_Request_Add_Header_Map(p_req, "Authorization", auth_header);
217
218 Seobeo_Log(SEOBEO_DEBUG, "[S3] Uploading %zu bytes to %s\n", data_length, url);
219 Seobeo_Log(SEOBEO_DEBUG, "[S3] Content-Type: %s\n", content_type);
220 Seobeo_Log(SEOBEO_DEBUG, "[S3] x-amz-date: %s\n", ts.datetime);
221 Seobeo_Log(SEOBEO_DEBUG, "[S3] x-amz-content-sha256: %s\n", payload_hash);
222 Seobeo_Log(SEOBEO_DEBUG, "[S3] Authorization: %.80s...\n", auth_header);
220 223
221 Seobeo_Client_Response *p_resp = Seobeo_Client_Request_Execute(p_req); 224 Seobeo_Client_Response *p_resp = Seobeo_Client_Request_Execute(p_req);
222 225
223 if (p_resp) 226 if (p_resp)
224 { 227 {