Skip to content

Commit d264362

Browse files
Change HTTP response default encoding from ISO-8859-1 to UTF-8
Matches System.Net.Http.HttpClient behaviour. RFC 2616 specifies ISO-8859-1 as the default, but modern servers, browsers, and HttpClient all default to UTF-8 in practice. This fixes garbled characters when fetching UTF-8 content from servers that don't specify a charset. The responseEncodingOverride parameter can still be used to override for any response, including forcing ISO-8859-1 when needed. Closes #1251 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f6f5b99 commit d264362

7 files changed

Lines changed: 9 additions & 8 deletions

File tree

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 8.1.0-beta
44

5+
- Change HTTP response default encoding from ISO-8859-1 to UTF-8 to match `System.Net.Http.HttpClient` behaviour (closes #1251)
56
- Add `PreferOptionals` parameter to `JsonProvider` and `XmlProvider` (defaults to `true` to match existing behavior; set to `false` to use empty string or `NaN` for missing values, like the CsvProvider default) (closes #649)
67

78
## 8.0.0 - Feb 25 2026

src/FSharp.Data.DesignTime/Csv/CsvProvider.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ type public CsvProvider(cfg: TypeProviderConfig) as this =
264264
+ """</c>.</param>
265265
<param name='CacheRows'>Whether the rows should be caches so they can be iterated multiple times. Defaults to true. Disable for large datasets.</param>
266266
<param name='Culture'>The culture used for parsing numbers and dates. Defaults to the invariant culture.</param>
267-
<param name='Encoding'>The encoding used to read the sample. You can specify either the character set name or the codepage number. Defaults to UTF8 for files, and to ISO-8859-1 the for HTTP requests, unless <c>charset</c> is specified in the <c>Content-Type</c> response header.</param>
267+
<param name='Encoding'>The encoding used to read the sample. You can specify either the character set name or the codepage number. Defaults to UTF8 for files, and for HTTP requests when no <c>charset</c> is specified in the <c>Content-Type</c> response header.</param>
268268
<param name='ResolutionFolder'>A directory that is used when resolving relative file references (at design time and in hosted execution).</param>
269269
<param name='EmbeddedResource'>When specified, the type provider first attempts to load the sample from the specified resource
270270
(e.g. 'MyCompany.MyAssembly, resource_name.csv'). This is useful when exposing types generated by the type provider.</param>

src/FSharp.Data.DesignTime/Html/HtmlProvider.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ type public HtmlProvider(cfg: TypeProviderConfig) as this =
111111
+ String.Join(",", TextConversions.DefaultMissingValues)
112112
+ """</c>.</param>
113113
<param name='Culture'>The culture used for parsing numbers and dates. Defaults to the invariant culture.</param>
114-
<param name='Encoding'>The encoding used to read the sample. You can specify either the character set name or the codepage number. Defaults to UTF8 for files, and to ISO-8859-1 the for HTTP requests, unless <c>charset</c> is specified in the <c>Content-Type</c> response header.</param>
114+
<param name='Encoding'>The encoding used to read the sample. You can specify either the character set name or the codepage number. Defaults to UTF8 for files, and for HTTP requests when no <c>charset</c> is specified in the <c>Content-Type</c> response header.</param>
115115
<param name='ResolutionFolder'>A directory that is used when resolving relative file references (at design time and in hosted execution).</param>
116116
<param name='EmbeddedResource'>When specified, the type provider first attempts to load the sample from the specified resource
117117
(e.g. 'MyCompany.MyAssembly, resource_name.html'). This is useful when exposing types generated by the type provider.</param>

src/FSharp.Data.DesignTime/Json/JsonProvider.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ type public JsonProvider(cfg: TypeProviderConfig) as this =
186186
<param name='SampleIsList'>If true, sample should be a list of individual samples for the inference.</param>
187187
<param name='RootName'>The name to be used to the root type. Defaults to `Root`.</param>
188188
<param name='Culture'>The culture used for parsing numbers and dates. Defaults to the invariant culture.</param>
189-
<param name='Encoding'>The encoding used to read the sample. You can specify either the character set name or the codepage number. Defaults to UTF8 for files, and to ISO-8859-1 the for HTTP requests, unless `charset` is specified in the `Content-Type` response header.</param>
189+
<param name='Encoding'>The encoding used to read the sample. You can specify either the character set name or the codepage number. Defaults to UTF8 for files, and for HTTP requests when no `charset` is specified in the `Content-Type` response header.</param>
190190
<param name='ResolutionFolder'>A directory that is used when resolving relative file references (at design time and in hosted execution).</param>
191191
<param name='EmbeddedResource'>When specified, the type provider first attempts to load the sample from the specified resource
192192
(e.g. 'MyCompany.MyAssembly, resource_name.json'). This is useful when exposing types generated by the type provider.</param>

src/FSharp.Data.DesignTime/Xml/XmlProvider.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ type public XmlProvider(cfg: TypeProviderConfig) as this =
213213
<param name='SampleIsList'>If true, the children of the root in the sample document represent individual samples for the inference.</param>
214214
<param name='Global'>If true, the inference unifies all XML elements with the same name.</param>
215215
<param name='Culture'>The culture used for parsing numbers and dates. Defaults to the invariant culture.</param>
216-
<param name='Encoding'>The encoding used to read the sample. You can specify either the character set name or the codepage number. Defaults to UTF8 for files, and to ISO-8859-1 the for HTTP requests, unless <c>charset</c> is specified in the <c>Content-Type</c> response header.</param>
216+
<param name='Encoding'>The encoding used to read the sample. You can specify either the character set name or the codepage number. Defaults to UTF8 for files, and for HTTP requests when no <c>charset</c> is specified in the <c>Content-Type</c> response header.</param>
217217
<param name='ResolutionFolder'>A directory that is used when resolving relative file references (at design time and in hosted execution).</param>
218218
<param name='EmbeddedResource'>When specified, the type provider first attempts to load the sample from the specified resource
219219
(e.g. 'MyCompany.MyAssembly, resource_name.xml'). This is useful when exposing types generated by the type provider.</param>

src/FSharp.Data.Http/Http.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,8 +1376,8 @@ module HttpEncodings =
13761376
/// ISO-8859-1
13771377
let PostDefaultEncoding = Encoding.GetEncoding("ISO-8859-1") // http://stackoverflow.com/questions/708915/detecting-the-character-encoding-of-an-http-post-request/708942#708942
13781378

1379-
/// ISO-8859-1
1380-
let ResponseDefaultEncoding = Encoding.GetEncoding("ISO-8859-1") // http://www.ietf.org/rfc/rfc2616.txt
1379+
/// UTF-8 (matches System.Net.Http.HttpClient default behaviour; RFC 2616 specifies ISO-8859-1 but modern servers and browsers default to UTF-8)
1380+
let ResponseDefaultEncoding = Encoding.UTF8
13811381

13821382
let internal getEncoding (encodingStr: string) =
13831383
match Int32.TryParse(encodingStr, NumberStyles.Integer, CultureInfo.InvariantCulture) with

tests/FSharp.Data.Core.Tests/HttpEncodings.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ let ``HttpEncodings.PostDefaultEncoding returns ISO-8859-1`` () =
1010
HttpEncodings.PostDefaultEncoding.WebName |> should equal "iso-8859-1"
1111

1212
[<Test>]
13-
let ``HttpEncodings.ResponseDefaultEncoding returns ISO-8859-1`` () =
14-
HttpEncodings.ResponseDefaultEncoding.WebName |> should equal "iso-8859-1"
13+
let ``HttpEncodings.ResponseDefaultEncoding returns UTF-8`` () =
14+
HttpEncodings.ResponseDefaultEncoding.WebName |> should equal "utf-8"
1515

1616
[<Test>]
1717
let ``HttpEncodings.getEncoding with valid encoding name works`` () =

0 commit comments

Comments
 (0)