You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi! I think I found a bug: when a response has a content-type header with multiple parameters (e.g. "text/xml;charset=utf-8;foo=bar"), then content(response) throws a somewhat cryptic error. I don't think its common to have more than one parameter (usually just charset), but as far as I know it's not illegal to have multiple parameters.
I ultimately figured out this is due to the version of str_split_fixed() that is included within httr not being vectorized (as indicated by the comment at the top of str.R). So parse_media() removes the MIME type, then tries to split each of the two parameters at = but fails because str_split_fixed() is not vectorized and thus expects the input to be a character vector of length 1. In other words:
Not sure if it's easier to vectorize the version of str_split_fixed() in httr, or to have parse_media() run a loop over the vector of parameters (in case there is more than 1).
For now, I'm just manually changing the response header to only one parameter after calling GET(), which fixes the problem.
Using httr v1.1.0
Thanks!
The text was updated successfully, but these errors were encountered:
Hi! I think I found a bug: when a response has a content-type header with multiple parameters (e.g.
"text/xml;charset=utf-8;foo=bar"
), thencontent(response)
throws a somewhat cryptic error. I don't think its common to have more than one parameter (usually justcharset
), but as far as I know it's not illegal to have multiple parameters.Example:
The traceback and subsequent debugging indicate it comes from parsing the content-type header.
For this URL, the content-type has a MIME type (
text/xml
) followed by TWO parameters:parse_media()
only works when there is one parameter in the content-type:I ultimately figured out this is due to the version of
str_split_fixed()
that is included withinhttr
not being vectorized (as indicated by the comment at the top ofstr.R
). Soparse_media()
removes the MIME type, then tries to split each of the two parameters at=
but fails becausestr_split_fixed()
is not vectorized and thus expects the input to be a character vector of length 1. In other words:The stringr version works though:
Not sure if it's easier to vectorize the version of
str_split_fixed()
inhttr
, or to haveparse_media()
run a loop over the vector of parameters (in case there is more than 1).For now, I'm just manually changing the response header to only one parameter after calling
GET()
, which fixes the problem.Using httr v1.1.0
Thanks!
The text was updated successfully, but these errors were encountered: