Skip to content

Commit

Permalink
allow head
Browse files Browse the repository at this point in the history
  • Loading branch information
cirospaciari committed Dec 12, 2024
1 parent a5e6de5 commit adf3238
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/bun.js/webcore/response.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3230,6 +3230,11 @@ pub const Fetch = struct {
// TODO: should we generate the content hash? presigned never uses content-hash, maybe only if a extra option is passed to avoid the cost
var result = credentials.s3Request(url.hostname, url.path, method, null) catch |sign_err| {
switch (sign_err) {
error.MissingCredentials => {
const err = JSC.toTypeError(.ERR_INVALID_ARG_VALUE, "missing s3 credentials", .{}, ctx);
is_error = true;
return JSPromise.rejectedPromiseValue(globalThis, err);
},
error.InvalidMethod => {
const err = JSC.toTypeError(.ERR_INVALID_ARG_VALUE, "method must be GET, PUT, DELETE when using s3 protocol", .{}, ctx);
is_error = true;
Expand Down
4 changes: 4 additions & 0 deletions src/s3.zig
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,20 @@ pub const AWSCredentials = struct {
};

pub fn s3Request(this: *const @This(), bucket: []const u8, path: []const u8, method: bun.http.Method, content_hash: ?[]const u8) !SignResult {
if (this.accessKeyId.len == 0 or this.secretAccessKey.len == 0) return error.MissingCredentials;

const method_name = switch (method) {
.GET => "GET",
.POST, .PUT => "PUT",
.DELETE => "DELETE",
.HEAD => "HEAD",
else => return error.InvalidMethod,
};

if (bucket.len == 0) return error.InvalidPath;
// if we allow path.len == 0 it will list the bucket for now we disallow
if (path.len == 0) return error.InvalidPath;

var path_buffer: [1024 + 63 + 2]u8 = undefined; // 1024 max key size and 63 max bucket name

const normalizedPath = std.fmt.bufPrint(&path_buffer, "/{s}{s}", .{ bucket, if (strings.endsWith(path, "/")) path[0 .. path.len - 1] else path }) catch return error.InvalidPath;
Expand Down

0 comments on commit adf3238

Please sign in to comment.