@@ -394,13 +394,16 @@ public function logWarning(array $request, array $response): void
394
394
*/
395
395
public function logRequestSuccess (array $ request , array $ response ): void
396
396
{
397
+ $ port = $ request ['client ' ]['curl ' ][CURLOPT_PORT ] ?? $ response ['transfer_stats ' ]['primary_port ' ] ?? '' ;
398
+ $ uri = $ this ->addPortInUrl ($ response ['effective_url ' ], (int ) $ port );
399
+
397
400
$ this ->log ->debug ('Request Body ' , array ($ request ['body ' ]));
398
401
$ this ->log ->info (
399
402
'Request Success: ' ,
400
403
array (
401
404
'method ' => $ request ['http_method ' ],
402
- 'uri ' => $ response [ ' effective_url ' ] ,
403
- 'port ' => $ response [ ' transfer_stats ' ][ ' primary_port ' ] ?? '' ,
405
+ 'uri ' => $ uri ,
406
+ 'port ' => $ port ,
404
407
'headers ' => $ request ['headers ' ],
405
408
'HTTP code ' => $ response ['status ' ],
406
409
'duration ' => $ response ['transfer_stats ' ]['total_time ' ],
@@ -409,14 +412,15 @@ public function logRequestSuccess(array $request, array $response): void
409
412
$ this ->log ->debug ('Response ' , array ($ response ['body ' ]));
410
413
411
414
// Build the curl command for Trace.
412
- $ curlCommand = $ this ->buildCurlCommand ($ request ['http_method ' ], $ response [ ' effective_url ' ] , $ request ['body ' ]);
415
+ $ curlCommand = $ this ->buildCurlCommand ($ request ['http_method ' ], $ uri , $ request ['body ' ]);
413
416
$ this ->trace ->info ($ curlCommand );
414
417
$ this ->trace ->debug (
415
418
'Response: ' ,
416
419
array (
417
420
'response ' => $ response ['body ' ],
418
421
'method ' => $ request ['http_method ' ],
419
- 'uri ' => $ response ['effective_url ' ],
422
+ 'uri ' => $ uri ,
423
+ 'port ' => $ port ,
420
424
'HTTP code ' => $ response ['status ' ],
421
425
'duration ' => $ response ['transfer_stats ' ]['total_time ' ],
422
426
)
@@ -434,14 +438,16 @@ public function logRequestSuccess(array $request, array $response): void
434
438
*/
435
439
public function logRequestFail (array $ request , array $ response , \Exception $ exception ): void
436
440
{
437
- $ this ->log ->debug ('Request Body ' , array ($ request ['body ' ]));
441
+ $ port = $ request ['client ' ]['curl ' ][CURLOPT_PORT ] ?? $ response ['transfer_stats ' ]['primary_port ' ] ?? '' ;
442
+ $ uri = $ this ->addPortInUrl ($ response ['effective_url ' ], (int ) $ port );
438
443
444
+ $ this ->log ->debug ('Request Body ' , array ($ request ['body ' ]));
439
445
$ this ->log ->warning (
440
446
'Request Failure: ' ,
441
447
array (
442
448
'method ' => $ request ['http_method ' ],
443
- 'uri ' => $ response [ ' effective_url ' ] ,
444
- 'port ' => $ response [ ' transfer_stats ' ][ ' primary_port ' ] ?? '' ,
449
+ 'uri ' => $ uri ,
450
+ 'port ' => $ port ,
445
451
'headers ' => $ request ['headers ' ],
446
452
'HTTP code ' => $ response ['status ' ],
447
453
'duration ' => $ response ['transfer_stats ' ]['total_time ' ],
@@ -451,14 +457,15 @@ public function logRequestFail(array $request, array $response, \Exception $exce
451
457
$ this ->log ->warning ('Response ' , array ($ response ['body ' ]));
452
458
453
459
// Build the curl command for Trace.
454
- $ curlCommand = $ this ->buildCurlCommand ($ request ['http_method ' ], $ response [ ' effective_url ' ] , $ request ['body ' ]);
460
+ $ curlCommand = $ this ->buildCurlCommand ($ request ['http_method ' ], $ uri , $ request ['body ' ]);
455
461
$ this ->trace ->info ($ curlCommand );
456
462
$ this ->trace ->debug (
457
463
'Response: ' ,
458
464
array (
459
465
'response ' => $ response ,
460
466
'method ' => $ request ['http_method ' ],
461
- 'uri ' => $ response ['effective_url ' ],
467
+ 'uri ' => $ uri ,
468
+ 'port ' => $ port ,
462
469
'HTTP code ' => $ response ['status ' ],
463
470
'duration ' => $ response ['transfer_stats ' ]['total_time ' ],
464
471
)
@@ -624,19 +631,30 @@ private function getOSVersion(): string
624
631
return $ this ->OSVersion ;
625
632
}
626
633
634
+ /**
635
+ * Add the port value in the URL if not present
636
+ */
637
+ private function addPortInUrl (string $ uri , int $ port ): string
638
+ {
639
+ if (strpos ($ uri , ': ' , 7 ) !== false ) {
640
+ return $ uri ;
641
+ }
642
+ return preg_replace ('#([^/])/([^/])# ' , sprintf ("$1:%s/$2 " , $ port ), $ uri , 1 );
643
+ }
644
+
627
645
/**
628
646
* Construct a string cURL command
629
647
*/
630
- private function buildCurlCommand (string $ method , string $ uri , ?string $ body ): string
648
+ private function buildCurlCommand (string $ method , string $ url , ?string $ body ): string
631
649
{
632
- if (strpos ($ uri , '? ' ) === false ) {
633
- $ uri .= '?pretty=true ' ;
650
+ if (strpos ($ url , '? ' ) === false ) {
651
+ $ url .= '?pretty=true ' ;
634
652
} else {
635
- str_replace ('? ' , '?pretty=true ' , $ uri );
653
+ str_replace ('? ' , '?pretty=true ' , $ url );
636
654
}
637
655
638
656
$ curlCommand = 'curl -X ' . strtoupper ($ method );
639
- $ curlCommand .= " ' " . $ uri . "' " ;
657
+ $ curlCommand .= " ' " . $ url . "' " ;
640
658
641
659
if (isset ($ body ) === true && $ body !== '' ) {
642
660
$ curlCommand .= " -d ' " . $ body . "' " ;
0 commit comments