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

Add an example to parse_multipart_form docs #949

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion src/parsemultipart.jl
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ end
"""
parse_multipart_form(req::Request)::Vector{Multipart}

Parse the full mutipart form submission from the client returning and
Parse the full mutipart form submission from the client returning an
array of Multipart objects containing all the data.

The order of the multipart form data in the request should be preserved.
Expand All @@ -231,6 +231,33 @@ The boundary delimiter MUST NOT appear inside any of the encapsulated parts. Not
that the boundary delimiter does not need to have '-' characters, but a line using
the boundary delimiter will start with '--' and end in \r\n.
[RFC2046 5.1](https://tools.ietf.org/html/rfc2046#section-5.1.1)

# Examples
```jldoctest
julia> req = HTTP.Request(
"POST",
"/",
["Content-Type" => "multipart/form-data; boundary=12345"],
"""--12345
Content-Disposition: form-data; name="text"

Hello!
--12345
Content-Disposition: form-data; name="file1"; filename="a.txt"
Content-Type: text/plain

Content of a.txt.

--12345--
""" |> str -> replace(str, "\n" => "\r\n"));

julia> HTTP.MultiPartParsing.parse_multipart_form(req)
2-element Vector{HTTP.Forms.Multipart}:
HTTP.Multipart(data=::Base.GenericIOBuffer{SubArray{UInt8, 1, Vector{UInt8}, Tuple{UnitRange{Int64}}, true}}, contenttype="tex
t/plain", contenttransferencoding=""))
HTTP.Multipart(filename="a.txt", data=::Base.GenericIOBuffer{SubArray{UInt8, 1, Vector{UInt8}, Tuple{UnitRange{Int64}}, true}}
, contenttype="text/plain", contenttransferencoding=""))
```
"""
function parse_multipart_form(msg::Message)::Union{Vector{Multipart}, Nothing}
# parse boundary from Content-Type
Expand Down