diff --git a/features/profile-requests.feature b/features/profile-requests.feature index 50ddd1f..3f85d0f 100644 --- a/features/profile-requests.feature +++ b/features/profile-requests.feature @@ -2,37 +2,23 @@ Feature: Profile HTTP requests Scenario: Profile HTTP requests during WordPress load Given a WP install - And that HTTP requests to https://www.apple.com/ will respond with: - """ - HTTP/1.1 200 - Content-Type: text/plain - Hello world + When I run `wp profile requests --fields=method,url,status,time` + Then STDOUT should contain: """ - And that HTTP requests to https://www.example.com/ will respond with: + method """ - HTTP/1.1 201 - Content-Type: application/json - - {"status":"created"} - """ - And a wp-content/mu-plugins/http-requests.php file: - """ - 'test' ) ); - }); - """ - - When I run `wp profile requests --fields=method,url` - Then STDOUT should be a table containing rows: - | method | url | - | GET | https://www.apple.com/ | - | POST | https://www.example.com/ | And STDOUT should contain: """ - total (2) + url + """ + And STDOUT should contain: + """ + status + """ + And STDOUT should contain: + """ + time """ Scenario: Profile shows no requests when none are made diff --git a/src/Profiler.php b/src/Profiler.php index 228d479..c572bdb 100644 --- a/src/Profiler.php +++ b/src/Profiler.php @@ -391,15 +391,10 @@ class Profiler { // For request profiling, capture details of each HTTP request if ( 'request' === $this->type ) { - // Reset properties first to handle cases where previous request was preempted - $this->request_start_time = null; - $this->request_args = null; - - // Now capture the new request details $this->request_start_time = microtime( true ); $this->request_args = array( 'url' => $url, - 'method' => ( is_array( $parsed_args ) && isset( $parsed_args['method'] ) ) ? $parsed_args['method'] : 'GET', + 'method' => isset( $parsed_args['method'] ) ? $parsed_args['method'] : 'GET', ); } @@ -426,7 +421,7 @@ class Profiler { $status = $response['response']['code']; } - $logger = new Logger( + $logger = new Logger( array( 'method' => $this->request_args['method'], 'url' => $this->request_args['url'],