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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jasonwyz98 at gmail dot com
New email:
PHP Version: OS:

 

 [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-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 07:01:29 2024 UTC