Skip to content

Commit

Permalink
Allow charset in multipart Content-Type
Browse files Browse the repository at this point in the history
Closes #3
  • Loading branch information
jeroen committed Apr 28, 2020
1 parent 49bf412 commit 835953e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: webutils
Type: Package
Title: Utility Functions for Developing Web Applications
Version: 1.0
Version: 1.1
Author: Jeroen Ooms
Maintainer: Jeroen Ooms <[email protected]>
Description: Parses http request data in application/json, multipart/form-data,
Expand All @@ -16,5 +16,5 @@ Imports:
Suggests:
httpuv,
testthat
RoxygenNote: 6.1.1
RoxygenNote: 7.0.2
Language: en-US
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
1.1
- Allow charset in multipart Content-Type (#3)

1.0
- Ignore additional fields such as charset from the multipart boundary
- Fix a unit test to avoid a bug in libcurl: https://github.com/curl/curl/issues/4246
Expand Down
6 changes: 4 additions & 2 deletions R/get_boundary.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
get_boundary <- function(content_type){
# Check for multipart
if(!grepl("multipart/form-data; boundary=", content_type, fixed = TRUE))
# Check for multipart header
if(!grepl("multipart/form-data;", content_type, fixed = TRUE))
stop("Content type is not multipart/form-data: ", content_type)
if(!grepl("boundary=", content_type, fixed = TRUE))
stop("Multipart content-type header without boundary: ", content_type)

# Extract bounary
m <- regexpr('boundary=[^; ]{2,}', content_type, ignore.case = TRUE)
Expand Down
2 changes: 1 addition & 1 deletion R/parse_http.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ parse_http <- function(body, content_type, ...){
content_type <- sub("Content-Type: ?", "", content_type, ignore.case=TRUE);

# Switch by content-type
if(grepl("multipart/form-data; boundary=", content_type, fixed=TRUE)){
if(grepl("multipart/form-data;", content_type, fixed = TRUE)){
return(parse_multipart(body, get_boundary(content_type)))
} else if(grepl("application/x-www-form-urlencoded", content_type, fixed=TRUE)){
return(parse_query(body))
Expand Down
3 changes: 2 additions & 1 deletion man/demo_httpuv.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/demo_rhttpd.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 835953e

Please sign in to comment.