r-lib / httr2

Make HTTP requests and process their responses. A modern reimagining of httr.
https://httr2.r-lib.org
Other
237 stars 59 forks source link

Can't set Host header via req_headers() #564

Open i2z1 opened 6 days ago

i2z1 commented 6 days ago

I am trying to upload file with httr2 to S3 with custom endpoint (so have problems using aws.s3 package, so making it with httr2). While constructing request I found that cant overide Host header with req_headers() function, it always matches to base url, provided with request() function.


  resp <- request(s3baseurl) %>% 
    req_method("PUT") %>% 
    req_body_file(path = file) %>% 
    req_headers(
      "Host" = paste0(bucket, ".storage.example.com"),
      "Date" = dateValue,
      "ContentType" = contentType,
      "Authorization" = paste0("AWS ", s3_key_id, ":", signature)) %>% 
    req_dry_run()

Output:

PUT / HTTP/1.1
Host: example.com
User-Agent: httr2/1.0.5 r-curl/5.2.3 libcurl/8.10.1
Accept: */*
Accept-Encoding: deflate, gzip, br, zstd
Date: Mon, 14 Oct 2024 17:24:29 +0300
ContentType: text/xml
Authorization: AWS YCAJEsP-XW0vHQNghKS2t68GK:XZHHgch9Qbm1u6pVsQv8HpjtPMI=
Content-Length: 38922

38922 bytes of binary data

Is there are some way to change Host header with httr2?

hadley commented 4 days ago

It looks like this is an artifact of the way that req_dry_run() works; I think it should actually be setting the host header for real requests.