From 835953ea30de789293082f7f4c1c0f45566fae21 Mon Sep 17 00:00:00 2001 From: Jeroen Ooms Date: Tue, 28 Apr 2020 22:16:05 +0200 Subject: [PATCH] Allow charset in multipart Content-Type Closes #3 --- DESCRIPTION | 4 ++-- NEWS | 3 +++ R/get_boundary.R | 6 ++++-- R/parse_http.R | 2 +- man/demo_httpuv.Rd | 3 ++- man/demo_rhttpd.Rd | 3 ++- 6 files changed, 14 insertions(+), 7 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 4b1d2b1..3d0c956 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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 Description: Parses http request data in application/json, multipart/form-data, @@ -16,5 +16,5 @@ Imports: Suggests: httpuv, testthat -RoxygenNote: 6.1.1 +RoxygenNote: 7.0.2 Language: en-US diff --git a/NEWS b/NEWS index 95e2e20..c04d4e7 100644 --- a/NEWS +++ b/NEWS @@ -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 diff --git a/R/get_boundary.R b/R/get_boundary.R index e2339f3..0a69bc5 100644 --- a/R/get_boundary.R +++ b/R/get_boundary.R @@ -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) diff --git a/R/parse_http.R b/R/parse_http.R index e5009ce..3b5c2ad 100644 --- a/R/parse_http.R +++ b/R/parse_http.R @@ -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)) diff --git a/man/demo_httpuv.Rd b/man/demo_httpuv.Rd index 6b84b5d..33367ae 100644 --- a/man/demo_httpuv.Rd +++ b/man/demo_httpuv.Rd @@ -14,6 +14,7 @@ Starts the httpuv web server and hosts a simple form including a file upload to demo the multipart parser. } \seealso{ -Other demo: \code{\link{demo_rhttpd}} +Other demo: +\code{\link{demo_rhttpd}()} } \concept{demo} diff --git a/man/demo_rhttpd.Rd b/man/demo_rhttpd.Rd index 519e6ba..68a9aa9 100644 --- a/man/demo_rhttpd.Rd +++ b/man/demo_rhttpd.Rd @@ -11,6 +11,7 @@ Starts the Rhttpd web server and hosts a simple form including a file upload to demo the multipart parser. } \seealso{ -Other demo: \code{\link{demo_httpuv}} +Other demo: +\code{\link{demo_httpuv}()} } \concept{demo}