mirror of
https://0xacab.org/radar/radar-wp.git
synced 2025-04-19 14:27:30 +02:00
Initial import.
This commit is contained in:
commit
86383280c9
428 changed files with 68738 additions and 0 deletions
58
vendor/guzzle/parser/Guzzle/Parser/Message/AbstractMessageParser.php
vendored
Normal file
58
vendor/guzzle/parser/Guzzle/Parser/Message/AbstractMessageParser.php
vendored
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace Guzzle\Parser\Message;
|
||||
|
||||
/**
|
||||
* Implements shared message parsing functionality
|
||||
*/
|
||||
abstract class AbstractMessageParser implements MessageParserInterface
|
||||
{
|
||||
/**
|
||||
* Create URL parts from HTTP message parts
|
||||
*
|
||||
* @param string $requestUrl Associated URL
|
||||
* @param array $parts HTTP message parts
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getUrlPartsFromMessage($requestUrl, array $parts)
|
||||
{
|
||||
// Parse the URL information from the message
|
||||
$urlParts = array(
|
||||
'path' => $requestUrl,
|
||||
'scheme' => 'http'
|
||||
);
|
||||
|
||||
// Check for the Host header
|
||||
if (isset($parts['headers']['Host'])) {
|
||||
$urlParts['host'] = $parts['headers']['Host'];
|
||||
} elseif (isset($parts['headers']['host'])) {
|
||||
$urlParts['host'] = $parts['headers']['host'];
|
||||
} else {
|
||||
$urlParts['host'] = null;
|
||||
}
|
||||
|
||||
if (false === strpos($urlParts['host'], ':')) {
|
||||
$urlParts['port'] = '';
|
||||
} else {
|
||||
$hostParts = explode(':', $urlParts['host']);
|
||||
$urlParts['host'] = trim($hostParts[0]);
|
||||
$urlParts['port'] = (int) trim($hostParts[1]);
|
||||
if ($urlParts['port'] == 443) {
|
||||
$urlParts['scheme'] = 'https';
|
||||
}
|
||||
}
|
||||
|
||||
// Check if a query is present
|
||||
$path = $urlParts['path'];
|
||||
$qpos = strpos($path, '?');
|
||||
if ($qpos) {
|
||||
$urlParts['query'] = substr($path, $qpos + 1);
|
||||
$urlParts['path'] = substr($path, 0, $qpos);
|
||||
} else {
|
||||
$urlParts['query'] = '';
|
||||
}
|
||||
|
||||
return $urlParts;
|
||||
}
|
||||
}
|
110
vendor/guzzle/parser/Guzzle/Parser/Message/MessageParser.php
vendored
Normal file
110
vendor/guzzle/parser/Guzzle/Parser/Message/MessageParser.php
vendored
Normal file
|
@ -0,0 +1,110 @@
|
|||
<?php
|
||||
|
||||
namespace Guzzle\Parser\Message;
|
||||
|
||||
/**
|
||||
* Default request and response parser used by Guzzle. Optimized for speed.
|
||||
*/
|
||||
class MessageParser extends AbstractMessageParser
|
||||
{
|
||||
public function parseRequest($message)
|
||||
{
|
||||
if (!$message) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$parts = $this->parseMessage($message);
|
||||
|
||||
// Parse the protocol and protocol version
|
||||
if (isset($parts['start_line'][2])) {
|
||||
$startParts = explode('/', $parts['start_line'][2]);
|
||||
$protocol = strtoupper($startParts[0]);
|
||||
$version = isset($startParts[1]) ? $startParts[1] : '1.1';
|
||||
} else {
|
||||
$protocol = 'HTTP';
|
||||
$version = '1.1';
|
||||
}
|
||||
|
||||
$parsed = array(
|
||||
'method' => strtoupper($parts['start_line'][0]),
|
||||
'protocol' => $protocol,
|
||||
'version' => $version,
|
||||
'headers' => $parts['headers'],
|
||||
'body' => $parts['body']
|
||||
);
|
||||
|
||||
$parsed['request_url'] = $this->getUrlPartsFromMessage($parts['start_line'][1], $parsed);
|
||||
|
||||
return $parsed;
|
||||
}
|
||||
|
||||
public function parseResponse($message)
|
||||
{
|
||||
if (!$message) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$parts = $this->parseMessage($message);
|
||||
list($protocol, $version) = explode('/', trim($parts['start_line'][0]));
|
||||
|
||||
return array(
|
||||
'protocol' => $protocol,
|
||||
'version' => $version,
|
||||
'code' => $parts['start_line'][1],
|
||||
'reason_phrase' => isset($parts['start_line'][2]) ? $parts['start_line'][2] : '',
|
||||
'headers' => $parts['headers'],
|
||||
'body' => $parts['body']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a message into parts
|
||||
*
|
||||
* @param string $message Message to parse
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function parseMessage($message)
|
||||
{
|
||||
$startLine = null;
|
||||
$headers = array();
|
||||
$body = '';
|
||||
|
||||
// Iterate over each line in the message, accounting for line endings
|
||||
$lines = preg_split('/(\\r?\\n)/', $message, -1, PREG_SPLIT_DELIM_CAPTURE);
|
||||
for ($i = 0, $totalLines = count($lines); $i < $totalLines; $i += 2) {
|
||||
|
||||
$line = $lines[$i];
|
||||
|
||||
// If two line breaks were encountered, then this is the end of body
|
||||
if (empty($line)) {
|
||||
if ($i < $totalLines - 1) {
|
||||
$body = implode('', array_slice($lines, $i + 2));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Parse message headers
|
||||
if (!$startLine) {
|
||||
$startLine = explode(' ', $line, 3);
|
||||
} elseif (strpos($line, ':')) {
|
||||
$parts = explode(':', $line, 2);
|
||||
$key = trim($parts[0]);
|
||||
$value = isset($parts[1]) ? trim($parts[1]) : '';
|
||||
if (!isset($headers[$key])) {
|
||||
$headers[$key] = $value;
|
||||
} elseif (!is_array($headers[$key])) {
|
||||
$headers[$key] = array($headers[$key], $value);
|
||||
} else {
|
||||
$headers[$key][] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
'start_line' => $startLine,
|
||||
'headers' => $headers,
|
||||
'body' => $body
|
||||
);
|
||||
}
|
||||
}
|
27
vendor/guzzle/parser/Guzzle/Parser/Message/MessageParserInterface.php
vendored
Normal file
27
vendor/guzzle/parser/Guzzle/Parser/Message/MessageParserInterface.php
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Guzzle\Parser\Message;
|
||||
|
||||
/**
|
||||
* HTTP message parser interface used to parse HTTP messages into an array
|
||||
*/
|
||||
interface MessageParserInterface
|
||||
{
|
||||
/**
|
||||
* Parse an HTTP request message into an associative array of parts.
|
||||
*
|
||||
* @param string $message HTTP request to parse
|
||||
*
|
||||
* @return array|bool Returns false if the message is invalid
|
||||
*/
|
||||
public function parseRequest($message);
|
||||
|
||||
/**
|
||||
* Parse an HTTP response message into an associative array of parts.
|
||||
*
|
||||
* @param string $message HTTP response to parse
|
||||
*
|
||||
* @return array|bool Returns false if the message is invalid
|
||||
*/
|
||||
public function parseResponse($message);
|
||||
}
|
48
vendor/guzzle/parser/Guzzle/Parser/Message/PeclHttpMessageParser.php
vendored
Normal file
48
vendor/guzzle/parser/Guzzle/Parser/Message/PeclHttpMessageParser.php
vendored
Normal file
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
namespace Guzzle\Parser\Message;
|
||||
|
||||
/**
|
||||
* Pecl HTTP message parser
|
||||
*/
|
||||
class PeclHttpMessageParser extends AbstractMessageParser
|
||||
{
|
||||
public function parseRequest($message)
|
||||
{
|
||||
if (!$message) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$parts = http_parse_message($message);
|
||||
|
||||
$parsed = array(
|
||||
'method' => $parts->requestMethod,
|
||||
'protocol' => 'HTTP',
|
||||
'version' => number_format($parts->httpVersion, 1),
|
||||
'headers' => $parts->headers,
|
||||
'body' => $parts->body
|
||||
);
|
||||
|
||||
$parsed['request_url'] = $this->getUrlPartsFromMessage($parts->requestUrl, $parsed);
|
||||
|
||||
return $parsed;
|
||||
}
|
||||
|
||||
public function parseResponse($message)
|
||||
{
|
||||
if (!$message) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$parts = http_parse_message($message);
|
||||
|
||||
return array(
|
||||
'protocol' => 'HTTP',
|
||||
'version' => number_format($parts->httpVersion, 1),
|
||||
'code' => $parts->responseCode,
|
||||
'reason_phrase' => $parts->responseStatus,
|
||||
'headers' => $parts->headers,
|
||||
'body' => $parts->body
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue