-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Moving AMP to fetch polyfill #17642
Moving AMP to fetch polyfill #17642
Conversation
…into move-to-fetch
const options = { | ||
status: xhr.status, | ||
statusText: xhr.statusText, | ||
headers: parseHeaders(xhr.getAllResponseHeaders()), |
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.
@jridgewell, we have a pending discussion around this piece of code in one of the earlier PRs, where you wanted to skip this part.
If we want to skip this we'll need to change code in assetSuccess
and verifyAmpCorsHeaders
code as they both rely on Response type
@@ -688,9 +688,9 @@ export class AmpAdNetworkDoubleclickImpl extends AmpA4A { | |||
this.ampAnalyticsConfig_ = extractAmpAnalyticsConfig(this, responseHeaders); | |||
this.qqid_ = responseHeaders.get(QQID_HEADER); | |||
this.troubleshootData_.creativeId = | |||
responseHeaders.get('google-creative-id'); | |||
(/** @type {string} **/ (responseHeaders.get('google-creative-id'))); |
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.
dev().assertString()
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.
question: there is no guarantee that this'll be a string, but the code consuming this assumed so. Adding a dev assert might just start throwing errors which aren't expected.
In other words this might have been null in some cases even today, but never caught. Adding a dev assert might start surfacing this. It is a great thing to have if we WANT to catch these, but not if we want to ignore these.
Not sure about the use case here.
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.
pinged author, seems like dev assert will be fine
this.troubleshootData_.lineItemId = | ||
responseHeaders.get('google-lineitem-id'); | ||
(/** @type {string} **/ (responseHeaders.get('google-lineitem-id'))); |
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.
Ditto.
src/document-fetcher.js
Outdated
// Replace instances of \r\n and \n followed by at least one space or | ||
// horizontal tab with a space. | ||
// https://tools.ietf.org/html/rfc7230#section-3.2 | ||
const preProcessedHeaders = rawHeaders.replace(/\r?\n[\t ]+/g, ' '); |
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.
This isn't explained in the link.
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.
deleted
@@ -315,7 +315,8 @@ export class SignatureVerifier { | |||
'Fast Fetch keyset spec requires Content-Type: ' + | |||
'application/jwk-set+json'); | |||
return response.json().then( |
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.
Can we override the definition for Response.p.json
to return a !JsonObject
?
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.
I have no idea no to do this.
can you explain a bit?
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.
I don't either. I just don't want to always /** @type {!JsonObject} */
when we call Reponse.p.json
.
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.
How does dev.assertJson sound?
@@ -716,7 +716,7 @@ export class AmpAdNetworkDoubleclickImpl extends AmpA4A { | |||
if (responseHeaders.get('amp-ff-pageview-tokens')) { | |||
this.removePageviewStateToken(); | |||
this.setPageviewStateToken( | |||
responseHeaders.get('amp-ff-pageview-tokens')); | |||
/** @type {string} */ (responseHeaders.get('amp-ff-pageview-tokens'))); |
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.
Ditto.
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.
done
src/document-fetcher.js
Outdated
// https://tools.ietf.org/html/rfc7230#section-3.2 | ||
const preProcessedHeaders = rawHeaders.replace(/\r?\n[\t ]+/g, ' '); | ||
preProcessedHeaders.split(/\r?\n/).forEach(function(line) { | ||
const parts = line.split(':'); |
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.
const match = /([^:]+):(.*)/.exec(line);
adding @glevitzky to review the default value for headers in |
* moving to fetch polyfills * dep-check fixes * fixing batched-xhr tests * fixing more tests * fixing xhr-tests * fixing amp-ad-tests * fixing more tests * Update test-doubleclick-sra.js * Update test-doubleclick-sra.js * Update test-doubleclick-sra.js * adding proxy methods * fixing document-fetcher * document-fetcher * resolving comments * adds a default value * fixing fetch value * increasing bundlesize for fetch polyfill * Update bundle-size.js * missed the 0.1kb warning
* moving to fetch polyfills * dep-check fixes * fixing batched-xhr tests * fixing more tests * fixing xhr-tests * fixing amp-ad-tests * fixing more tests * Update test-doubleclick-sra.js * Update test-doubleclick-sra.js * Update test-doubleclick-sra.js * adding proxy methods * fixing document-fetcher * document-fetcher * resolving comments * adds a default value * fixing fetch value * increasing bundlesize for fetch polyfill * Update bundle-size.js * missed the 0.1kb warning
FetchResponse
andFetchPolyfill