Skip to content
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 1.3.2

Released on Friday, November 13 2026.

- Fixed `fetch`, `XMLHttpRequest` and `sendBeacon` sending the `Accept` header of a navigation (`text/html,...`), so that servers choosing by it answered with their web page instead of the data; it is `*/*` unless the script sets one

# 1.3.1

Released on Sunday, November 8 2026.
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ AngleSharp.Io contains code written by (in order of first pull request / commit)

* [Florian Rappl](https://github.com/FlorianRappl)
* [Joel Verhagen](https://github.com/joelverhagen)
* [Michael Thyregod](https://github.com/michaelthyregod)

Without these awesome people AngleSharp.Io could not exist. Thanks to everyone for your contributions! :beers:

Expand Down
2 changes: 1 addition & 1 deletion src/AngleSharp.Io.Docs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@anglesharp/io",
"version": "1.3.0",
"version": "1.3.2",
"preview": true,
"description": "The doclet for the AngleSharp.Io documentation.",
"keywords": [
Expand Down
12 changes: 12 additions & 0 deletions src/AngleSharp.Io.Tests/Beacon/BeaconTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,18 @@ public async Task SameOriginBeaconsAreNotPreflighted()
Assert.AreEqual("https://beacon.example", server.Requests[0].Headers[HeaderNames.Origin]);
}

[Test]
public async Task BeaconsAcceptAnyType()
{
var server = new CorsServer();
var navigator = await server.OpenNavigatorAsync("https://beacon.example/").ConfigureAwait(false);

Assert.IsTrue(navigator.SendBeacon("/collect", "data"));
await WaitForAsync(() => server.Requests.Count == 1).ConfigureAwait(false);

Assert.AreEqual("*/*", server.Requests[0].Headers[HeaderNames.Accept]);
}

[Test]
public async Task PreflightIsSentWithoutCredentialsAndTheBeaconWithThem()
{
Expand Down
32 changes: 32 additions & 0 deletions src/AngleSharp.Io.Tests/Network/FetchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,38 @@ public async Task FetchShouldApplyMethodHeadersAndBody()
}
}

[Test]
public async Task FetchShouldAcceptAnyTypeByDefault()
{
var loader = new TestDocumentLoader(request =>
new TestDownload(Task.FromResult<IResponse>(CreateResponse("https://example.org/api", "{}"))));

var window = await OpenWindowAsync(loader, "https://example.org/base/page").ConfigureAwait(false);
await window.FetchAsync("/api").ConfigureAwait(false);

Assert.AreEqual("*/*", loader.LastRequest.Headers[HeaderNames.Accept]);
}

[Test]
public async Task FetchShouldSendTheAcceptHeaderOfTheScript()
{
var loader = new TestDocumentLoader(request =>
new TestDownload(Task.FromResult<IResponse>(CreateResponse("https://example.org/api", "{}"))));

var window = await OpenWindowAsync(loader, "https://example.org/base/page").ConfigureAwait(false);
var options = new FetchOptions
{
Headers = new Dictionary<String, String>
{
["accept"] = "application/json"
},
};

await window.FetchAsync("/api", options).ConfigureAwait(false);

Assert.AreEqual("application/json", loader.LastRequest.Headers[HeaderNames.Accept]);
}

[Test]
public async Task FetchShouldSetMultipartContentTypeForFormDataWhenMissing()
{
Expand Down
25 changes: 25 additions & 0 deletions src/AngleSharp.Io.Tests/Network/XmlHttpRequesterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,31 @@ public async Task OpenAndSendShouldCreateRequestWithHeadersAndBody()
}
}

[TestCase(null, "*/*")]
[TestCase("application/json", "application/json")]
public async Task SendShouldAcceptAnyTypeUnlessSetByTheScript(String accept, String expected)
{
var loader = new TestDocumentLoader(request =>
{
var response = CreateResponse("https://api.example.test/endpoint", "{}", HttpStatusCode.OK);
return new TestDownload(request.Target, Task.FromResult<IResponse>(response));
});

var xhr = await CreateRequesterAsync(loader, "https://origin.example.test/").ConfigureAwait(false);
xhr.Open("GET", "https://api.example.test/endpoint");

if (accept != null)
{
xhr.SetRequestHeader("Accept", accept);
}

xhr.Send();

await WaitForReadyStateAsync(xhr, RequesterState.Done).ConfigureAwait(false);

Assert.AreEqual(expected, loader.LastRequest.Headers[HeaderNames.Accept]);
}

[Test]
public async Task SendWithFormDataShouldSetMultipartContentTypeWhenMissing()
{
Expand Down
1 change: 1 addition & 0 deletions src/AngleSharp.Io/Dom/BeaconSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ public DocumentRequest CreateRequest()
Referer = Referer,
};

request.Headers[HeaderNames.Accept] = "*/*";
request.Headers[HeaderNames.Origin] = Origin;

if (ContentType is not null)
Expand Down
4 changes: 4 additions & 0 deletions src/AngleSharp.Io/Dom/WindowExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ private static DocumentRequest CreateRequest(IWindow window, Url url, FetchOptio
Referer = window.Document?.DocumentUri,
};

// not the documents a navigation asks for: servers answering by Accept would give
// their web page instead of the data (fetch takes any type unless the script says so)
request.Headers[HeaderNames.Accept] = "*/*";

if (requestOptions.Headers != null)
{
foreach (var pair in requestOptions.Headers.Pairs)
Expand Down
3 changes: 3 additions & 0 deletions src/AngleSharp.Io/Dom/XmlHttpRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ public void Send(Object body = null)
Referer = _window.Document.DocumentUri,
};

// any type, not the documents of a navigation, unless set by the script
request.Headers[HeaderNames.Accept] = "*/*";

foreach (var header in _headers)
{
request.Headers[header.Key] = header.Value;
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<Description>Providers additional requesters and IO helpers for AngleSharp.</Description>
<Product>AngleSharp.Io</Product>
<Version>1.3.0</Version>
<Version>1.3.2</Version>
<LangVersion>latest</LangVersion>
<SignAssembly>true</SignAssembly>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand Down
Loading