Fix OnReceiveResponse expectations (fixes issue #3380)

OnHeadersReceived may not have been called for cached responses.
This commit is contained in:
Marshall Greenblatt 2022-08-30 14:11:52 -04:00
parent 27d4f1fc97
commit f8d90a8972
1 changed files with 9 additions and 8 deletions

View File

@ -562,10 +562,11 @@ void InterceptedRequest::OnReceiveResponse(
current_response_ = std::move(head);
current_body_ = std::move(body);
if (current_request_uses_header_client_) {
// |current_headers_| may be null for cached responses where OnHeadersReceived
// is not called.
if (current_request_uses_header_client_ && current_headers_) {
// Use the headers we got from OnHeadersReceived as that'll contain
// Set-Cookie if it existed.
DCHECK(current_headers_);
current_response_->headers = current_headers_;
current_headers_ = nullptr;
ContinueToResponseStarted(net::OK);
@ -588,14 +589,14 @@ void InterceptedRequest::OnReceiveRedirect(
current_response_ = std::move(head);
current_body_.reset();
if (current_request_uses_header_client_) {
// |current_headers_| may be null for synthetic redirects where
// OnHeadersReceived is not called.
if (current_request_uses_header_client_ && current_headers_) {
// Use the headers we got from OnHeadersReceived as that'll contain
// Set-Cookie if it existed. May be null for synthetic redirects.
if (current_headers_) {
// Set-Cookie if it existed.
current_response_->headers = current_headers_;
current_headers_ = nullptr;
}
}
if (--redirect_limit_ == 0) {
SendErrorAndCompleteImmediately(net::ERR_TOO_MANY_REDIRECTS);