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

Multipart Body parsing #663

Merged
merged 24 commits into from
Aug 28, 2020
Merged

Multipart Body parsing #663

merged 24 commits into from
Aug 28, 2020

Conversation

schloerke
Copy link
Collaborator

@schloerke schloerke commented Aug 27, 2020

Fixes #662

  • Rename many forms of postBody to body
  • If a body is received by Plumber, store the parsed value in req$body
  • If a multipart body is parsed, the values used in req$argsBody are the plucked parsed values of each part in req$body.
  • parser_octet() only returns the raw value as is

PR task list:

  • Update NEWS
  • Add tests
  • Update documentation with devtools::document()

Pseudo code structure information:

multipart/* POST:
- req$bodyRaw - raw vector
  - req$postbody (obsolete)
- req$argsBody - list(partname = data.frame(), partname2 = raw())
- req$args - will contain list(partname = data.frame(), partname2 = raw())
- req$body = list(partname = webutils_output(), partname2 = webutils_output())

Example req$argsBody

> str(req$body)
List of 5
 $ files:List of 6
  ..$ value              : raw [1:1117] 89 50 4e 47 ...
  ..$ content_disposition: chr "form-data"
  ..$ content_type       : chr "image/png"
  ..$ name               : chr "files"
  ..$ filename           : chr "avatar2-small.png"
  ..$ parsed             : raw [1:1117] 89 50 4e 47 ...
 $ files:List of 6
  ..$ value              : raw 61
  ..$ content_disposition: chr "form-data"
  ..$ content_type       : chr "application/octet-stream"
  ..$ name               : chr "files"
  ..$ filename           : chr "text1.bin"
  ..$ parsed             : raw 61
 $ files:List of 6
  ..$ value              : raw 62
  ..$ content_disposition: chr "form-data"
  ..$ content_type       : chr "application/octet-stream"
  ..$ name               : chr "files"
  ..$ filename           : chr "text2.bin"
  ..$ parsed             : raw 62
 $ files:List of 6
  ..$ value              : raw 63
  ..$ content_disposition: chr "form-data"
  ..$ content_type       : chr "application/octet-stream"
  ..$ name               : chr "files"
  ..$ filename           : chr "text3.bin"
  ..$ parsed             : raw 63
 $ dt   :List of 4
  ..$ value              : raw [1:2] 7b 7d
  ..$ content_disposition: chr "form-data"
  ..$ name               : chr "dt"
  ..$ parsed             : Named list()
 - attr(*, "class")= chr "plumber_multipart"

> str(req$argsBody)
List of 2
 $ files:List of 4
  ..$ avatar2-small.png: raw [1:1117] 89 50 4e 47 ...
  ..$ text1.bin        : raw 61
  ..$ text2.bin        : raw 62
  ..$ text3.bin        : raw 63
 $ dt   : Named list()
> str(req$body)
List of 4
 $ json:List of 4
  ..$ value              : raw [1:59] 7b 0a 20 20 ...
  ..$ content_disposition: chr "form-data"
  ..$ name               : chr "json"
  ..$ parsed             :List of 3
  .. ..$ a: int 2
  .. ..$ b: int 4
  .. ..$ c:List of 2
  .. .. ..$ w: int 3
  .. .. ..$ t: int 5
 $ img1:List of 6
  ..$ value              : raw [1:1117] 89 50 4e 47 ...
  ..$ content_disposition: chr "form-data"
  ..$ content_type       : chr "image/png"
  ..$ name               : chr "img1"
  ..$ filename           : chr "avatar2-small.png"
  ..$ parsed             : raw [1:1117] 89 50 4e 47 ...
 $ img2:List of 6
  ..$ value              : raw [1:1537] 89 50 4e 47 ...
  ..$ content_disposition: chr "form-data"
  ..$ content_type       : chr "image/png"
  ..$ name               : chr "img2"
  ..$ filename           : chr "ragnarok_small.png"
  ..$ parsed             : raw [1:1537] 89 50 4e 47 ...
 $ rds :List of 6
  ..$ value              : raw [1:211] 1f 8b 08 00 ...
  ..$ content_disposition: chr "form-data"
  ..$ content_type       : chr "application/rds"
  ..$ name               : chr "rds"
  ..$ filename           : chr "women.rds"
  ..$ parsed             :'data.frame':	15 obs. of  2 variables:
  .. ..$ height: num [1:15] 58 59 60 61 62 63 64 65 66 67 ...
  .. ..$ weight: num [1:15] 115 117 120 123 126 129 132 135 139 142 ...
 - attr(*, "class")= chr "plumber_multipart"

> str(req$argsBody)
List of 4
 $ json:List of 3
  ..$ a: int 2
  ..$ b: int 4
  ..$ c:List of 2
  .. ..$ w: int 3
  .. ..$ t: int 5
 $ img1:List of 1
  ..$ avatar2-small.png: raw [1:1117] 89 50 4e 47 ...
 $ img2:List of 1
  ..$ ragnarok_small.png: raw [1:1537] 89 50 4e 47 ...
 $ rds :List of 1
  ..$ women.rds:'data.frame':	15 obs. of  2 variables:
  .. ..$ height: num [1:15] 58 59 60 61 62 63 64 65 66 67 ...
  .. ..$ weight: num [1:15] 115 117 120 123 126 129 132 135 139 142 ...

cc @jcheng5

@schloerke schloerke added this to the v1.0.0 - Next CRAN release milestone Aug 27, 2020
@schloerke schloerke requested a review from cpsievert August 27, 2020 17:46
NEWS.md Outdated Show resolved Hide resolved
schloerke and others added 4 commits August 28, 2020 10:05
Co-authored-by: Carson Sievert <cpsievert1@gmail.com>
R/plumber.R Show resolved Hide resolved
NEWS.md Outdated Show resolved Hide resolved
R/parse-body.R Outdated Show resolved Hide resolved
R/parse-query.R Outdated Show resolved Hide resolved
R/parse-body.R Outdated Show resolved Hide resolved
@cpsievert cpsievert self-requested a review August 28, 2020 19:36
@schloerke schloerke merged commit 4714945 into master Aug 28, 2020
@schloerke schloerke deleted the post_body_parsing branch August 28, 2020 23:12
@schloerke schloerke mentioned this pull request Sep 1, 2020
2 tasks
schloerke added a commit that referenced this pull request Sep 1, 2020
* master:
  Multipart body followup (#667)
  Copy in properly sized png logo
  Multipart Body parsing (#663)
  Add `serializer_write_file()` and add to some news entries (#660)
  Update logos to include a url. Add hex submitted to rstudio/hex-stickers
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.

Non-octect multipart files lose their filename
2 participants