24 require_once
'HTTP/Request2/Adapter.php';
73 $requestUrl = (string)$request->
getUrl();
75 foreach ($this->responses as $k => $v) {
76 if (!$v[1] || $requestUrl == $v[1]) {
78 array_splice($this->responses, $k, 1);
83 return self::createResponseFromString(
"HTTP/1.1 400 Bad Request\r\n\r\n");
90 $class = get_class($response);
91 $message = $response->getMessage();
92 $code = $response->getCode();
93 throw new $class($message, $code);
109 if (is_string($response)) {
110 $response = self::createResponseFromString($response);
111 } elseif (is_resource($response)) {
112 $response = self::createResponseFromFile($response);
114 !$response instanceof Exception
118 $this->responses[] = array($response, $url);
131 $parts = preg_split(
'!(\r?\n){2}!m', $str, 2);
132 $headerLines = explode(
"\n", $parts[0]);
134 foreach ($headerLines as $headerLine) {
135 $response->parseHeaderLine($headerLine);
137 $response->parseHeaderLine(
'');
138 if (isset($parts[1])) {
139 $response->appendBody($parts[1]);
156 $headerLine = fgets($fp);
157 $response->parseHeaderLine($headerLine);
158 }
while (
'' != trim($headerLine));
161 $response->appendBody(fread($fp, 8192));
sendRequest(HTTP_Request2 $request)
static createResponseFromString($str)
static createResponseFromFile($fp)
addResponse($response, $url=null)