Skip to content

Commit

Permalink
Proposed fix to fsprojects#1420 on extra newline before endBoundarySt…
Browse files Browse the repository at this point in the history
…ream
  • Loading branch information
Markus committed Jan 1, 2022
1 parent f5f4e1e commit 7da8d26
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
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

0 comments on commit 7da8d26

Please sign in to comment.