Skip to content
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

Support .multi in req_body_form() #371

Merged
merged 4 commits into from
Nov 10, 2023
Merged

Support .multi in req_body_form() #371

merged 4 commits into from
Nov 10, 2023

Conversation

hadley
Copy link
Member

@hadley hadley commented Oct 31, 2023

Fixes #368

@hadley hadley requested a review from mgirlich October 31, 2023 21:43
}

# Format other params
dots[n == 1] <- lapply(dots[n == 1], format_query_param, error_call = error_call)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I stumbled over this issue

devtools::load_all("~/GitHub/httr2/")
#> ℹ Loading httr2
data <- list(a = c("ab", "c"))

request_test("/post") %>%
  req_body_form(!!!data, .multi = "comma") %>%
  req_verbose(body_req = TRUE) %>% 
  req_perform()
#> -> POST /post HTTP/1.1
#> -> Host: 127.0.0.1:50747
#> -> User-Agent: httr2/0.2.3.9000 r-curl/5.1.0 libcurl/8.1.2
#> -> Accept: */*
#> -> Accept-Encoding: deflate, gzip
#> -> Content-Type: application/x-www-form-urlencoded
#> -> Content-Length: 9
#> -> 
#> >> a=ab,c%20
#> <- HTTP/1.1 200 OK
#> <- Connection: close
#> <- Date: Fri, 10 Nov 2023 10:00:31 GMT
#> <- Content-Type: application/json
#> <- Content-Length: 457
#> <- ETag: "6dd433e5"
#> <-
#> <httr2_response>
#> POST http://127.0.0.1:50747/post
#> Status: 200 OK
#> Content-Type: application/json
#> Body: In memory (457 bytes)

Created on 2023-11-10 with reprex v2.0.2

You can see that the body is a=ab,c%20 instead of a=ab,c because white spaces are appended.
In format_query_param() we need to use justify = "none"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, I did that in #355. Maybe that didn't get in this branch? Anyway I'll double check.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No looks like a different problem.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ARGH you need justify = "none" for strings and trim = TRUE for numbers.

@hadley hadley merged commit 2212d2a into main Nov 10, 2023
12 checks passed
@hadley hadley deleted the multi-body-form branch November 10, 2023 20:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add .multi to req_body_form()
2 participants