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

Proposed fix to #1420 on extra newline before endBoundaryStream #1421

Merged
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion src/Net/Http.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1388,7 +1388,8 @@ module internal HttpHelpers =
let bytes = e.GetBytes text
new MemoryStream(bytes) :> Stream

let wholePayload = Seq.append segments [newlineStream(); endBoundaryStream; ]
/// per spec, close-delimiter := "--" boundary "--" CRLF ; no need extra newline
let wholePayload = Seq.append segments [ endBoundaryStream; ]
let wholePayloadLength = wholePayload |> trySumLength
new CombinedStream(wholePayloadLength, wholePayload) :> Stream

Expand Down
5 changes: 3 additions & 2 deletions tests/FSharp.Data.Tests/Http.fs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ let ``correct multipart content format`` () =
let str = Encoding.UTF8.GetString(ms.ToArray())
Console.WriteLine(str)
let singleMultipartFormat file = sprintf "--%s\r\nContent-Disposition: form-data; name=\"%i\"; filename=\"%i\"\r\nContent-Type: application/octet-stream\r\n\r\n%s\r\n" boundary file file content
let finalFormat = [sprintf "\r\n--%s--" boundary] |> Seq.append (seq {for i in [0..numFiles] -> singleMultipartFormat i }) |> String.concat ""
// No need extra newline /r/n before closing delimiter
let finalFormat = [sprintf "--%s--" boundary] |> Seq.append (seq {for i in [0..numFiles] -> singleMultipartFormat i }) |> String.concat ""
str |> should equal finalFormat

[<Test>]
Expand Down Expand Up @@ -244,7 +245,7 @@ let ``Non-seekable streams create non-seekable CombinedStream`` () =
[<Test>]
let ``Seekable streams create Seekable CombinedStream`` () =
let byteLen = 10L
let result = byteLen + 110L //110 is headers
let result = byteLen + 108L // As no extra /r/n, 2 bytes removed, 108 is headers
use ms = new IO.MemoryStream(Array.zeroCreate (int byteLen))
let multiparts = [MultipartItem("","", ms)]
let combinedStream = HttpHelpers.writeMultipart "-" multiparts Encoding.UTF8
Expand Down