Don't override Accept-Language header if set by the client (fixes issue #3139)

This commit is contained in:
Marshall Greenblatt 2022-04-20 14:39:43 -04:00
parent a1e2187e83
commit 0783cf8db5
1 changed files with 8 additions and 4 deletions

View File

@ -112,6 +112,7 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
CefRefPtr<CefResponseImpl> pending_response_; CefRefPtr<CefResponseImpl> pending_response_;
bool request_was_redirected_ = false; bool request_was_redirected_ = false;
bool was_custom_handled_ = false; bool was_custom_handled_ = false;
bool accept_language_added_ = false;
CancelRequestCallback cancel_callback_; CancelRequestCallback cancel_callback_;
}; };
@ -514,9 +515,12 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
} }
// Add standard headers, if currently unspecified. // Add standard headers, if currently unspecified.
request->headers.SetHeaderIfMissing( if (!request->headers.HasHeader(net::HttpRequestHeaders::kAcceptLanguage)) {
net::HttpRequestHeaders::kAcceptLanguage, request->headers.SetHeaderIfMissing(
init_state_->accept_language_); net::HttpRequestHeaders::kAcceptLanguage,
init_state_->accept_language_);
state->accept_language_added_ = true;
}
request->headers.SetHeaderIfMissing(net::HttpRequestHeaders::kUserAgent, request->headers.SetHeaderIfMissing(net::HttpRequestHeaders::kUserAgent,
init_state_->user_agent_); init_state_->user_agent_);
@ -771,7 +775,7 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
resource_response = CreateResourceResponse(request_id, resource_handler); resource_response = CreateResourceResponse(request_id, resource_handler);
DCHECK(resource_response); DCHECK(resource_response);
state->was_custom_handled_ = true; state->was_custom_handled_ = true;
} else { } else if (state->accept_language_added_) {
// The request will be handled by the NetworkService. Remove the // The request will be handled by the NetworkService. Remove the
// "Accept-Language" header here so that it can be re-added in // "Accept-Language" header here so that it can be re-added in
// URLRequestHttpJob::AddExtraHeaders with correct ordering applied. // URLRequestHttpJob::AddExtraHeaders with correct ordering applied.