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

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: 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
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 const HTTPHeaderMap& headerMap = request.httpHeaderFields();
yhirano 2016/11/07 12:30:50 m_requestHeaders = request.httpHeaderFields();
Jack Bates 2016/11/12 21:13:30 Done.
206 for (const auto& header : headerMap) { 206 for (const auto& header : headerMap) {
207 if (FetchUtils::isSimpleHeader(header.key, header.value)) { 207 m_requestHeaders.add(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 } 208 }
218 209
219 // DocumentThreadableLoader is used by all javascript initiated fetch, so we 210 // DocumentThreadableLoader is used by all javascript initiated fetch, so we
220 // use this chance to record non-GET fetch script requests. However, this is 211 // 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 212 // based on the following assumptions, so please be careful when adding
222 // similar logic: 213 // similar logic:
223 // - ThreadableLoader is used as backend for all javascript initiated network 214 // - ThreadableLoader is used as backend for all javascript initiated network
224 // fetches. 215 // fetches.
225 // - Note that ThreadableLoader is also used for non-network fetch such as 216 // - Note that ThreadableLoader is also used for non-network fetch such as
226 // FileReaderLoader. However it emulates GET method so signal is not 217 // FileReaderLoader. However it emulates GET method so signal is not
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 628
638 ResourceRequest crossOriginRequest(request); 629 ResourceRequest crossOriginRequest(request);
639 630
640 // Remove any headers that may have been added by the network layer that cause 631 // Remove any headers that may have been added by the network layer that cause
641 // access control to fail. 632 // access control to fail.
642 crossOriginRequest.clearHTTPReferrer(); 633 crossOriginRequest.clearHTTPReferrer();
643 crossOriginRequest.clearHTTPOrigin(); 634 crossOriginRequest.clearHTTPOrigin();
644 crossOriginRequest.clearHTTPUserAgent(); 635 crossOriginRequest.clearHTTPUserAgent();
645 // Add any CORS simple request headers which we previously saved from the 636 // Add any CORS simple request headers which we previously saved from the
646 // original request. 637 // original request.
647 for (const auto& header : m_simpleRequestHeaders) 638 for (const auto& header : m_requestHeaders)
648 crossOriginRequest.setHTTPHeaderField(header.key, header.value); 639 crossOriginRequest.setHTTPHeaderField(header.key, header.value);
649 makeCrossOriginAccessRequest(crossOriginRequest); 640 makeCrossOriginAccessRequest(crossOriginRequest);
650 641
651 return false; 642 return false;
652 } 643 }
653 644
654 void DocumentThreadableLoader::redirectBlocked() { 645 void DocumentThreadableLoader::redirectBlocked() {
655 m_checker.redirectBlocked(); 646 m_checker.redirectBlocked();
656 647
657 // Tells the client that a redirect was received but not followed (for an 648 // Tells the client that a redirect was received but not followed (for an
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
1131 } 1122 }
1132 1123
1133 DEFINE_TRACE(DocumentThreadableLoader) { 1124 DEFINE_TRACE(DocumentThreadableLoader) {
1134 visitor->trace(m_resource); 1125 visitor->trace(m_resource);
1135 visitor->trace(m_document); 1126 visitor->trace(m_document);
1136 ThreadableLoader::trace(visitor); 1127 ThreadableLoader::trace(visitor);
1137 RawResourceClient::trace(visitor); 1128 RawResourceClient::trace(visitor);
1138 } 1129 }
1139 1130
1140 } // namespace blink 1131 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698