mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 15:10:19 +00:00
RequestServer: Clear "Content-Type" header when one isn't provided
Some checks are pending
CI / Lagom (false, FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (true, NO_FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Push notes / build (push) Waiting to run
Some checks are pending
CI / Lagom (false, FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (true, NO_FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Push notes / build (push) Waiting to run
libcurl will automatically set the Content-Type header when using the CURLOPT_POSTFIELDS option to "application/x-www-form-urlencoded". See: https://curl.se/libcurl/c/CURLOPT_POSTFIELDS.html The following WPT cases now pass (8 tests): http://wpt.live/xhr/send-blob-with-no-mime-type.html
This commit is contained in:
parent
3e8c8b185e
commit
8d511b2f7b
Notes:
github-actions[bot]
2024-11-18 01:04:07 +00:00
Author: https://github.com/rmg-x Commit: https://github.com/LadybirdBrowser/ladybird/commit/8d511b2f7ba Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2407 Reviewed-by: https://github.com/alimpfard ✅
1 changed files with 9 additions and 0 deletions
|
@ -311,12 +311,15 @@ void ConnectionFromClient::start_request(i32 request_id, ByteString const& metho
|
|||
set_option(CURLOPT_PORT, url.port_or_default());
|
||||
set_option(CURLOPT_CONNECTTIMEOUT, s_connect_timeout_seconds);
|
||||
|
||||
bool did_set_body = false;
|
||||
|
||||
if (method == "GET"sv) {
|
||||
set_option(CURLOPT_HTTPGET, 1L);
|
||||
} else if (method.is_one_of("POST"sv, "PUT"sv, "PATCH"sv, "DELETE"sv)) {
|
||||
request->body = request_body;
|
||||
set_option(CURLOPT_POSTFIELDSIZE, request->body.size());
|
||||
set_option(CURLOPT_POSTFIELDS, request->body.data());
|
||||
did_set_body = true;
|
||||
} else if (method == "HEAD") {
|
||||
set_option(CURLOPT_NOBODY, 1L);
|
||||
}
|
||||
|
@ -325,6 +328,12 @@ void ConnectionFromClient::start_request(i32 request_id, ByteString const& metho
|
|||
set_option(CURLOPT_FOLLOWLOCATION, 0);
|
||||
|
||||
struct curl_slist* curl_headers = nullptr;
|
||||
|
||||
// NOTE: CURLOPT_POSTFIELDS automatically sets the Content-Type header.
|
||||
// Set it to empty if the headers passed in don't contain a content type.
|
||||
if (did_set_body && !request_headers.contains("Content-Type"))
|
||||
curl_headers = curl_slist_append(curl_headers, "Content-Type:");
|
||||
|
||||
for (auto const& header : request_headers.headers()) {
|
||||
auto header_string = ByteString::formatted("{}: {}", header.name, header.value);
|
||||
curl_headers = curl_slist_append(curl_headers, header_string.characters());
|
||||
|
|
Loading…
Reference in a new issue