Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
2577d24
feat: implement cors #2015
maifeeulasad May 11, 2026
f391f85
integration: cors in xml-http-request
maifeeulasad May 11, 2026
09bcf53
integration: cors in fetch
maifeeulasad May 11, 2026
aa77011
fix: cors preflight validation and vary handling
maifeeulasad May 11, 2026
93ff253
Merge branch 'main' into feat-cors-maifee
maifeeulasad May 11, 2026
9732adf
chore: listed cors as implemented feature
maifeeulasad May 11, 2026
30462fb
fix: resolve issues from merging main
maifeeulasad May 11, 2026
69679f4
lint: ran `zig fmt ./`
maifeeulasad May 12, 2026
eaa95d4
Merge branch 'lightpanda-io:main' into feat-cors-maifee
maifeeulasad May 13, 2026
8bcca74
feat: cehck if header is exposed for cors
maifeeulasad Jun 10, 2026
6a307db
integration: build cors header for fetch
maifeeulasad Jun 10, 2026
950b714
integration: build cors header for xml http request
maifeeulasad Jun 10, 2026
81527cd
test: setup for cors pass and failing
maifeeulasad Jun 10, 2026
0400274
test: cors for fetch
maifeeulasad Jun 10, 2026
11fc749
test: cors for xhr
maifeeulasad Jun 10, 2026
26fce96
lint: ran `zig fmt ./`
maifeeulasad Jun 10, 2026
0697a54
Merge branch 'feat-cors-maifee' of https://github.com/maifeeulasad/br…
maifeeulasad Jun 10, 2026
36cf969
feat: build pre flight header for cors
maifeeulasad Jun 10, 2026
2c543dc
fix: cors build issue
maifeeulasad Jun 10, 2026
0e251ef
integration: preflight request for cors in xml http request
maifeeulasad Jun 10, 2026
2abac18
integration: preflight request for cors in fetch
maifeeulasad Jun 10, 2026
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ You may still encounter errors or crashes. Please open an issue with specifics i

Here are the key features we have implemented:

- [ ] CORS [#2015](https://github.com/lightpanda-io/browser/issues/2015)
- [x] CORS ([CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CORS))
- [x] HTTP loader ([Libcurl](https://curl.se/libcurl/))
- [x] HTML parser ([html5ever](https://github.com/servo/html5ever))
- [x] DOM tree
Expand Down
81 changes: 81 additions & 0 deletions src/browser/tests/net/fetch.html
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,84 @@
});
}
</script>

<script id=fetch_cors_ok type=module>
{
const state = await testing.async();
const response = await fetch('http://localhost:9582/cors/ok');
const text = await response.text();

state.resolve();

await state.done(() => {
testing.expectEqual(200, response.status);
testing.expectEqual(true, response.ok);
testing.expectEqual('cors', response.type);
testing.expectEqual('cors-ok', text);
testing.expectEqual('text/plain', response.headers.get('Content-Type'));
testing.expectEqual('allowed', response.headers.get('X-Test-Header'));
testing.expectEqual(null, response.headers.get('X-Blocked'));
testing.expectEqual(null, response.headers.get('Content-Length'));
});
}
</script>

<script id=fetch_cors_credentials type=module>
{
const state = await testing.async();
const response = await fetch('http://localhost:9582/cors/cred', {
credentials: 'include'
});
const text = await response.text();

state.resolve();

await state.done(() => {
testing.expectEqual(200, response.status);
testing.expectEqual(true, response.ok);
testing.expectEqual('cors', response.type);
testing.expectEqual('cors-cred', text);
testing.expectEqual('allowed', response.headers.get('X-Test-Header'));
});
}
</script>

<script id=fetch_cors_blocked type=module>
{
const state = await testing.async();
try {
await fetch('http://localhost:9582/cors/block');
state.resolve({ ok: false });
} catch (e) {
state.resolve({ ok: true, name: e.name });
}

await state.done((result) => {
testing.expectEqual(true, result.ok);
testing.expectEqual('TypeError', result.name);
});
}
</script>

<script id=fetch_cors_non_simple_blocked type=module>
{
const state = await testing.async();
try {
await fetch('http://localhost:9582/cors/ok', {
method: 'POST',
headers: {
'X-Custom-Header': '1'
},
body: 'hi'
});
state.resolve({ ok: false });
} catch (e) {
state.resolve({ ok: true, name: e.name });
}

await state.done((result) => {
testing.expectEqual(true, result.ok);
testing.expectEqual('TypeError', result.name);
});
}
</script>
73 changes: 73 additions & 0 deletions src/browser/tests/net/xhr.html
Original file line number Diff line number Diff line change
Expand Up @@ -386,3 +386,76 @@
});
}
</script>

<script id=xhr_cors_ok type=module>
{
const state = await testing.async();
const req = new XMLHttpRequest();
req.onload = () => { state.resolve({ ok: true }); };
req.onerror = () => { state.resolve({ ok: false }); };
req.open('GET', 'http://localhost:9582/cors/ok');
req.send();

await state.done((result) => {
testing.expectEqual(true, result.ok);
testing.expectEqual(200, req.status);
testing.expectEqual('cors-ok', req.responseText);
testing.expectEqual('allowed', req.getResponseHeader('X-Test-Header'));
testing.expectEqual(null, req.getResponseHeader('X-Blocked'));
const all = req.getAllResponseHeaders();
testing.expectEqual(false, all.toLowerCase().includes('x-blocked'));
});
}
</script>

<script id=xhr_cors_credentials type=module>
{
const state = await testing.async();
const req = new XMLHttpRequest();
req.onload = () => { state.resolve({ ok: true }); };
req.onerror = () => { state.resolve({ ok: false }); };
req.withCredentials = true;
req.open('GET', 'http://localhost:9582/cors/cred');
req.send();

await state.done((result) => {
testing.expectEqual(true, result.ok);
testing.expectEqual(200, req.status);
testing.expectEqual('cors-cred', req.responseText);
testing.expectEqual('allowed', req.getResponseHeader('X-Test-Header'));
});
}
</script>

<script id=xhr_cors_blocked type=module>
{
const state = await testing.async();
const req = new XMLHttpRequest();
req.onload = () => { state.resolve({ ok: false }); };
req.onerror = () => { state.resolve({ ok: true }); };
req.open('GET', 'http://localhost:9582/cors/block');
req.send();

await state.done((result) => {
testing.expectEqual(true, result.ok);
testing.expectEqual(0, req.status);
});
}
</script>

<script id=xhr_cors_non_simple_blocked type=module>
{
const state = await testing.async();
const req = new XMLHttpRequest();
req.onload = () => { state.resolve({ ok: false }); };
req.onerror = () => { state.resolve({ ok: true }); };
req.open('POST', 'http://localhost:9582/cors/ok');
req.setRequestHeader('X-Custom-Header', '1');
req.send('hi');

await state.done((result) => {
testing.expectEqual(true, result.ok);
testing.expectEqual(0, req.status);
});
}
</script>
Loading
Loading