Skip to content
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

Merged
merged 29 commits into from
Sep 17, 2018
Merged

Conversation

prateekbh
Copy link
Member

@prateekbh prateekbh commented Aug 21, 2018

  • Utilizes fetch polyfill.
  • Deletes all instances of FetchResponse and FetchPolyfill

@prateekbh prateekbh changed the title moving AMP to fetch polyfill [WIP] moving AMP to fetch polyfill Aug 21, 2018
@prateekbh prateekbh changed the title [WIP] moving AMP to fetch polyfill Moving AMP to fetch polyfill Aug 31, 2018
const options = {
status: xhr.status,
statusText: xhr.statusText,
headers: parseHeaders(xhr.getAllResponseHeaders()),
Copy link
Member Author

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')));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dev().assertString()

Copy link
Member Author

@prateekbh prateekbh Sep 4, 2018

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.

Copy link
Member Author

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')));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

// 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, ' ');
Copy link
Contributor

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.

Copy link
Member Author

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(
Copy link
Contributor

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?

Copy link
Member Author

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?

Copy link
Contributor

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.

Copy link
Member Author

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')));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

// 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(':');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const match = /([^:]+):(.*)/.exec(line);

@prateekbh
Copy link
Member Author

prateekbh commented Sep 5, 2018

adding @glevitzky to review the default value for headers in amp-ad-network-doubleclick-impl.js

@prateekbh prateekbh merged commit bc2b84f into ampproject:master Sep 17, 2018
@prateekbh prateekbh deleted the move-to-fetch branch September 17, 2018 19:51
torch2424 pushed a commit to torch2424/amphtml that referenced this pull request Sep 20, 2018
* 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
Enriqe pushed a commit to Enriqe/amphtml that referenced this pull request Nov 28, 2018
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants