Skip to content

Commit

Permalink
Added content length to JHttp.
Browse files Browse the repository at this point in the history
Added authentication support to Github.
  • Loading branch information
Ian MacLennan committed Nov 15, 2011
1 parent 68216e3 commit 54d8800
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
10 changes: 10 additions & 0 deletions libraries/joomla/github/object.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ protected function fetchUrl($path, $page = 0, $limit = 0)
// Get a new JUri object fousing the api url and given path.
$uri = new JUri($this->options->get('api.url') . $path);

if ($this->options->get('api.username', false))
{
$uri->setUser($this->options->get('api.username'));
}

if ($this->options->get('api.password', false))
{
$uri->setPass($this->options->get('api.password'));
}

// If we have a defined page number add it to the JUri object.
if ($page > 0)
{
Expand Down
2 changes: 2 additions & 0 deletions libraries/joomla/http/transport/curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ public function request($method, JUri $uri, $data = null, array $headers = null,
{
$headers['Content-type'] = 'application/x-www-form-urlencoded';
}

$headers['Content-length'] = strlen($options['content']);
}

// Build the headers string for the request.
Expand Down
2 changes: 2 additions & 0 deletions libraries/joomla/http/transport/stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public function request($method, JUri $uri, $data = null, array $headers = null,
{
$headers['Content-type'] = 'application/x-www-form-urlencoded';
}

$headers['Content-length'] = strlen($options['content']);
}

// Build the headers string for the request.
Expand Down
24 changes: 24 additions & 0 deletions tests/suite/joomla/http/JHttpTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,30 @@ public function testRequestGet($transportClass)
);
}

/**
* Tests the request method with a put request
*
* @dataProvider transportProvider
*/
public function testRequestPut($transportClass)
{
$transport = new $transportClass($this->options);

$response = $transport->request('put', new JUri($this->config->jhttp_stub));

$body = json_decode($response->body);

$this->assertThat(
$response->code,
$this->equalTo(200)
);

$this->assertThat(
$body->method,
$this->equalTo('PUT')
);
}

/**
* Tests the request method with a post request and array data
*
Expand Down

0 comments on commit 54d8800

Please sign in to comment.