Amphtml: "AMP-Redirect-To" header doesn't work in cdn cache

Created on 26 Sep 2018  路  4Comments  路  Source: ampproject/amphtml

To Whom it may concern:

I like to implement redirect action after amp-form submit. It's kind of strange with CORS header and always occur the following error message:

Console log

I am sure the CORS is correct (I've already use it in different feature, such as "like" and it works well).

Here comes some information about this issue:

I wonder is it an issue or do I need to set extra header ?

Have a nice day.

Paul

Soon Documentation Bug

Most helpful comment

Hi @meistudioli thanks for opening this issue! Access-Control-Expose-Headers needs to contain all non-standard headers that need to be exposed. Both AMP-Redirect-To and AMP-Access-Control-Allow-Source-Origin must be in the list of Access-Control-Expose-Headers for the server to receive them both correctly.

e.g.

Access-Control-Expose-Headers: AMP-Redirect-To, AMP-Access-Control-Allow-Source-Origin

It looks like only AMP-Redirect-To is present above. Try adding that header, and let us know if that solves your problem.

All 4 comments

/to @cvializ /cc @aghassemi

Hi @meistudioli thanks for opening this issue! Access-Control-Expose-Headers needs to contain all non-standard headers that need to be exposed. Both AMP-Redirect-To and AMP-Access-Control-Allow-Source-Origin must be in the list of Access-Control-Expose-Headers for the server to receive them both correctly.

e.g.

Access-Control-Expose-Headers: AMP-Redirect-To, AMP-Access-Control-Allow-Source-Origin

It looks like only AMP-Redirect-To is present above. Try adding that header, and let us know if that solves your problem.

Hi, @cvializ:

I checked my code and figure out I rewrite the "Access-Control-Expose-Headers" orz. Everything is fine after I add AMP-Access-Control-Allow-Source-Origin in the Access-Control-Expose-Headers.

Here is my code:

header("Access-Control-Expose-Headers: AMP-Access-Control-Allow-Source-Origin");
...
...
...
if (purchaseSuccess) {
    header('AMP-Redirect-To: https://tw.sc.mall.yahoo.com/mcart/preview');
    header('Access-Control-Expose-Headers: AMP-Redirect-To, Another-Header, And-Some-More');
}

Kind of stupid about this orz.

By the way. Is it possible to make it more clear in amp-form document about redirect section ? I think other developers may just copy / paste the sample code like me.

amp-form: redirecting-after-a-submission

Thank you again for helping solving.

Paul

That's a great idea, we should update that documentation. Thanks for letting us know how you fixed it and suggesting an improvement 馃槂

Was this page helpful?
0 / 5 - 0 ratings