Changeset 1491

Show
Ignore:
Timestamp:
04/04/08 11:37:14 (5 months ago)
Author:
mikey
Message:

allow to inject a header list

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/peer/http/stubHTTPConnection.php

    r1486 r1491  
    4545     * constructor 
    4646     * 
    47      * @param  stubHTTPURL  $http  url to create connection to 
     47     * @param  stubHTTPURL     $http     url to create connection to 
     48     * @param  stubHeaderList  $headers  optional  list of headers to be used 
    4849     */ 
    49     public function __construct(stubHTTPURL $http
     50    public function __construct(stubHTTPURL $http, stubHeaderList $headers = null
    5051    { 
    5152        $this->url     = $http; 
    52         $this->headers = new stubHeaderList(); 
     53        if (null === $headers) { 
     54            $this->headers = new stubHeaderList(); 
     55        } else { 
     56            $this->headers = $headers; 
     57        } 
     58    } 
     59 
     60    /** 
     61     * returns list of headers 
     62     * 
     63     * @return  stubHeaderList 
     64     */ 
     65    public function getHeaderList() 
     66    { 
     67        return $this->headers; 
    5368    } 
    5469 
  • trunk/src/main/php/net/stubbles/peer/http/stubHTTPURL.php

    r1486 r1491  
    169169     * </code> 
    170170     * 
     171     * @param   stubHeaderList      $headers  optional  list of headers to be used 
    171172     * @return  stubHTTPConnection 
    172173     */ 
    173     public function connect(
     174    public function connect(stubHeaderList $headers = null
    174175    { 
    175176        stubClassLoader::load('net::stubbles::peer::http::stubHTTPConnection'); 
    176         return new stubHTTPConnection($this); 
     177        return new stubHTTPConnection($this, $headers); 
    177178    } 
    178179 
  • trunk/src/test/php/net/stubbles/peer/http/stubHTTPURLTestCase.php

    r1486 r1491  
    105105 
    106106    /** 
     107     * assure that values are returned the expected way 
     108     * 
     109     * @test 
     110     */ 
     111    public function valueHTTPSIP() 
     112    { 
     113        $http = stubHTTPURL::fromString('https://127.0.0.1:125/'); 
     114        $this->assertTrue($http->isValid()); 
     115        $this->assertFalse($http->hasDefaultPort()); 
     116        $this->assertEquals('https://127.0.0.1/', $http->get()); 
     117        $this->assertEquals('https://127.0.0.1:125/', $http->get(true)); 
     118        $this->assertEquals('127.0.0.1', $http->getHost()); 
     119        $this->assertEquals(125, $http->getPort()); 
     120        $this->assertEquals($http->getPath(), '/'); 
     121        $this->assertFalse($http->hasQuery()); 
     122        $this->assertTrue($http->checkDNS()); 
     123    } 
     124 
     125    /** 
    107126     * assure that wrong values trigger an exception 
    108127     * 
     
    242261        $this->assertType('stubHTTPConnection', $httpconnection); 
    243262    } 
     263 
     264    /** 
     265     * assure getting a connection works as expected 
     266     * 
     267     * @test 
     268     */ 
     269    public function connectionWithHeaderList() 
     270    { 
     271        $http    = stubHTTPURL::fromString('http://example.com/'); 
     272        $headers = new stubHeaderList(); 
     273        $httpconnection = $http->connect($headers); 
     274        $this->assertType('stubHTTPConnection', $httpconnection); 
     275        $this->assertSame($headers, $httpconnection->getHeaderList()); 
     276    } 
    244277} 
    245278?>