zend-http icon indicating copy to clipboard operation
zend-http copied to clipboard

Request object can't easily be proxied because new headers get overwritten by original request's headers

Open dkmuir opened this issue 9 years ago • 1 comments

Originally zendframework/zendframework#6101

I have an action that proxies the current request by modifying the Uri in the original request and then sending it through Zend\Http\Client. However, the new Host header based on the Uri gets overwritten by the original Host header in the original request.

Eg:

//original uri: http://example.com/proxy-request
$request = clone $this->request;
$uri = $request->getUri();
$uri->setHost('target-site.com');
$uri->setPath('/proxy-target');

$client = new Zend\Http\Client();
$response = $client->send($request);

The request ends up being sent to http://example.com/proxy-target instead of http://target-site.com/proxy-target

The new host header gets set up in https://github.com/zendframework/zend-http/blob/master/src/Client.php#L1110

But then gets replaced with the header from the request here: https://github.com/zendframework/zend-http/blob/master/src/Client.php#L1174

Shouldn't the new headers take precedence over the headers from the request?

dkmuir avatar Jun 28 '16 06:06 dkmuir

This repository has been closed and moved to laminas/laminas-http; a new issue has been opened at https://github.com/laminas/laminas-http/issues/19.

weierophinney avatar Dec 31 '19 22:12 weierophinney