-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path_core-http.php
78 lines (73 loc) · 2.09 KB
/
_core-http.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/*
* Plugin Name: HTTP settings
* Plugin URI: https://github.com/szepeviktor/wordpress-website-lifecycle
*
* Use these constants to restrict outbound HTTP requests.
*
* define('WP_HTTP_BLOCK_EXTERNAL', true);
* define('WP_ACCESSIBLE_HOSTS', 'api.wordpress.org');
*/
// Disable HTTPS detection by setting error-free result.
add_filter(
'pre_wp_update_https_detection_errors',
static function () {
return new \WP_Error();
},
10,
0
);
// Log failed external HTTP requests.
add_action(
'http_api_debug',
static function ($response, $context, $class, $parsedArgs, $url) {
if ($context !== 'response' || $class !== 'Requests' || ! is_wp_error($response)) {
return;
}
error_log(
sprintf(
'WordPress external HTTP request failed with message [%s:%s] %s (%s)',
$response->get_error_code(),
$response->get_error_message(),
$url,
wp_json_encode($parsedArgs, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)
)
);
},
99,
5
);
// Debug external HTTP requests.
if (defined('WP_DEBUG') && WP_DEBUG) :
add_action(
'http_api_debug',
static function ($response, $context, $class, $parsedArgs, $url) {
if ($context !== 'response' || $class !== 'Requests' || is_wp_error($response)) {
return;
}
error_log(
sprintf(
'%s: %s (%s)',
'WordPress external HTTP request',
$url,
wp_json_encode($parsedArgs, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)
)
);
},
100,
5
);
endif;
// Send Pragma HTTP header only for HTTP/1.0 clients.
add_action(
'send_headers',
static function () {
// https://github.com/php/php-src/blob/php-8.1.14/ext/session/session.c#L1208-L1212
if (wp_get_server_protocol() === 'HTTP/1.0') {
return;
}
header_remove('Pragma');
},
PHP_INT_MAX,
0
);