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
Serializing Requests #106
Comments
The problem is the scheme is only part of the TCP connection (via port, ssl) and not really part of the request HTTP representation. What you can do, is to set the request target ( |
Hello Tobion, Thanks for your quick answer. I followed your advice but this breaks "unserializing": /**
* @param \Psr\Http\Message\RequestInterface $request
* @return string
*/
function serializePSRRequest(\Psr\Http\Message\RequestInterface $request) {
if ($request->getUri()->getScheme() === 'https') {
$request = $request->withRequestTarget('absolute-form');
}
return \GuzzleHttp\Psr7\str($request);
}
/**
* @param string $string
* @return GuzzleHttp\Psr7\Request
*/
function unserializePSRRequest(string $string) {
return \GuzzleHttp\Psr7\parse_request($string);
}
$secureRequest = new \GuzzleHttp\Psr7\Request('GET', 'https://example.org');
$unsecureRequest = new \GuzzleHttp\Psr7\Request('GET', 'http://example.org');
$secureRequestStr = serializePSRRequest($secureRequest);
$unsecureRequestStr = serializePSRRequest($unsecureRequest);
var_dump($secureRequestStr === $unsecureRequestStr); // false
var_dump(unserializePSRRequest($unsecureRequestStr)); // returns \GuzzleHttp\Psr7\Request object
var_dump(unserializePSRRequest($secureRequestStr)); // throws \InvalidArgumentException: Invalid request string What would be the best practice? Thanks, |
This is not correct. Absolute-form is just the name. This should do it: |
LMAO - #facepalm ^^ Sorry, my skills in raw HTTP messages aren't that good. Thanks! I owe you a beer. |
Hello guys,
I want to serialize requests and responses as well.
I found the solution on #53 - but
The
\GuzzleHttp\Psr7\str
function does a good job indeed, except it doesn't make a difference between HTTP and HTTPS.This is quite disturbing because when I store a request as string for further use, the request automatically switches to HTTP...
Any ideas?
Thanks,
Ben
The text was updated successfully, but these errors were encountered: