Conversation
| return false; | ||
| } | ||
|
|
||
| return strpos($url, Amp::CACHE_HOST) === 0; |
There was a problem hiding this comment.
Minor thing, but in shouldPreload it's using substr_compare(). Would that not be minimally better than using strpos() here?
Co-authored-by: Weston Ruter <westonruter@google.com>
Co-authored-by: Weston Ruter <westonruter@google.com>
…com/ampproject/amp-toolbox-php into add/20-rewrite-amp-urls-transformer
| * @param string $name Name of the part to return. | ||
| * @return string|null Part string or null if it was not found during parsing. | ||
| */ | ||
| public function __get($name) |
There was a problem hiding this comment.
Eventually we should implement __set() as well, since it would be very useful to be able to change out just the host, when rewriting a URL to use the AMP Cache for example.
Either this, or make the member variables public.
There was a problem hiding this comment.
I'd recommend against that. This is supposed to behave like a value object, so it should be immutable to avoid bugs.
It could have a method to retrieve a new clone with a different host, though:
$cachedUrl = $url->withHost($cachedHost);
The important part is that the original object is not changed (as that would changed it in all the places it was passed around), but rather we return a new instance with the adapted host.
|
|
||
| $src = $element->getAttribute(Attribute::SRC); | ||
| if ($element->tagName === Extension::IMG && Url::isValidNonDataUrl($src)) { | ||
| if ($element->tagName === Extension::IMG && (new Url($src))->isValidNonDataUrl()) { |
There was a problem hiding this comment.
Now that Url can throw an exception, should this method indicate that it @throws FailedToParseUrl Exception when the URL or Base URL is malformed.? Should the exception get added to $errors?
| if (!empty($url->scheme) && !empty($url->host)) { | ||
| $origin = "{$url->scheme}://{$url->host}"; | ||
| $this->addMeta($document, 'runtime-host', $origin); |
There was a problem hiding this comment.
What about scheme-relative URLs? In that case, $url->scheme would be empty and the $origin would be "//{$url->host}". I guess that's not supported, and we'd want an explicit HTTPS URL anyway.
There was a problem hiding this comment.
That would fail the first check (!empty($url->scheme)) and generate an error. Looks correct to me.
There was a problem hiding this comment.
I mean, if such URLs should be supported.
There was a problem hiding this comment.
Not sure what the requirements of the runtime are here. @sebastianbenz ?
There was a problem hiding this comment.
Weston is right, we want an explicit https URL.
| /** | ||
| * Query string. | ||
| * | ||
| * @var string|null | ||
| */ | ||
| private $query; |
There was a problem hiding this comment.
Eventually it will be nice to add a way to access/manipulate the query vars as an array.
There was a problem hiding this comment.
That would be powered by a separate object, so that you'd be able to use it as part of a URL, or stand-alone when dealing with WP query vars, for example.
| private function calculateHost() | ||
| { | ||
| $lts = $this->configuration->get(RewriteAmpUrlsConfiguration::LTS); | ||
| $rtv = $this->configuration->get(RewriteAmpUrlsConfiguration::RTV); | ||
|
|
||
| if ($lts && $rtv) { | ||
| throw InvalidConfiguration::forMutuallyExclusiveFlags( | ||
| RewriteAmpUrlsConfiguration::LTS, | ||
| RewriteAmpUrlsConfiguration::RTV | ||
| ); | ||
| } | ||
|
|
||
| $ampUrlPrefix = $this->configuration->get(RewriteAmpUrlsConfiguration::AMP_URL_PREFIX); | ||
| $ampRuntimeVersion = $this->configuration->get(RewriteAmpUrlsConfiguration::AMP_RUNTIME_VERSION); | ||
|
|
||
| $ampUrlPrefix = rtrim($ampUrlPrefix, '/'); | ||
|
|
||
| if ($ampRuntimeVersion && $rtv) { | ||
| $ampUrlPrefix = RuntimeVersion::appendRuntimeVersion($ampUrlPrefix, $ampRuntimeVersion); | ||
| } elseif ($lts) { | ||
| $ampUrlPrefix .= '/lts'; | ||
| } | ||
|
|
||
| return $ampUrlPrefix; | ||
| } |
There was a problem hiding this comment.
I just realized that the rtv and ampRuntimeVersion are both empty. Instead of seeing the AMP runtime loaded with https://cdn.ampproject.org/rtv/012103261048002/v0.mjs it comes out rtv-less: https://cdn.ampproject.org/v0.mjs
However, if I hack this to force $rtv to be true and $ampRuntimeVersion to be 012103261048002, then the result is invalid AMP:
The attribute 'src' in tag 'amphtml module engine script' is set to the invalid value 'https://cdn.ampproject.org/rtv/012103261048002/v0.mjs'
I guess versioned URLs are not yet valid AMP?
There was a problem hiding this comment.
Only lts is valid. RTV-specific scripts are not yet valid: https://github.com/ampproject/amphtml/blob/52407d1c72c5e2051fda427270b9503ae9900ebf/validator/validator-main.protoascii#L3109-L3256
I think this is being tracked by ampproject/amphtml#27546, although this is about self-hosting and not allowing versioned script URLs. @sebastianbenz is that right?
There was a problem hiding this comment.
Correct, there are no plans to support RTV versions served from cdn.ampproject.org.
This reverts commit e0dd638.
…into add/20-rewrite-amp-urls-transformer * 'main' of https://github.com/ampproject/amp-toolbox-php: Sync spec test suite - 2021-04-09 Sync local fallback files - 2021-04-09 Only construct preload if it is needed Sync local fallback files - 2021-04-08 Replace phpcs exclude-pattern with explicit file includes Delete .phpunit.result.cache Sync local fallback files - 2021-04-07 moving the curl_errno() call up, otherwise won't be reached if the response body is empty Calling curl_errno() before closing the conextion trhows an error Sync local fallback files - 2021-04-04 Sync local fallback files - 2021-04-03 Fix SSR for nested AMP components Sync spec test suite - 2021-04-02 Sync local fallback files - 2021-04-02 Sync local fallback files - 2021-04-01
This PR adds the
RewriteAmpUrlstransformer that enables the following features:geo-apiURLThis PR also moves some code from
AMP_DOM_Utilsinto the library to enable the library to usecopyAttributes().This PR also includes changes to the
ReorderHeadtransformer to make it work properly with module/nomodule script combinations.Fixes #20