-
Notifications
You must be signed in to change notification settings - Fork 6.6k
fix(network): preserve dates in response headers #42734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,7 @@ export function headersObjectToArray(headers: HeadersObject, separator?: string, | |
| continue; | ||
| if (separator) { | ||
| const sep = name.toLowerCase() === 'set-cookie' ? setCookieSeparator : separator; | ||
| for (const value of values.split(sep!)) | ||
| for (const value of splitHeaderValue(name, values, sep!)) | ||
| result.push({ name, value: value.trim() }); | ||
| } else { | ||
| result.push({ name, value: values }); | ||
|
|
@@ -42,3 +42,22 @@ export function headersArrayToObject(headers: HeadersArray, lowerCase: boolean): | |
| result[lowerCase ? name.toLowerCase() : name] = value; | ||
| return result; | ||
| } | ||
|
|
||
| export function splitHeaderValue(name: string, value: string, separator: string): string[] { | ||
| if (separator === ',') { | ||
| switch (name.toLowerCase()) { | ||
| case 'date': | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use Chromium's non-coalescing list (
|
||
| case 'expires': | ||
| case 'last-modified': | ||
| case 'if-modified-since': | ||
| case 'if-unmodified-since': | ||
| case 'if-range': | ||
| case 'retry-after': | ||
| return [value]; | ||
| case 'set-cookie': | ||
| // Only split before a cookie pair, not the date following an Expires comma. | ||
| return value.split(/,(?=\s*[!#$%&'*+\-.^_`|~\da-z]+=)/i); | ||
| } | ||
| } | ||
| return value.split(separator); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| * limitations under the License. | ||
| */ | ||
|
|
||
| import { splitHeaderValue } from '@isomorphic/headers'; | ||
| import { eventsHelper } from '@utils/eventsHelper'; | ||
| import * as network from '../network'; | ||
|
|
||
|
|
@@ -281,7 +282,7 @@ function parseMultivalueHeaders(headers: HeadersArray) { | |
| const result: HeadersArray = []; | ||
| for (const header of headers) { | ||
| const separator = header.name.toLowerCase() === 'set-cookie' ? '\n' : ','; | ||
| const tokens = header.value.split(separator).map(s => s.trim()); | ||
| const tokens = splitHeaderValue(header.name, header.value, separator).map(s => s.trim()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For Firefox we don't need to guess. That needs a Firefox roll, so fine to land the heuristic first, but let's not treat this as the Firefox fix. |
||
| for (const token of tokens) | ||
| result.push({ name: header.name, value: token }); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
separator === ','guard makes the coupling between the name switch and the separator implicit. Suggest keeping plainsplit('\n')for the raw-header paths and giving the comma path its ownsplitCommaSeparatedHeader(name, value).