-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
S3 HEAD request 403 error #868
Comments
Ah thanks for identify the issue before it goes live :) I will look into it. |
Interesting this appears to be happening due to httr2. When I switched back to |
So when i comment out all the httr2 and replace with httr. The connection works fine. request_aws <- function(url, http_request) {
# req <- httr2::request(url)
# req$method <- http_request$method
# req$headers <- http_request$header
# req$policies$error_is_error <- function(resp) FALSE
# if (!is.null(http_request$body)) {
# req$body <- list(data = http_request$body, type = "raw", content_type = "", params = list())
# }
# req <- req_options(
# .req = req,
# timeout_ms = http_request$timeout * 1000,
# connecttimeout = http_request$connect_timeout,
# debugfunction = paws_debug,
# verbose = isTRUE(getOption("paws.log_level") >= 3L)
# )
# if (http_request$stream_api) {
# return(req_perform_connection(req))
# } else {
dest <- NULL
if (!is.null(http_request$dest)) {
dest <- httr::write_disk(http_request$dest, TRUE)
}
timeout_config <- Filter(
Negate(is.null),
list(connecttimeout = http_request$connect_timeout, timeout = http_request$timeout)
)
timeout <- do.call(httr::config, timeout_config)
httr::VERB(
http_request$method,
url = url,
config = c(httr::add_headers(.headers = unlist(http_request$header)), dest),
body = http_request$body,
httr::verbose(),
timeout
)
# return(req_perform(req, path = http_request$dest))
# }
} |
library(paws)
client <- s3(config(credentials(profile = "paws")))
bucket <- "test-paws-common-head-bucket-1"
response <- client$head_object(
Bucket = bucket,
Key = "x"
)
# -> HEAD /x HTTP/1.1
# -> Host: test-paws-common-head-bucket-1.s3.amazonaws.com
# -> Accept-Encoding: deflate, gzip
# -> Accept: application/json, text/xml, application/xml, */*
# -> User-Agent: paws/0.8.0 (R4.4.2; darwin20; aarch64)
# -> Content-Length: 0
# -> X-Amz-Date: 20250103T124113Z
# -> X-Amz-Content-Sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
# -> Authorization: AWS4-HMAC-SHA256 Credential=DUMMY/20250103/us-east-1/s3/aws4_request, SignedHeaders=content-length;host;x-amz-content-sha256;x-amz-date, Signature=986495378caa6eb14a543e497582e2a8050c0fd6117856c5050306201c7f2905
# ->
# <- HTTP/1.1 200 OK
# <- x-amz-id-2: 1dnQkiY4Xns0f2wz/0M25mbRPHeK7i/BqqJaeiepk94TX1bb5OI9mvk0DRcsRJDc48cPilyOyGE=
# <- x-amz-request-id: J7MGZKN4JPWQ23H0
# <- Date: Fri, 03 Jan 2025 12:41:15 GMT
# <- Last-Modified: Thu, 02 Jan 2025 16:50:50 GMT
# <- ETag: "ab56b4d92b40713acc5af89985d4b786"
# <- x-amz-server-side-encryption: AES256
# <- Accept-Ranges: bytes
# <- Content-Type: binary/octet-stream
# <- Content-Length: 5
# <- Server: AmazonS3
# <- |
Oh hang on it looks like httr2 is using "POST" method instead of HEAD DEBUG [2025-01-03 13:18:50.158]: -> POST /x HTTP/1.1
-> Host: test-paws-common-head-bucket-1.s3.amazonaws.com
-> Accept: */*
-> Accept-Encoding: deflate, gzip
-> User-Agent: paws/0.8.0 (R4.4.2; darwin20; aarch64)
-> Content-Length: 0
-> X-Amz-Date: 20250103T131157Z
-> X-Amz-Content-Sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
-> Authorization: AWS4-HMAC-SHA256 Credential= DUMMY/20250103/us-east-1/s3/aws4_request, SignedHeaders=content-length;host;x-amz-content-sha256;x-amz-date, Signature=ee02777c2bbd78a9d3a6fbb3427ddd7b9e44c3c97d796b175eb162c8211374ef
-> |
I think I have found the issue. if (!is.null(http_request$body)) {
req$body <- list(data = http_request$body, type = "raw", content_type = "", params = list())
} This will add a body regardless. So if we add a check on the method as well this should ensure we send an empty body for HEAD calls. if (!is.null(http_request$body) && http_request$method != "HEAD") {
req$body <- list(data = http_request$body, type = "raw", content_type = "", params = list())
} |
Thanks! #870 fixes it for me. |
The following reprex runs without error in the current CRAN versions of
paws.common
andpaws.storage
(0.7.7 and 0.7.0) but throws an error using the development versions (0.8.0 for both).Created on 2025-01-02 with reprex v2.1.1
Session info
The text was updated successfully, but these errors were encountered: