-
Notifications
You must be signed in to change notification settings - Fork 52
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
Content.Text adds invisible whitespace to output #1105
Comments
What |
I think it expects |
By default, I think the problem might be that it sends empty headers. Can you try replacing let Text (msg: string) =
Content.Custom(
Headers = [Http.Header.Custom "content-type" "text/plain"],
WriteBody = fun s ->
let encoding = System.Text.Encoding.UTF8
use w = new System.IO.StreamWriter(s, encoding)
w.Write msg
) |
Alternately, this should be equivalent: |
Strangely, the above results in the same issue. In Postman, I'm able to download the the response, even though when I open the file it appears empty. However, with the following, I get a true, empty body: let Text (msg: string) =
Content.Custom(
WriteBody = fun s ->
let bytes = System.Text.Encoding.UTF8.GetBytes(msg)
s.Write(bytes, 0, bytes.Length)) |
You mentioned extra characters - can you paste a screenshot of the difference between the two functions above? |
I deleted the file I downloaded from Postman. It's some sort of non-printable whitespace character. When writing original: static member Text (text: string, ?encoding: System.Text.Encoding) : Async<Content<'Endpoint>> =
let encoding = System.Text.Encoding.UTF8
Content.Custom(
WriteBody = fun s ->
use w = new System.IO.StreamWriter(s, encoding)
w.Write msg
) updated: let Text (msg: string) =
Content.Custom(
WriteBody = fun s ->
let bytes = System.Text.Encoding.UTF8.GetBytes(msg)
s.Write(bytes, 0, bytes.Length)
) The only differences are that I get the bytes and write them directly, whereas the original uses a |
It looks like let defaultEncoding = new System.Text.Encoding.UTF8Encoding(false)
let Text (msg: string) =
Content.Custom(
WriteBody = fun s ->
use w = new System.IO.StreamWriter(s, defaultEncoding)
w.Write(msg)
) |
Awesome! I didn’t know about that! |
As |
The tests for the-benchmarker/web-frameworks#2888 are failing. When printed out, they look correct, e.g.
"" = ""
or"0" = "0"
. However, there is evidence of additional characters or at least mismatched encoding. According to the project, encoding should be UTF-8, which should matchContent.Text
's output. However, something is clearly added that doesn't appear to affect normal parsing or processing.The text was updated successfully, but these errors were encountered: