Skip to content

Commit

Permalink
We should maintain the original Content-Type header on 303 HTTP redirect
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=242969

Reviewed by Darin Adler and Alex Christensen.

Maintain the original Content-Type header on 303 HTTP redirect, like we do for
the 307 and 308 ones. This aligns our behavior with both Blink and Gecko.

* LayoutTests/imported/w3c/web-platform-tests/xhr/send-redirect-expected.txt:
* Source/WebCore/platform/network/mac/ResourceHandleMac.mm:
(WebCore::ResourceHandle::willSendRequest):
* Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm:
(WebKit::NetworkDataTaskCocoa::willPerformHTTPRedirection):

Canonical link: https://commits.webkit.org/252713@main
  • Loading branch information
cdumez committed Jul 21, 2022
1 parent 1d6daa4 commit afacf71
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

PASS XMLHttpRequest: send() - Redirects (basics) (301)
PASS XMLHttpRequest: send() - Redirects (basics) (302)
FAIL XMLHttpRequest: send() - Redirects (basics) (303) assert_equals: expected "application/x-pony" but got "NO"
PASS XMLHttpRequest: send() - Redirects (basics) (303)
PASS XMLHttpRequest: send() - Redirects (basics) (307)

10 changes: 8 additions & 2 deletions Source/WebCore/platform/network/mac/ResourceHandleMac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,14 @@ static bool synchronousWillSendRequestEnabled()
if (!originalContentType.isEmpty())
request.setHTTPHeaderField(HTTPHeaderName::ContentType, originalContentType);
}
} else if (redirectResponse.httpStatusCode() == 303 && equalLettersIgnoringASCIICase(d->m_firstRequest.httpMethod(), "head"_s)) // FIXME: (rdar://problem/13706454).
request.setHTTPMethod("HEAD"_s);
} else if (redirectResponse.httpStatusCode() == 303) { // FIXME: (rdar://problem/13706454).
if (equalLettersIgnoringASCIICase(d->m_firstRequest.httpMethod(), "head"_s))
request.setHTTPMethod("HEAD"_s);

String originalContentType = d->m_firstRequest.httpContentType();
if (!originalContentType.isEmpty())
request.setHTTPHeaderField(HTTPHeaderName::ContentType, originalContentType);
}

// Should not set Referer after a redirect from a secure resource to non-secure one.
if (!request.url().protocolIs("https"_s) && protocolIs(request.httpReferrer(), "https"_s) && d->m_context->shouldClearReferrerOnHTTPSToHTTPRedirect())
Expand Down
10 changes: 8 additions & 2 deletions Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,14 @@ static inline bool computeIsAlwaysOnLoggingAllowed(NetworkSession& session)
String originalContentType = m_firstRequest.httpContentType();
if (!originalContentType.isEmpty())
request.setHTTPHeaderField(WebCore::HTTPHeaderName::ContentType, originalContentType);
} else if (redirectResponse.httpStatusCode() == 303 && equalLettersIgnoringASCIICase(m_firstRequest.httpMethod(), "head"_s)) // FIXME: (rdar://problem/13706454).
request.setHTTPMethod("HEAD"_s);
} else if (redirectResponse.httpStatusCode() == 303) { // FIXME: (rdar://problem/13706454).
if (equalLettersIgnoringASCIICase(m_firstRequest.httpMethod(), "head"_s))
request.setHTTPMethod("HEAD"_s);

String originalContentType = m_firstRequest.httpContentType();
if (!originalContentType.isEmpty())
request.setHTTPHeaderField(WebCore::HTTPHeaderName::ContentType, originalContentType);
}

// Should not set Referer after a redirect from a secure resource to non-secure one.
if (m_shouldClearReferrerOnHTTPSToHTTPRedirect && !request.url().protocolIs("https"_s) && WTF::protocolIs(request.httpReferrer(), "https"_s))
Expand Down

0 comments on commit afacf71

Please sign in to comment.