php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #59179 HttpRequest->getUrl() returns the wrong scheme
Submitted: 2010-04-26 05:48 UTC Modified: 2010-04-28 02:46 UTC
From: jasonwyz98 at gmail dot com Assigned: mike (profile)
Status: Wont fix Package: pecl_http (PECL)
PHP Version: 5.3.2 OS: Ubuntu 9.10
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
48 + 5 = ?
Subscribe to this entry?

 
 [2010-04-26 05:48 UTC] jasonwyz98 at gmail dot com
Description:
------------
Hi

HttpRequest->getUrl() returns the wrong scheme, it doesn't handle the scheme HTTPS.

ex. If I access a resource via https://localhost/test.php

the getUrl() method returns "http://localhost/test.php" instead of "https://localhost/test.php"

Thanks

Reproduce code:
---------------
1. Create a file test.php with the following code:

$req = HttpMessage::fromEnv( \HttpMessage::TYPE_REQUEST )->toMessageTypeObject();

echo $req->getUrl();

Expected result:
----------------
https://localhost/test.php

Actual result:
--------------
http://localhost/test.php

It should be "https"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-04-27 09:30 UTC] mike@php.net
Well, acutally that's not totally true.

The message does not know the scheme it was sent/accessed/delivered, as it loos like:

GET /test.php HTTP/1.1
Host: localhost
...

- REQUEST_URI actually is "/test.php" only in HttpMessage::fromEnv().

- in HttpMessage->toMessageTypeObject() the message checks if it has a "Host" header to adapt the request url.

You might want to overreide the request's url with the ENV's URL:

$request->setUrl(http_build_url());
 [2010-04-27 23:32 UTC] jasonwyz98 at gmail dot com
Hi Mike

I see your point, but can we test $_SERVER['HTTPS'] or similar to see if it's set and determine whether it's http/https.

This would make pecl_http extension more robust.

Thanks
 [2010-04-28 02:46 UTC] mike@php.net
Hi Jason, no you actually didn't see my point, sorry.

What I meant to say is, that the message does not care how it was transported, and at the time of the call of toMessageTypeObject() it doesn't know it has been scraped from the environment.

Though, I'm still open for meaningful suggestions.

Thank you.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Mon Oct 21 15:01:27 2019 UTC