Commit Graph

24 Commits

Author SHA1 Message Date
Tim Ledbetter
49834ef782 Tests: Add test server endpoint that records the last request's headers 2026-04-25 08:49:04 +02:00
Timothy Flynn
4ad800b594 RequestServer: Use correct request map for stale-while-revalidate cookie
When we request the HTTP cookie for a SWR request, we were providing the
cookie to the standard request corresponding to the SWR request's ID.
This had two effects:

1. The SWR request would never finish.
2. If the corresponding standard request happened to be a connect-only
   request, this would result in a crash as we were expecting it to have
   gone through the normal fetch process.

This was seen on some articles on news.google.com.
2026-04-13 19:43:13 -04:00
Shannon Booth
ba79535d94 Tests/LibWeb: Support absolute paths for WPT files in HTTP test server
Imported WPT tests often load resources using canonical absolute paths,
for example:

/html/browsers/windows/resources/message-parent.html

Our usual strategy is to rewrite such URLs to relative paths during
import so they resolve from the importing test HTML file (which also
allows for loading this HTML as a file://).

That works for same-origin relative loading with the echo server, but it
breaks down when a test constructs a cross-origin URL from an absolute
path, for example:

get_host_info().REMOTE_ORIGIN + "/some/wpt/path.html"

In that case the resource still needs to be fetched at its canonical
absolute path, so rewriting it relative to the importing document is no
longer sufficient.

Update the HTTP test server so /static/ continues to serve from the
general test root, other non-echo requests are served from the imported
WPT tree, and dynamically registered echo responses live under /echo/
to avoid path conflicts.
2026-03-23 22:32:43 +01:00
Shannon Booth
322fc9aff4 Tests/LibWeb: Factor out function to serving static files in echo server
To keep the routing logic as localized as possible.
2026-03-23 22:32:43 +01:00
Shannon Booth
892231ebb2 Tests/LibWeb: Use early return in handle_echo implementation
Reduce some of the nesting by early returning.
2026-03-23 22:32:43 +01:00
Shannon Booth
6db245b1fe Tests/LibWeb: Factor out a function to handle registering echo server
To accomodate for future routing changes without making the handler
too complicated.
2026-03-23 22:32:43 +01:00
Jelle Raaijmakers
f6f7e75ac9 LibWeb: Report actual network error for failed XHRs
Seeing "NetworkError: Network error" when an XHR failed was not that
useful - use the actual error message when available.
2026-03-22 18:58:49 +01:00
Jelle Raaijmakers
61ce8765bc Tests/LibWeb: Support base64-encoded bodies in HTTP test server
This makes it possible to make the HTTP test server respond with images,
for example. We'll need this for a new test we're adding.
2026-03-21 10:29:54 +01:00
Jonathan Gamble
34cecb4643 LibWeb+test-web: Allow identical echo registrations in http-test-server
The http-test-server.py change allows repeated fixed /echo route
registration by Text/input/navigation/iframe-referrer-policy.html.
Before this change, the second registration of the same method+path+def
returned 409, causing include.js to throw and fail the test.

Make /echo registration idempotent for identical definitions and return
success, but keep 409 for conflicting redefinitions of an existing
method+path.
2026-02-25 12:33:35 -06:00
Luke Wilde
84db5d8c1c Meta+test-web: Support per-test .headers files
If a test requires custom response headers, we now serve it via the
http-test-server, which will read the headers file and add them to the
response.
2026-02-19 14:58:09 +01:00
Timothy Flynn
8156531477 LibWeb: Decode Set-Cookie response headers before parsing
It's possible for the cookie value from a Set-Cookie header to contain
invalid UTF-8. We must isomorphic decode this header.

This fixes the /cookies/domain/domain-attribute-idn-host.sub.https.html
WPT test. The test added here is a crash test rather than a text test
because we cannot access the received Set-Cookie header from JS on the
file:// test URL.
2026-02-03 07:20:41 -05:00
CountBleck
bc0cceae1f LibWeb: Add a test checking the referrer of worker script fetches
Also, allow the echo server to reflect headers by substituting it into a
provided template body, enabling them to be read programmatically as
part of a script.
2026-01-31 22:45:08 +01:00
Timothy Flynn
453764d3f0 LibHTTP: Do not respond to Range requests with cached full responses
If we have the response for a non-Range request in the memory cache, we
would previously use it in reply to Range requests. Similar to commit
878b00ae61f998a26aad7f50fae66cf969878ad6, we are just punting on Range
requests in the HTTP caches for now.
2026-01-10 09:02:41 -05:00
Timothy Flynn
9f2ac14521 LibHTTP+RequestServer: Do not flush partial responses to the cache index
If the cURL request completes with anything other than CURLE_OK, we must
not keep the cache entry. For example, if the server's connection closes
while transferring data, we receive CURLE_PARTIAL_FILE. We don't want
this cache entry to be treated as valid in a subsequent request.
2026-01-08 11:59:12 +01:00
Timothy Flynn
4053a5f9d4 Tests/LibWeb: Create a copy of the echoed response headers
Otherwise, updates to the local `response_headers` will update the echo
store, which we do not want in upcoming tests.
2026-01-08 11:59:12 +01:00
Timothy Flynn
a4c8e39b99 test-web: Add basic support for If-Mod-Since requests in our test server
This just lets the test decide on a per-request basis if it wants the
test server to respond with a 304.
2025-11-20 09:33:49 +01:00
Julian Dominguez-Schatz
36bfee7f1b Tests: Add 'reflect' option to http-test-server.py
Add an option to http-test-server.py to return received headers as the
response body. This is useful for checking that outgoing headers are
correct, for example in cookie tests.
2025-09-24 10:12:56 +01:00
Timothy Flynn
18718e0876 Meta: Sort all python imports 2025-06-09 11:25:14 -04:00
rmg-x
0cd4c26ae8 Tests/LibWeb: Fix type for delay_ms property in HTTP echo server
This was mistakenly changed from int -> str in a previous commit:
08b8c88ac3
2024-12-07 15:49:15 +00:00
rmg-x
de595b713d Tests/LibWeb: Allow setting custom reason phrase in HTTP echo server 2024-12-06 06:09:44 +00:00
rmg-x
08b8c88ac3 Tests/LibWeb: Use Optional instead of | None syntax in echo script
The `str | None` syntax is only supported in Python 3.10+ and we can
support more Python versions without compromising readability by
importing the `Optional` type.
2024-12-06 06:09:44 +00:00
rmg-x
e4bc6178b9 Tests/LibWeb: Remove duplicate "headers" property in HTTP echo request 2024-12-06 06:09:44 +00:00
rmg-x
4dd21d0b80 Tests/LibWeb: Refactor HTTP echo server script
This commit makes the following changes:
- Adds a model "Echo" for the request body
- Changes the main endpoint from /create to /echo (more REST-y)
- Sends "400: Bad Request" for invalid params or a reserved path
- Sends "409: Conflict" when trying to use an already registered path
- Prints the server port to stdout
- Removes unnecessary subcommands/options (start, stop, --background)
2024-12-05 17:02:57 -07:00
Cory Virok
97d47a38c9 Meta: Add an HTTP echo server to help with testing Browser JS
This allows us to simulate HTTP responses from Browser JS tests.
Instead of using hacks like data URLs to "load" external data,
we can now generate an actual HTTP response that contains
arbitrary headers, body, and has a defined response delay.
2024-11-09 13:08:31 -07:00