Skip to content

Commit

Permalink
Enable sending blank request headers
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroen committed Jan 30, 2024
1 parent 5e0d608 commit 34fd602
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
5.2.1
- In handle_setheader(), setting a header to a non-empty whitespace string will
now send a blank header. Using an empty string will still remove the header
alltogether (this has not changed).
- Fix an issue where curl_fetch_stream() might not return all bytes received
by the C layer if the server closed the connection mid-response.
- No longer enable CURLOPT_UNRESTRICTED_AUTH by default
Expand Down
5 changes: 3 additions & 2 deletions R/handle.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ handle_setheaders <- function(handle, ..., .list = list()){
opts$Expect = ""
names <- names(opts)
values <- as.character(unlist(opts))
vec <- paste0(names, ": ", values)
.Call(R_handle_setheaders, handle, vec)
postfix <- ifelse(grepl("^\\s+$", values), ";", paste(":", values))
headers <- paste0(names, postfix)
.Call(R_handle_setheaders, handle, headers)
invisible(handle)
}

Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test-handle.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ test_that("setting request headers", {
expect_length(curl:::handle_getheaders(h), 0)
})


test_that("Set blank and NULL headers", {
skip_if_not_installed('httpuv')
skip_if_not_installed('webutils')
h <- new_handle(url = 'https://httpbin.org/get')
handle_setheaders(h, "accept-encoding" = "", "accept" = "", "user-agent" = "", foo = " ", bar = "\t")
req <- curl::curl_echo(h)
expect_equal(req$headers, c(bar = "", foo = "", host = "httpbin.org"))
})

test_that("Custom vector options", {
h <- new_handle()
x <- c("[email protected]", "[email protected]")
Expand Down

0 comments on commit 34fd602

Please sign in to comment.