php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69314 http\Url infers incorrect default scheme ports from apache request
Submitted: 2015-03-27 01:20 UTC Modified: 2015-03-27 07:32 UTC
From: php at qzxj dot net Assigned: mike (profile)
Status: Not a bug Package: pecl_http (PECL)
PHP Version: 5.6.7 OS: Ubuntu
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: php at qzxj dot net
New email:
PHP Version: OS:

 

 [2015-03-27 01:20 UTC] php at qzxj dot net
Description:
------------
Using the CLI it works as I'd expect - no ports are inferred using http or https when one is not specified:

    $ php test.php
    http://example.com/yep
    https://example.com/yep

http\Url incorrectly infers port 80 for https Url when request is made using http protocol to PHP apache2 handler:

    $ curl ht tp://localhost/test.php
    http://example.com/yep
    https://example.com:80/yep

http\Url incorrectly infers port 443 for http Url when request is made using https protocol to PHP apache2 handler:

    $ curl -k ht tps://localhost/test.php
    http://example.com:443/yep
    https://example.com/yep

Using PHP's development server infers the same port for both http and https:


    $ php -S 127.0.0.1:1234 > /tmp/php.log 2>&1 &
    $ curl http://localhost:1234/test.php
    http://example.com:1234/yep
    https://example.com:1234/yep

Using Ubuntu 14.04 and 14.10, PHP 5.6.7, Apache 2.4. 32-bit and 64-bit.

Sorry, I had to mangle some of the URLs in the curl call examples to get around the spam filter.

Test script:
---------------
<?php
$u = new \http\Url("http://example.com/yep");
echo $u."\n";

$u = new \http\Url("https://example.com/yep");
echo $u."\n";



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-03-27 07:32 UTC] mike@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: mike
 [2015-03-27 07:32 UTC] mike@php.net
If you don't want http\Url to infer parts of the URL from the environment, you have to set the $flags argument of http\Url::__construct(), which defaults to http\Url::FROM_ENV. 

See http://devel-m6w6.rhcloud.com/mdref/http/Url/__construct

Please let me know, if that's what you're looking for.
 [2015-03-27 08:26 UTC] php at qzxj dot net
This is quite astonishing behaviour. It has taken every developer on my team by surprise at least once in just two months. I beg you, please remove http\Url::FROM_ENV from the default! Perhaps http\Env\Url would be a good complement, given the presence of http\Env\Request and http\Env\Response, then http\Url can simply be a generic representation with more explicit semantics?
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 06:01:38 2025 UTC