Nyholm / psr7

A super lightweight PSR-7 implementation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting empty host , but filled path value.

gyaaniguy opened this issue · comments

Using this lib with kriswallsmith/Buzz

$request = new Request('GET', 'robu.in');
$this->client->sendAsyncRequest($request,$callback);

//Callback
$uri = $request->getUri(); 
$uri->host // is empty string
$uri->path // is 'robu.in' 

image

Not sure if this is expected behavior. But I was expecting the host to be filled in .

This is somewhat expected. I think.

By WHATWG URL parsing rules, I think the string robu.in is not a valid URL at all and this should have thrown. Not 100% sure how it goes by RFC 3986 rules, as followed by PSR.

We simply offload the parsing here to PHP’s built in function. My guess is that the lack of schema makes it put the information into path instead of host. PHP basically treats the string as a relative URL.

We rely on PHP’s internal parser completely:

var_dump(parse_url('robu.in'));
// array(1) {
//   ["path"]=>
//   string(7) "robu.in"
// }

Closing this for now. Anyone should feel free to reopen if there is some other suggestion for how to handle this. But I am pretty happy following whatever PHP does here.