Skip to content
This repository was archived by the owner on Apr 21, 2019. It is now read-only.

Commit c1a97be

Browse files
committedDec 2, 2011
add client->response_raw, fix typo
1 parent cf8b83e commit c1a97be

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed
 

‎README.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ pecl http module settings, see examples below. Constructor accepts all *http_opt
99
from http://us.php.net/manual/en/http.request.options.php . Easy to extend.
1010

1111
Detailed response information and [response object](http://us.php.net/manual/en/class.httpresponse.php)
12-
are respectively in *$client->response_info* and *$client->response_object*
12+
are respectively in *$client->response_info* and *$client->response_object*.
13+
Raw response data is available in *$client->response_raw*
1314

1415
Examples
1516
--------
@@ -60,6 +61,14 @@ Examples
6061
'http://www.example.com/upload.txt', 'PUT request data'
6162
);
6263

64+
*RAW response data*
65+
66+
$res = $c->get(
67+
'http://www.example.com/upload.txt'
68+
);
69+
70+
echo $c->response_raw;
71+
6372
References
6473
----------
6574

‎rest_client.php

+17-16
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ class RestClientException extends Exception {
1515
class RestClient {
1616

1717
const COOKIE_JAR = '/tmp/rest-client-cookie';
18-
const AGENT = 'rest-client-php/0.0.1';
18+
const AGENT = 'rest-client-php/0.0.2';
1919

2020
public $response_info;
21-
public $resonse_object;
21+
public $response_object;
22+
public $response_raw;
2223

2324
public $http_options = array();
2425

@@ -35,7 +36,7 @@ function get($url, $http_options = array()) {
3536
$this->http_parse_message(
3637
http_get($url, $http_options, $this->response_info)
3738
);
38-
return $this->resonse_object->body;
39+
return $this->response_object->body;
3940
}
4041

4142
function post($url, $fields = array(), $http_options = array()) {
@@ -44,46 +45,46 @@ function post($url, $fields = array(), $http_options = array()) {
4445
http_post_fields($url, $fields, array(), $http_options, $this->response_info) :
4546
http_post_data($url, $fields, $http_options, $this->response_info);
4647
$this->http_parse_message($res);
47-
return $this->resonse_object->body;
48+
return $this->response_object->body;
4849
}
4950

5051
function put($url, $data = '', $http_options = array()) {
5152
$http_options = array_merge($this->http_options, $http_options);
5253
$this->http_parse_message(
5354
http_put_data($url, $data, $http_options, $this->response_info)
5455
);
55-
return $this->resonse_object->body;
56+
return $this->response_object->body;
5657
}
5758

5859
function delete($url, $http_options = array()) {
5960
$http_options = array_merge($this->http_options, $http_options);
6061
$this->http_parse_message(
6162
http_request(HTTP_METH_DELETE, $url, '', $http_options, $this->response_info)
6263
);
63-
return $this->resonse_object->body;
64+
return $this->response_object->body;
6465
}
6566

6667
function http_parse_message($res) {
67-
68-
$this->resonse_object = http_parse_message($res);
68+
$this->response_raw = $res;
69+
$this->response_object = http_parse_message($res);
6970

70-
if($this->resonse_object->responseCode == 404) {
71+
if($this->response_object->responseCode == 404) {
7172
throw new HttpServerException404(
72-
$this->resonse_object->responseStatus
73+
$this->response_object->responseStatus
7374
);
7475
}
7576

76-
if($this->resonse_object->responseCode >= 400 && $this->resonse_object->responseCode <=600) {
77+
if($this->response_object->responseCode >= 400 && $this->response_object->responseCode <=600) {
7778
throw new HttpServerException(
78-
$this->resonse_object->responseStatus,
79-
$this->resonse_object->responseCode
79+
$this->response_object->responseStatus,
80+
$this->response_object->responseCode
8081
);
8182
}
8283

83-
if(!in_array($this->resonse_object->responseCode, range(200,207))) {
84+
if(!in_array($this->response_object->responseCode, range(200,207))) {
8485
throw new RestClientException(
85-
$this->resonse_object->responseStatus,
86-
$this->resonse_object->responseCode
86+
$this->response_object->responseStatus,
87+
$this->response_object->responseCode
8788
);
8889
}
8990
}

0 commit comments

Comments
 (0)
This repository has been archived.