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

Add AMP-first preview and args to validate request for Site Scanning #6615

Merged
merged 20 commits into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
30301da
Allow validate requests to also store results
westonruter Sep 18, 2021
6f34359
Make is_validate_request a public method and member var protected
westonruter Sep 23, 2021
f57e397
fixup! Allow validate requests to also store results
westonruter Sep 23, 2021
af3c45b
Use constant for amp_store query param
westonruter Sep 23, 2021
f930949
Remove needless pretty-printing of validation response
westonruter Sep 23, 2021
808d969
Add amp_available_override query param to force AMP to be available
westonruter Sep 23, 2021
c2a4738
WIP: Try facilitating selective AMP-first URLs when in paired mode
westonruter Sep 25, 2021
ee5cd4b
Adopt the Web Stories approach of selectively enabling Standard mode
westonruter Sep 25, 2021
3eadf15
Revert "Add amp_available_override query param to force AMP to be ava…
westonruter Sep 25, 2021
8a61a74
Move validate logic to validation manager
westonruter Sep 25, 2021
6050db9
Merge branch 'develop' of github.com:ampproject/amp-wp into add/valid…
westonruter Sep 25, 2021
b3a12bd
Improve send_validate_response logic and add test coverage
westonruter Sep 27, 2021
c24e0ef
Add test coverage for AMP-first override requests
westonruter Sep 27, 2021
06284df
Introduce args for validate requests to cache, serve cached, and omit…
westonruter Oct 6, 2021
aa02b96
Move logic into maybe_send_cached_validate_response method
westonruter Oct 7, 2021
4d12ffe
Replace redundante staleness with revalidated prop
westonruter Oct 7, 2021
c3294c9
Test omission of stylesheets in send_validate_response
westonruter Oct 7, 2021
cdc0132
Add test for maybe_send_cached_validate_response
westonruter Oct 7, 2021
9f3a80c
Improve tests for send_validate_response
westonruter Oct 7, 2021
c226596
Remove extraneous action priority
westonruter Oct 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions includes/class-amp-theme-support.php
Original file line number Diff line number Diff line change
Expand Up @@ -1882,7 +1882,7 @@ public static function prepare_response( $response, $args = [] ) {
}
$did_redirect = $status_code >= 300 && $status_code < 400 && $sent_location_header;

if ( AMP_Validation_Manager::$is_validate_request && ! $did_redirect ) {
if ( AMP_Validation_Manager::is_validate_request() && ! $did_redirect ) {
if ( ! headers_sent() ) {
status_header( 400 );
header( 'Content-Type: application/json; charset=utf-8' );
Expand Down Expand Up @@ -1941,7 +1941,7 @@ public static function prepare_response( $response, $args = [] ) {

$dom = Document::fromHtml( $response, Options::DEFAULTS );

if ( AMP_Validation_Manager::$is_validate_request ) {
if ( AMP_Validation_Manager::is_validate_request() ) {
AMP_Validation_Manager::remove_illegal_source_stack_comments( $dom );
}

Expand Down Expand Up @@ -1997,18 +1997,12 @@ public static function prepare_response( $response, $args = [] ) {
do_action( 'amp_server_timing_stop', 'amp_sanitizer' );

// Respond early with results if performing a validate request.
if ( AMP_Validation_Manager::$is_validate_request ) {
status_header( 200 );
header( 'Content-Type: application/json; charset=utf-8' );
$data = [
'http_status_code' => $status_code,
'php_fatal_error' => false,
];
if ( $last_error && in_array( $last_error['type'], [ E_ERROR, E_RECOVERABLE_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR, E_PARSE ], true ) ) {
$data['php_fatal_error'] = $last_error;
}
$data = array_merge( $data, AMP_Validation_Manager::get_validate_response_data( $sanitization_results ) );
return wp_json_encode( $data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );
if ( AMP_Validation_Manager::is_validate_request() ) {
return AMP_Validation_Manager::send_validate_response(
$sanitization_results,
$status_code,
$last_error
);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion includes/validation/class-amp-validated-url-post-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ protected static function normalize_url_for_storage( $url ) {
// Query args to be removed from validated URLs.
$removable_query_vars = array_merge(
wp_removable_query_args(),
[ 'preview_id', 'preview_nonce', 'preview', QueryVar::NOAMP ]
[ 'preview_id', 'preview_nonce', 'preview', QueryVar::NOAMP, AMP_Validation_Manager::VALIDATE_QUERY_VAR ]
);

// Normalize query args, removing all that are not recognized or which are removable.
Expand Down
Loading