laravel-blanket
laravel-blanket copied to clipboard
Show raw HTTP request and response
Outputting the request and response inside a JSON wrapper is useful in that it shows what data was sent, but it isn't a true representation of the raw HTTP request and responses that were transmitted.
If you're sending a JSON payload to a remote API and the exact format is important (objects vs arrays, etc) then it's difficult to know if what you're seeing in Blanket is exactly what you sent or an interpreted version of it.
Is it possible to piece the JSON components back together to show what was actually sent in its raw form (like what you'd see if you were using a packet sniffer)?
You'd show something like this for a request:
POST /restapi/v1.2/leads HTTP/1.1
Content-Length: 110
User-Agent: GuzzleHttp/7
Content-Type: application/json
Host: ******
{"key":"******","leads":[{"id":"12345","update":{"status":"sold"}}]}
And this for the response:
HTTP/1.1 401 Unauthorized
Date: Tue, 07 Sep 2021 12:41:39 GMT
Content-Type: text/html;charset=UTF-8
"Content-Length: 472
Connection: keep-alive
Server: Apache
x-xss-protection: 0
x-frame-options: SAMEORIGIN
x-content-type-options: nosniff
Set-Cookie: PHPSESSID=******; path=/; secure; HttpOnly
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
X-Robots-Tag: noindex
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>401 Unauthorized</title>
</head>
<body>
<h1>Unauthorized</h1>
<p>You must be authorized to view this page.</p>
<hr />
<address>Apache Server at ******</address>
</body>
</html>
With current implementation this is not possible, cus if you look at the data method implementation of laravel client request https://github.com/laravel/framework/blob/8.x/src/Illuminate/Http/Client/Request.php and response classes it always return data in array format if data can be decoded as json. One way to do that is extend those cleasses and get the underlying data property directly in that case then we need to create two more columns to save raw forms of request and response data.
I understand. It would be very helpful to have in the future, but I appreciate that it isn't straightforward.
For now, I'm just taking the body text and assuming it is verbatim.
Your package has helped me out a lot today, so I very much appreciate your work!
I will add this feature in the future when i have some time, and i am glad to know this package helped you thanks for the appreciation.