本文整理汇总了PHP中TYPO3\Flow\Http\Response::createFromRaw方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::createFromRaw方法的具体用法?PHP Response::createFromRaw怎么用?PHP Response::createFromRaw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TYPO3\Flow\Http\Response
的用法示例。
在下文中一共展示了Response::createFromRaw方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sendRequest
/**
* Sends the given HTTP request
*
* @param \TYPO3\Flow\Http\Request $request
* @return \TYPO3\Flow\Http\Response The response or FALSE
* @api
* @throws \TYPO3\Flow\Http\Exception
* @throws CurlEngineException
*/
public function sendRequest(Request $request)
{
if (!extension_loaded('curl')) {
throw new \TYPO3\Flow\Http\Exception('CurlEngine requires the PHP CURL extension to be installed and loaded.', 1346319808);
}
$requestUri = $request->getUri();
$curlHandle = curl_init((string) $requestUri);
curl_setopt_array($curlHandle, $this->options);
// Send an empty Expect header in order to avoid chunked data transfer (which we can't handle yet).
// If we don't set this, cURL will set "Expect: 100-continue" for requests larger than 1024 bytes.
curl_setopt($curlHandle, CURLOPT_HTTPHEADER, array('Expect:'));
// If the content is a stream resource, use cURL's INFILE feature to stream it
$content = $request->getContent();
if (is_resource($content)) {
curl_setopt_array($curlHandle, array(CURLOPT_INFILE => $content, CURLOPT_INFILESIZE => $request->getHeader('Content-Length')));
}
switch ($request->getMethod()) {
case 'GET':
if ($request->getContent()) {
// workaround because else the request would implicitly fall into POST:
curl_setopt($curlHandle, CURLOPT_CUSTOMREQUEST, 'GET');
if (!is_resource($content)) {
curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $content);
}
}
break;
case 'POST':
curl_setopt($curlHandle, CURLOPT_POST, TRUE);
if (!is_resource($content)) {
$body = $content !== '' ? $content : http_build_query($request->getArguments());
curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $body);
}
break;
case 'PUT':
curl_setopt($curlHandle, CURLOPT_PUT, TRUE);
if (!is_resource($content) && $content !== '') {
$inFileHandler = fopen('php://temp', 'r+');
fwrite($inFileHandler, $request->getContent());
rewind($inFileHandler);
curl_setopt_array($curlHandle, array(CURLOPT_INFILE => $inFileHandler, CURLOPT_INFILESIZE => strlen($request->getContent())));
}
break;
default:
if (!is_resource($content)) {
$body = $content !== '' ? $content : http_build_query($request->getArguments());
curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $body);
}
curl_setopt($curlHandle, CURLOPT_CUSTOMREQUEST, $request->getMethod());
}
$preparedHeaders = array();
foreach ($request->getHeaders()->getAll() as $fieldName => $values) {
foreach ($values as $value) {
$preparedHeaders[] = $fieldName . ': ' . $value;
}
}
curl_setopt($curlHandle, CURLOPT_HTTPHEADER, $preparedHeaders);
// curl_setopt($curlHandle, CURLOPT_PROTOCOLS, CURLPROTO_HTTP && CURLPROTO_HTTPS);
// CURLOPT_UPLOAD
if ($requestUri->getPort() !== NULL) {
curl_setopt($curlHandle, CURLOPT_PORT, $requestUri->getPort());
}
// CURLOPT_COOKIE
$curlResult = curl_exec($curlHandle);
if ($curlResult === FALSE) {
throw new CurlEngineException(sprintf('cURL reported error code %s with message "%s". Last requested URL was "%s" (%s).', curl_errno($curlHandle), curl_error($curlHandle), curl_getinfo($curlHandle, CURLINFO_EFFECTIVE_URL), $request->getMethod()), 1338906040);
} elseif (strlen($curlResult) === 0) {
return FALSE;
}
curl_close($curlHandle);
$response = Response::createFromRaw($curlResult);
if ($response->getStatusCode() === 100) {
$response = Response::createFromRaw($response->getContent(), $response);
}
return $response;
}
示例2: getResponse
/**
* @return Response
*/
protected function getResponse()
{
$responseInfo = $this->oAuthClient->getLastResponseInfo();
$response = Response::createFromRaw($responseInfo['headers_recv']);
$response->appendContent($this->oAuthClient->getLastResponse());
return $response;
}
示例3: mergeHttpResponseFromOutput
/**
* @param string $output
* @param Runtime $typoScriptRuntime
* @return string The message body without the message head
*/
protected function mergeHttpResponseFromOutput($output, Runtime $typoScriptRuntime)
{
if (substr($output, 0, 5) === 'HTTP/') {
$endOfHeader = strpos($output, "\r\n\r\n");
if ($endOfHeader !== false) {
$header = substr($output, 0, $endOfHeader + 4);
try {
$renderedResponse = Response::createFromRaw($header);
/** @var Response $response */
$response = $typoScriptRuntime->getControllerContext()->getResponse();
$response->setStatus($renderedResponse->getStatusCode());
foreach ($renderedResponse->getHeaders()->getAll() as $headerName => $headerValues) {
$response->setHeader($headerName, $headerValues[0]);
}
$output = substr($output, strlen($header));
} catch (\InvalidArgumentException $exception) {
}
}
}
return $output;
}
示例4: settingVersionHasExpectedImplications
/**
* @test
*/
public function settingVersionHasExpectedImplications()
{
$response = Response::createFromRaw(file_get_contents(__DIR__ . '/../Fixtures/RawResponse-1.txt'));
$response->setVersion('HTTP/1.0');
$this->assertEquals('HTTP/1.0', $response->getVersion());
$this->assertStringStartsWith('HTTP/1.0', $response->getStatusLine());
}
示例5: getResponse
/**
* @return Response
*/
protected function getResponse()
{
$responseHeaders = $this->oAuthClient->getLastResponseHeaders();
$response = Response::createFromRaw($responseHeaders);
$response->appendContent($this->oAuthClient->getLastResponse());
return $response;
}
示例6: createFromRawThrowsExceptionOnFirstLine
/**
* @test
* @expectedException \InvalidArgumentException
*/
public function createFromRawThrowsExceptionOnFirstLine()
{
Response::createFromRaw('No valid response');
}