Skip to content

Commit 27e375e

Browse files
committed
Merge pull request daviddesberg#164 from connyay/issue160
Fixes daviddesberg#160 Thanks Connor!
2 parents a2796af + 3669e6f commit 27e375e

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

src/OAuth/Common/Http/Client/StreamClient.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,13 @@ public function retrieveResponse(
4343
$extraHeaders['Content-type'] = 'Content-type: application/x-www-form-urlencoded';
4444
}
4545

46-
$extraHeaders['Host'] = 'Host: '.$endpoint->getHost();
46+
$host = 'Host: '.$endpoint->getHost();
47+
// Append port to Host if it has been specified
48+
if ($endpoint->hasExplicitPortSpecified()) {
49+
$host .= ':'.$endpoint->getPort();
50+
}
51+
52+
$extraHeaders['Host'] = $host;
4753
$extraHeaders['Connection'] = 'Connection: close';
4854

4955
if (is_array($requestBody)) {

src/OAuth/Common/Http/Uri/Uri.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,4 +397,12 @@ public function hasExplicitTrailingHostSlash()
397397
{
398398
return $this->explicitTrailingHostSlash;
399399
}
400+
401+
/**
402+
* @return bool
403+
*/
404+
public function hasExplicitPortSpecified()
405+
{
406+
return $this->explicitPortSpecified;
407+
}
400408
}

src/OAuth/Common/Http/Uri/UriInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,9 @@ public function getRelativeUri();
125125
* @return bool
126126
*/
127127
public function hasExplicitTrailingHostSlash();
128+
129+
/**
130+
* @return bool
131+
*/
132+
public function hasExplicitPortSpecified();
128133
}

tests/Unit/Common/Http/Uri/UriTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,4 +871,28 @@ public function testHasExplicitTrailingHostSlashFalse()
871871

872872
$this->assertFalse($uri->hasExplicitTrailingHostSlash());
873873
}
874+
875+
/**
876+
* @covers OAuth\Common\Http\Uri\Uri::__construct
877+
* @covers OAuth\Common\Http\Uri\Uri::parseUri
878+
* @covers OAuth\Common\Http\Uri\Uri::hasExplicitPortSpecified
879+
*/
880+
public function testHasExplicitPortSpecifiedTrue()
881+
{
882+
$uri = new Uri('http://example.com:8080');
883+
884+
$this->assertTrue($uri->hasExplicitPortSpecified());
885+
}
886+
887+
/**
888+
* @covers OAuth\Common\Http\Uri\Uri::__construct
889+
* @covers OAuth\Common\Http\Uri\Uri::parseUri
890+
* @covers OAuth\Common\Http\Uri\Uri::hasExplicitPortSpecified
891+
*/
892+
public function testHasExplicitPortSpecifiedFalse()
893+
{
894+
$uri = new Uri('http://example.com');
895+
896+
$this->assertFalse($uri->hasExplicitPortSpecified());
897+
}
874898
}

0 commit comments

Comments
 (0)