Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: third_party/WebKit/Source/core/loader/DocumentThreadableLoader.cpp

Issue 2471533005: Preserve custom headers when following cross-origin redirects. (Closed)
Patch Set: Rebase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/loader/DocumentThreadableLoader.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
3 * Copyright (C) 2013, Intel Corporation 3 * Copyright (C) 2013, Intel Corporation
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 ThreadableLoaderClient* client = m_client; 192 ThreadableLoaderClient* client = m_client;
193 clear(); 193 clear();
194 client->didFail(ResourceError(errorDomainBlinkInternal, 0, 194 client->didFail(ResourceError(errorDomainBlinkInternal, 0,
195 request.url().getString(), 195 request.url().getString(),
196 "Cross origin requests are not supported.")); 196 "Cross origin requests are not supported."));
197 return; 197 return;
198 } 198 }
199 199
200 m_requestStartedSeconds = monotonicallyIncreasingTime(); 200 m_requestStartedSeconds = monotonicallyIncreasingTime();
201 201
202 // Save any CORS simple headers on the request here. If this request redirects 202 // Save any headers on the request here. If this request redirects
203 // cross-origin, we cancel the old request create a new one, and copy these 203 // cross-origin, we cancel the old request create a new one, and copy these
204 // headers. 204 // headers.
205 const HTTPHeaderMap& headerMap = request.httpHeaderFields(); 205 m_requestHeaders = request.httpHeaderFields();
206 for (const auto& header : headerMap) {
207 if (FetchUtils::isSimpleHeader(header.key, header.value)) {
208 m_simpleRequestHeaders.add(header.key, header.value);
209 } else if (equalIgnoringCase(header.key, HTTPNames::Range) &&
210 m_options.crossOriginRequestPolicy == UseAccessControl &&
211 m_options.preflightPolicy == PreventPreflight) {
212 // Allow an exception for the "range" header for when CORS callers request
213 // no preflight, this ensures cross-origin redirects work correctly for
214 // crossOrigin enabled WebURLRequest::RequestContextVideo type requests.
215 m_simpleRequestHeaders.add(header.key, header.value);
216 }
217 }
218 206
219 // DocumentThreadableLoader is used by all javascript initiated fetch, so we 207 // DocumentThreadableLoader is used by all javascript initiated fetch, so we
220 // use this chance to record non-GET fetch script requests. However, this is 208 // use this chance to record non-GET fetch script requests. However, this is
221 // based on the following assumptions, so please be careful when adding 209 // based on the following assumptions, so please be careful when adding
222 // similar logic: 210 // similar logic:
223 // - ThreadableLoader is used as backend for all javascript initiated network 211 // - ThreadableLoader is used as backend for all javascript initiated network
224 // fetches. 212 // fetches.
225 // - Note that ThreadableLoader is also used for non-network fetch such as 213 // - Note that ThreadableLoader is also used for non-network fetch such as
226 // FileReaderLoader. However it emulates GET method so signal is not 214 // FileReaderLoader. However it emulates GET method so signal is not
227 // recorded here. 215 // recorded here.
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 m_referrerAfterRedirect = 628 m_referrerAfterRedirect =
641 Referrer(request.httpReferrer(), request.getReferrerPolicy()); 629 Referrer(request.httpReferrer(), request.getReferrerPolicy());
642 630
643 ResourceRequest crossOriginRequest(request); 631 ResourceRequest crossOriginRequest(request);
644 632
645 // Remove any headers that may have been added by the network layer that cause 633 // Remove any headers that may have been added by the network layer that cause
646 // access control to fail. 634 // access control to fail.
647 crossOriginRequest.clearHTTPReferrer(); 635 crossOriginRequest.clearHTTPReferrer();
648 crossOriginRequest.clearHTTPOrigin(); 636 crossOriginRequest.clearHTTPOrigin();
649 crossOriginRequest.clearHTTPUserAgent(); 637 crossOriginRequest.clearHTTPUserAgent();
650 // Add any CORS simple request headers which we previously saved from the 638 // Add any request headers which we previously saved from the
651 // original request. 639 // original request.
652 for (const auto& header : m_simpleRequestHeaders) 640 for (const auto& header : m_requestHeaders)
653 crossOriginRequest.setHTTPHeaderField(header.key, header.value); 641 crossOriginRequest.setHTTPHeaderField(header.key, header.value);
654 makeCrossOriginAccessRequest(crossOriginRequest); 642 makeCrossOriginAccessRequest(crossOriginRequest);
655 643
656 return false; 644 return false;
657 } 645 }
658 646
659 void DocumentThreadableLoader::redirectBlocked() { 647 void DocumentThreadableLoader::redirectBlocked() {
660 m_checker.redirectBlocked(); 648 m_checker.redirectBlocked();
661 649
662 // Tells the client that a redirect was received but not followed (for an 650 // Tells the client that a redirect was received but not followed (for an
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 } 1123 }
1136 1124
1137 DEFINE_TRACE(DocumentThreadableLoader) { 1125 DEFINE_TRACE(DocumentThreadableLoader) {
1138 visitor->trace(m_resource); 1126 visitor->trace(m_resource);
1139 visitor->trace(m_document); 1127 visitor->trace(m_document);
1140 ThreadableLoader::trace(visitor); 1128 ThreadableLoader::trace(visitor);
1141 RawResourceClient::trace(visitor); 1129 RawResourceClient::trace(visitor);
1142 } 1130 }
1143 1131
1144 } // namespace blink 1132 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/loader/DocumentThreadableLoader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698