ampproject / amphtml

The AMP web component framework.
https://amp.dev
Apache License 2.0
14.89k stars 3.89k forks source link

AMP-Form: Support content-type with extra character #6172

Closed winstonma closed 7 years ago

winstonma commented 7 years ago

I am currently using App Engine's endpoint as a backend service. I would like AMPed my website.

In order for the form to show the success message, it requires content-type:application/json. I tried the API call from App Engine, it returns content-type:application/json; charset=UTF-8 with response status of 200. However the form showed the error message.

Since I can't change the content-type of the App Engine's backend, is it possible that the AMP-Form can ignore the extra characters on the content-type (as long as application/json exist and response status of 2XX it treat the form submission as success).

Thanks a lot

winstonma commented 7 years ago

After further checking the error message is Error: Response must contain the AMP-Access-Control-Allow-Source-Origin header​​​. I guess this is the problem of the CORS.

jridgewell commented 7 years ago

/to @mkhatib

winstonma commented 7 years ago

Sorry I read the CORS Requests in AMP. But after further checking seems it is not CORS related.

Here is the response header:

access-control-allow-credentials:true access-control-allow-origin:https://cdn.ampproject.org access-control-expose-headers:Cache-Control,Content-Encoding,Content-Length,content-type,Date,ETag,Expires,Pragma,Server,X-Google-GFE-Backend-Request-Cost alt-svc:quic=":443"; ma=2592000; v="36,35,34" cache-control:no-cache, no-store, max-age=0, must-revalidate content-encoding:gzip content-length:205 content-type:application/json; charset=UTF-8 date:Tue, 15 Nov 2016 02:19:53 GMT etag:"J9Y_9xYOOIwvSmPEeUuqsaoy_BA/wkX8DBMm5WbpvkDACL84WCvqg3E" expires:Mon, 01 Jan 1990 00:00:00 GMT pragma:no-cache server:GSE status:200 x-content-type-options:nosniff x-frame-options:SAMEORIGIN x-xss-protection:1; mode=block

After the AMP page received the response, it shows the error message on the form. So I really guess the problem comes from the content-type. But honestly I am not sure.

Thanks a lot. I think the AMP is a very good by giving limited building blocks.

mkhatib commented 7 years ago

Hey @winstonma yes, this is a bug, will send a fix for properly parsing content-type in a bit.

winstonma commented 7 years ago

Thanks @mkhatib

I am not familiar with Javascript so I really can't ensure. Thanks for the fix.