From 7da8d26de6c2f47f6d2d22fe6029f973c200cdc4 Mon Sep 17 00:00:00 2001 From: Markus Date: Sun, 2 Jan 2022 01:18:12 +0800 Subject: [PATCH] Proposed fix to #1420 on extra newline before endBoundaryStream --- src/Net/Http.fs | 3 ++- tests/FSharp.Data.Tests/Http.fs | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Net/Http.fs b/src/Net/Http.fs index 0c5aeaa5f..cf66853bf 100644 --- a/src/Net/Http.fs +++ b/src/Net/Http.fs @@ -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 diff --git a/tests/FSharp.Data.Tests/Http.fs b/tests/FSharp.Data.Tests/Http.fs index 58682730b..2738baf27 100644 --- a/tests/FSharp.Data.Tests/Http.fs +++ b/tests/FSharp.Data.Tests/Http.fs @@ -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 [] @@ -244,7 +245,7 @@ let ``Non-seekable streams create non-seekable CombinedStream`` () = [] 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