Manually concatenate ACRH headers to not include a space (#36455)

headers library will join values with `, ` (comma space) but
Access-Control-Request-Headers specifies that it does not use the normal
combining algorithm and values should be joined with `,` (comma).

Testing: WPT tests exist
Fixes: temporary fix for #36451 until hyperium/headers#207 is fixed

---------

Signed-off-by: Sebastian C <sebsebmc@gmail.com>
This commit is contained in:
Sebastian C 2025-04-11 12:01:55 -05:00 committed by GitHub
parent 0c8bb8287a
commit 87c40b4168
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 15 additions and 26 deletions

View file

@ -20,13 +20,13 @@ use futures::{TryFutureExt, TryStreamExt, future};
use headers::authorization::Basic;
use headers::{
AccessControlAllowCredentials, AccessControlAllowHeaders, AccessControlAllowMethods,
AccessControlAllowOrigin, AccessControlMaxAge, AccessControlRequestHeaders,
AccessControlRequestMethod, Authorization, CacheControl, ContentLength, HeaderMapExt,
IfModifiedSince, LastModified, Pragma, Referer, UserAgent,
AccessControlAllowOrigin, AccessControlMaxAge, AccessControlRequestMethod, Authorization,
CacheControl, ContentLength, HeaderMapExt, IfModifiedSince, LastModified, Pragma, Referer,
UserAgent,
};
use http::header::{
self, ACCEPT, AUTHORIZATION, CONTENT_ENCODING, CONTENT_LANGUAGE, CONTENT_LOCATION,
CONTENT_TYPE, HeaderValue, RANGE,
self, ACCEPT, ACCESS_CONTROL_REQUEST_HEADERS, AUTHORIZATION, CONTENT_ENCODING,
CONTENT_LANGUAGE, CONTENT_LOCATION, CONTENT_TYPE, HeaderValue, RANGE,
};
use http::{HeaderMap, Method, Request as HyperRequest, StatusCode};
use http_body_util::combinators::BoxBody;
@ -2139,11 +2139,15 @@ async fn cors_preflight_fetch(
// Step 4
let headers = get_cors_unsafe_header_names(&request.headers);
// Step 5
// Step 5 If headers is not empty, then:
if !headers.is_empty() {
preflight
.headers
.typed_insert(AccessControlRequestHeaders::from_iter(headers));
// 5.1 Let value be the items in headers separated from each other by `,`
// TODO(36451): replace this with typed_insert when headers fixes headers#207
preflight.headers.insert(
ACCESS_CONTROL_REQUEST_HEADERS,
HeaderValue::from_bytes(itertools::join(headers.iter(), ",").as_bytes())
.unwrap_or(HeaderValue::from_static("")),
);
}
// Step 6