Class yii\httpclient\debug\RequestExecuteAction
Inheritance | yii\httpclient\debug\RequestExecuteAction » yii\base\Action |
---|---|
Available since extension's version | 2.0 |
Source Code | https://github.com/yiisoft/yii2-httpclient/blob/master/src/debug/RequestExecuteAction.php |
RequestExecuteAction executes HTTP request and passes its result to the browser.
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$panel | yii\httpclient\debug\HttpClientPanel | yii\httpclient\debug\RequestExecuteAction |
Public Methods
Method | Description | Defined By |
---|---|---|
run() | yii\httpclient\debug\RequestExecuteAction |
Protected Methods
Method | Description | Defined By |
---|---|---|
createRequestFromLog() | Creates an HTTP request instance from log entry. | yii\httpclient\debug\RequestExecuteAction |
Property Details
Method Details
Creates an HTTP request instance from log entry.
protected yii\httpclient\Request createRequestFromLog ( $requestLog ) | ||
$requestLog | string |
HTTP request log entry |
return | yii\httpclient\Request |
Request instance. |
---|---|---|
throws | \yii\base\InvalidConfigException |
protected function createRequestFromLog($requestLog)
{
if (strpos($requestLog, "\n\n")) {
list($head, $content) = explode("\n\n", $requestLog, 2);
} else {
$head = $requestLog;
$content = null;
}
$headers = explode("\n", $head);
$main = array_shift($headers);
list($method, $url) = explode(' ', $main, 2);
return $this->panel->getHttpClient()->createRequest()
->setMethod($method)
->setUrl($url)
->setHeaders($headers)
->setContent($content);
}
public \yii\web\Response run ( $seq, $tag, $passthru = false ) | ||
$seq | string | |
$tag | string | |
$passthru | boolean |
Whether to send response to the browser or render it as plain text |
throws | \yii\web\HttpException | |
---|---|---|
throws | \yii\base\InvalidConfigException | |
throws | yii\httpclient\Exception |
public function run($seq, $tag, $passthru = false)
{
$this->controller->loadData($tag);
$timings = $this->panel->calculateTimings();
if (!isset($timings[$seq])) {
throw new HttpException(404, 'Log message not found.');
}
$requestInfo = $timings[$seq]['info'];
$httpRequest = $this->createRequestFromLog($requestInfo);
$httpResponse = $httpRequest->send();
$httpResponse->getHeaders()->get('content-type');
$response = new Response([
'format' => Response::FORMAT_RAW,
]);
if ($passthru) {
foreach ($httpResponse->getHeaders() as $name => $value) {
$response->getHeaders()->set($name, $value);
}
$response->content = $httpResponse->content;
return $response;
}
$response->getHeaders()->add('content-type', 'text/plain');
$response->content = $httpResponse->toString();
return $response;
}