mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-15 15:42:52 +00:00
The example shows how to write a test that depends on custom HTTP headers in the response. This will be useful for testing browser JS that depends on how Ladybird processes response headers, eg CORS headers like Access-Control-Allow-Origin and others.
29 lines
1 KiB
HTML
29 lines
1 KiB
HTML
<script src="./include.js"></script>
|
|
<script>
|
|
asyncTest(async (done) => {
|
|
try {
|
|
const httpServer = httpTestServer();
|
|
const url = await httpServer.createEcho("GET", "/test-http-test-server", {
|
|
status: 200,
|
|
headers: {
|
|
"Access-Control-Allow-Origin": "*", // necessary when running test using file://...
|
|
"Access-Control-Expose-Headers": "X-Custom-Header", // tells the browser which headers to expose to JS
|
|
"Content-Type": "text/plain",
|
|
"X-Custom-Header": "well hello friends",
|
|
},
|
|
body: "hello world!",
|
|
});
|
|
const result = await fetch(url);
|
|
const headers = result.headers;
|
|
|
|
if (headers.get("X-Custom-Header") === "well hello friends") {
|
|
println("PASS");
|
|
} else {
|
|
println("FAIL");
|
|
}
|
|
} catch (err) {
|
|
println("FAIL - " + err);
|
|
}
|
|
done();
|
|
});
|
|
</script>
|