diff --git a/.coveralls.yml b/.coveralls.yml index 5697ff1..cbd906c 100644 --- a/.coveralls.yml +++ b/.coveralls.yml @@ -1,3 +1,3 @@ -src_dir: . +src_dir: src coverage_clover: build/logs/clover.xml json_path: build/logs/coveralls-upload.json \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index ed96065..41e7648 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ language: php php: - 5.6 - 7.0 + - 7.2 - hhvm diff --git a/Curl/Collector/HeaderCollector.php b/Curl/Collector/HeaderCollector.php deleted file mode 100644 index ca19e26..0000000 --- a/Curl/Collector/HeaderCollector.php +++ /dev/null @@ -1,79 +0,0 @@ -parseHttp($cleanHeader); - } else { - $this->parseHeader($cleanHeader); - } - - return strlen($headerString); - } - - /** - * Parse the `HTTP/1.0 200 OK' header into the proper - * Status Code/Message and Protocol Version fields - * - * @param string $header - */ - private function parseHttp($header) { - list($version,$code,$message) = explode(" ", $header); - - $versionParts = explode("/",$version); - $this->version = end($versionParts); - $this->code = $code; - $this->message = $message; - } - - /** - * Parse the standard `Header-name: value' headers into - * individual header name/value pairs - * - * @param string $header - */ - private function parseHeader($header) { - if(!empty($header)) { - $pos = strpos($header, ": "); - - if(false !== $pos) { - $name = substr($header,0,$pos); - $value = substr($header,$pos+2); - - $this->headers[$name] = $value; - } - } - } - - public function retrieve() { - return $this->headers; - } - - public function getVersion() { - return $this->version; - } - - public function getMessage() { - return $this->message; - } - - public function getCode() { - return $this->code; - } -} diff --git a/Curl/CurlHeaderCollector.php b/Curl/CurlHeaderCollector.php deleted file mode 100644 index 94303f5..0000000 --- a/Curl/CurlHeaderCollector.php +++ /dev/null @@ -1,149 +0,0 @@ -parseHttp($cleanHeader); - } else { - $this->parseHeader($cleanHeader); - } - - return strlen($headerString); - } - - /** - * Parse the `HTTP/1.0 200 OK' header into the proper - * Status Code/Message and Protocol Version fields - * - * @param string $header - */ - private function parseHttp($header) { - list($version,$code,$message) = explode(" ", $header); - - $this->transactionHeaders[] = $header; - - $versionParts = explode("/",$version); - $this->version = end($versionParts); - $this->code = $code; - $this->message = $message; - } - - /** - * Parse the standard `Header-name: value' headers into - * individual header name/value pairs - * - * @param string $header - */ - private function parseHeader($header) { - - - if (empty($header)) { - return; - } - - $pos = strpos($header, ": "); - - if (false !== $pos) { - - $name = trim(substr($header, 0, $pos)); - $value = substr($header, $pos+2); - - if (strtolower($name) == "set-cookie") { - - $cookie = CookieParser::fromString($value); - $this->cookies[] = new Cookie( - $cookie->getName(), - $cookie->getRawValue(), - (int)$cookie->getExpiresTime(), - $cookie->getPath(), - $cookie->getDomain(), - $cookie->isSecure(), - $cookie->isHttpOnly() - ); - - } else { - - $this->headers[$name] = $value; - - } - } - - } - - public function retrieve() { - return $this->headers; - } - - public function getVersion() { - return $this->version; - } - - public function getMessage() { - return $this->message; - } - - public function getCode() { - return $this->code; - } - - /** - * @return array|Cookie get a list of Cookie instances - */ - public function getCookies() - { - return $this->cookies; - } - - /** - * @return array - */ - public function getTransactionHeaders() - { - return $this->transactionHeaders; - } - - - -} \ No newline at end of file diff --git a/composer.json b/composer.json index 2d42625..3daaa27 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,10 @@ }, "license": "MIT", "autoload": { - "psr-4": { "evaisse\\SimpleHttpBundle\\": "" } + "psr-4": { + "evaisse\\SimpleHttpBundle\\Tests\\": "tests/", + "evaisse\\SimpleHttpBundle\\": "src/" + } }, "authors": [ { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index dc0f8e8..dfdb6c3 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,18 +1,18 @@ - + - - ./Tests + + ./tests - ./Http - ./Service + ./src + ./src/Twig ./vendor - ./Tests + ./tests diff --git a/Controller/ReplayController.php b/src/Controller/ReplayController.php similarity index 100% rename from Controller/ReplayController.php rename to src/Controller/ReplayController.php diff --git a/Curl/Collector/CollectorInterface.php b/src/Curl/Collector/CollectorInterface.php similarity index 100% rename from Curl/Collector/CollectorInterface.php rename to src/Curl/Collector/CollectorInterface.php diff --git a/Curl/Collector/ContentCollector.php b/src/Curl/Collector/ContentCollector.php similarity index 100% rename from Curl/Collector/ContentCollector.php rename to src/Curl/Collector/ContentCollector.php diff --git a/src/Curl/Collector/HeaderCollector.php b/src/Curl/Collector/HeaderCollector.php new file mode 100644 index 0000000..7b4650e --- /dev/null +++ b/src/Curl/Collector/HeaderCollector.php @@ -0,0 +1,205 @@ +rawHeaders .= $headerString; + + $cleanHeader = trim($headerString); + + // The HTTP/X.X XXX XXX header is also passed through this function + // and must be parsed differently than the other HTTP headers + if (!$this->parseHttpVersionheader($cleanHeader)) { + $this->parseHeader($cleanHeader); + } + + return strlen($headerString); + } + + /** + * handle the 100 continue & 200 Connection establish code + * by stripping any extra headers directive before the latest one. + * + * e.g. "HTTP\/1.1 100 Continue\r\n\r\nHTTP\/1.1 200 Connection established\r\n\r\nHTTP\/1.1 200 OK\r\nContent-Type: application\/json; charset=utf-8\r\nDate: Mon, 17 Oct 2016 14:59:22 GMT\r\nExpires: Mon, 17 Oct 2016 14:59:22 GMT\r\nCache-Control: private, max-age=0\r\nX-Content-Type-Options: nosniff\r\nX-XSS-Protection: 1; mode=block\r\nServer: GSE\r\nAlt-Svc: quic=\":443\"; ma=2592000; v=\"36,35,34,33,32\"\r\nAccept-Ranges: none\r\nVary: Accept-Encoding\r\nTransfer-Encoding: chunked\r\n\r\n{\n??\"success\": true,\n??\"challenge_ts\": \"2016-10-17T14:59:12Z\",\n??\"hostname\": \"clients.boursorama.com\"\n}" + * + * let's celebrate : https://httpstatusdogs.com/100-continue + * @param string $header + */ + protected function parseHttpVersionheader($header) + { + if (!preg_match('/^http\/(\d+\.\d+)\s+(\d+)\s+(.+)/i', $header, $r)) { + return; + } + + $this->transactionHeaders[] = $header; + + // reset headers records since another transaction header has started, but keep cookies for redirections + $this->headers = []; + + + + $this->version = $r[1]; + $this->code = (int)$r[2]; + $this->message = trim($r[3]); + } + + /** + * Parse the standard `Header-name: value' headers into + * individual header name/value pairs + * + * @param string $header + */ + protected function parseHeader($header) + { + + // skip empty headers lines + if (empty($header)) { + return; + } + + if (!preg_match('/([a-z0-9][a-z0-9\-]*)\:\s*(.*)/i', $header, $h)) { + return; + } + + $name = str_replace(' ', '-', ucwords(str_replace('-', ' ', strtolower($h[1])))); + $value = $h[2]; + + if (strtolower($name) == "set-cookie") { + + try { + $cookie = CookieParser::fromString($value); + } catch (\InvalidArgumentException $e) { + // skip invalid cookie line + return; + } + + $this->cookies[] = new Cookie( + $cookie->getName(), + $cookie->getRawValue(), + (int)$cookie->getExpiresTime(), + $cookie->getPath(), + $cookie->getDomain(), + $cookie->isSecure(), + $cookie->isHttpOnly() + ); + + } else { + $this->headers[$name] = $value; + } + + } + + /** + * @return string[] + */ + public function retrieve() + { + return $this->headers; + } + + + /** + * @return Cookie[] get a list of Cookie instances + */ + public function getCookies() + { + return $this->cookies; + } + + /** + * @return string[] + */ + public function getTransactionHeaders() + { + return $this->transactionHeaders; + } + + /** + * @return string[] + */ + public function getHeaders() + { + return $this->headers; + } + + /** + * @return string + */ + public function getVersion() + { + return $this->version; + } + + /** + * @return int + */ + public function getCode() + { + return $this->code; + } + + /** + * @return string + */ + public function getMessage() + { + return $this->message; + } + + /** + * @return string + */ + public function getAllTransactionHeaders() + { + return $this->rawHeaders; + } + +} diff --git a/Curl/CurlErrorException.php b/src/Curl/CurlErrorException.php similarity index 100% rename from Curl/CurlErrorException.php rename to src/Curl/CurlErrorException.php diff --git a/Curl/CurlEvents.php b/src/Curl/CurlEvents.php similarity index 100% rename from Curl/CurlEvents.php rename to src/Curl/CurlEvents.php diff --git a/src/Curl/CurlHeaderCollector.php b/src/Curl/CurlHeaderCollector.php new file mode 100644 index 0000000..7e5c811 --- /dev/null +++ b/src/Curl/CurlHeaderCollector.php @@ -0,0 +1,17 @@ +headers->get('charset', '') == "utf-8" - || stripos($response->headers->get('content-type', ''), 'utf-8') !== 0 - ) { - $encoders = array(new LazyJsonEncoder()); - } else { - $encoders = array(new LazyJsonEncoder()); - } $normalizers = array(new CustomGetSetNormalizer()); $encoders = array(new LazyJsonEncoder()); @@ -584,4 +577,6 @@ public function urlsafeB64Encode($input) return str_replace('=', '', strtr(base64_encode($input), '+/', '-_')); } + + } diff --git a/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php similarity index 100% rename from DependencyInjection/Configuration.php rename to src/DependencyInjection/Configuration.php diff --git a/DependencyInjection/SimpleHttpExtension.php b/src/DependencyInjection/SimpleHttpExtension.php similarity index 100% rename from DependencyInjection/SimpleHttpExtension.php rename to src/DependencyInjection/SimpleHttpExtension.php diff --git a/Http/Event.php b/src/Http/Event.php similarity index 100% rename from Http/Event.php rename to src/Http/Event.php diff --git a/Http/Exception.php b/src/Http/Exception.php similarity index 100% rename from Http/Exception.php rename to src/Http/Exception.php diff --git a/Http/Exception/BadGatewayHttpException.php b/src/Http/Exception/BadGatewayHttpException.php similarity index 100% rename from Http/Exception/BadGatewayHttpException.php rename to src/Http/Exception/BadGatewayHttpException.php diff --git a/Http/Exception/ClientErrorHttpException.php b/src/Http/Exception/ClientErrorHttpException.php similarity index 100% rename from Http/Exception/ClientErrorHttpException.php rename to src/Http/Exception/ClientErrorHttpException.php diff --git a/Http/Exception/CurlTransportException.php b/src/Http/Exception/CurlTransportException.php similarity index 100% rename from Http/Exception/CurlTransportException.php rename to src/Http/Exception/CurlTransportException.php diff --git a/Http/Exception/ErrorHttpException.php b/src/Http/Exception/ErrorHttpException.php similarity index 100% rename from Http/Exception/ErrorHttpException.php rename to src/Http/Exception/ErrorHttpException.php diff --git a/Http/Exception/ExpectationFailedHttpException.php b/src/Http/Exception/ExpectationFailedHttpException.php similarity index 100% rename from Http/Exception/ExpectationFailedHttpException.php rename to src/Http/Exception/ExpectationFailedHttpException.php diff --git a/Http/Exception/ForbiddenHttpException.php b/src/Http/Exception/ForbiddenHttpException.php similarity index 100% rename from Http/Exception/ForbiddenHttpException.php rename to src/Http/Exception/ForbiddenHttpException.php diff --git a/Http/Exception/GatewayTimeoutHttpException.php b/src/Http/Exception/GatewayTimeoutHttpException.php similarity index 100% rename from Http/Exception/GatewayTimeoutHttpException.php rename to src/Http/Exception/GatewayTimeoutHttpException.php diff --git a/Http/Exception/HostNotFoundException.php b/src/Http/Exception/HostNotFoundException.php similarity index 100% rename from Http/Exception/HostNotFoundException.php rename to src/Http/Exception/HostNotFoundException.php diff --git a/Http/Exception/HttpVersionNotSupportedHttpException.php b/src/Http/Exception/HttpVersionNotSupportedHttpException.php similarity index 100% rename from Http/Exception/HttpVersionNotSupportedHttpException.php rename to src/Http/Exception/HttpVersionNotSupportedHttpException.php diff --git a/Http/Exception/InternalServerErrorHttpException.php b/src/Http/Exception/InternalServerErrorHttpException.php similarity index 100% rename from Http/Exception/InternalServerErrorHttpException.php rename to src/Http/Exception/InternalServerErrorHttpException.php diff --git a/Http/Exception/InvalidResponseBodyException.php b/src/Http/Exception/InvalidResponseBodyException.php similarity index 100% rename from Http/Exception/InvalidResponseBodyException.php rename to src/Http/Exception/InvalidResponseBodyException.php diff --git a/Http/Exception/NotImplementedHttpException.php b/src/Http/Exception/NotImplementedHttpException.php similarity index 100% rename from Http/Exception/NotImplementedHttpException.php rename to src/Http/Exception/NotImplementedHttpException.php diff --git a/Http/Exception/ProxyAuthenticationRequiredHttpException.php b/src/Http/Exception/ProxyAuthenticationRequiredHttpException.php similarity index 100% rename from Http/Exception/ProxyAuthenticationRequiredHttpException.php rename to src/Http/Exception/ProxyAuthenticationRequiredHttpException.php diff --git a/Http/Exception/RequestEntityTooLargeHttpException.php b/src/Http/Exception/RequestEntityTooLargeHttpException.php similarity index 100% rename from Http/Exception/RequestEntityTooLargeHttpException.php rename to src/Http/Exception/RequestEntityTooLargeHttpException.php diff --git a/Http/Exception/RequestException.php b/src/Http/Exception/RequestException.php similarity index 100% rename from Http/Exception/RequestException.php rename to src/Http/Exception/RequestException.php diff --git a/Http/Exception/RequestNotSentException.php b/src/Http/Exception/RequestNotSentException.php similarity index 100% rename from Http/Exception/RequestNotSentException.php rename to src/Http/Exception/RequestNotSentException.php diff --git a/Http/Exception/RequestTimeoutHttpException.php b/src/Http/Exception/RequestTimeoutHttpException.php similarity index 100% rename from Http/Exception/RequestTimeoutHttpException.php rename to src/Http/Exception/RequestTimeoutHttpException.php diff --git a/Http/Exception/RequestUriTooLongHttpException.php b/src/Http/Exception/RequestUriTooLongHttpException.php similarity index 100% rename from Http/Exception/RequestUriTooLongHttpException.php rename to src/Http/Exception/RequestUriTooLongHttpException.php diff --git a/Http/Exception/RequestedRangeNotSatisfiableHttpException.php b/src/Http/Exception/RequestedRangeNotSatisfiableHttpException.php similarity index 100% rename from Http/Exception/RequestedRangeNotSatisfiableHttpException.php rename to src/Http/Exception/RequestedRangeNotSatisfiableHttpException.php diff --git a/Http/Exception/ResponseException.php b/src/Http/Exception/ResponseException.php similarity index 100% rename from Http/Exception/ResponseException.php rename to src/Http/Exception/ResponseException.php diff --git a/Http/Exception/ServerErrorHttpException.php b/src/Http/Exception/ServerErrorHttpException.php similarity index 100% rename from Http/Exception/ServerErrorHttpException.php rename to src/Http/Exception/ServerErrorHttpException.php diff --git a/Http/Exception/SslException.php b/src/Http/Exception/SslException.php similarity index 100% rename from Http/Exception/SslException.php rename to src/Http/Exception/SslException.php diff --git a/Http/Exception/TimeoutException.php b/src/Http/Exception/TimeoutException.php similarity index 100% rename from Http/Exception/TimeoutException.php rename to src/Http/Exception/TimeoutException.php diff --git a/Http/Exception/TransportException.php b/src/Http/Exception/TransportException.php similarity index 100% rename from Http/Exception/TransportException.php rename to src/Http/Exception/TransportException.php diff --git a/Http/Exception/UnknownTransportException.php b/src/Http/Exception/UnknownTransportException.php similarity index 100% rename from Http/Exception/UnknownTransportException.php rename to src/Http/Exception/UnknownTransportException.php diff --git a/Http/Kernel.php b/src/Http/Kernel.php similarity index 98% rename from Http/Kernel.php rename to src/Http/Kernel.php index d32b107..5d54224 100644 --- a/Http/Kernel.php +++ b/src/Http/Kernel.php @@ -9,6 +9,7 @@ namespace evaisse\SimpleHttpBundle\Http; +use evaisse\SimpleHttpBundle\Curl\Collector\HeaderCollector; use evaisse\SimpleHttpBundle\Http\Exception\CurlTransportException; use evaisse\SimpleHttpBundle\Http\Exception\HostNotFoundException; use evaisse\SimpleHttpBundle\Http\Exception\ClientErrorHttpException; @@ -124,6 +125,11 @@ public function handleMultiInfoEvent(MultiInfoEvent $e) $stmt = $value[0]; $request = $stmt->getRequest(); + /** + * @var HeaderCollector $headersCollector + * @var ContentCollector $contentCollector + * @var CurlRequest $curlRequest + */ list($curlRequest, $contentCollector, $headersCollector) = $value[1]; $this->updateRequestHeadersFromCurlInfos($request, $e->getRequest()->getInfo()); @@ -164,7 +170,7 @@ public function handleMultiInfoEvent(MultiInfoEvent $e) $response->setStatusCode($headersCollector->getCode(), $headersCollector->getMessage()); $response->setTransferInfos(array_merge($e->getRequest()->getInfo(), [ - 'additionnalProxyHeaders' => $headersCollector->getTransactionHeaders() + 'allHeaders' => $headersCollector->getAllTransactionHeaders() ])); $event = new Event\FilterResponseEvent($this, $request, $requestType, $response); diff --git a/Http/Kernel/RemoteHttpKernel.php b/src/Http/Kernel/RemoteHttpKernel.php similarity index 100% rename from Http/Kernel/RemoteHttpKernel.php rename to src/Http/Kernel/RemoteHttpKernel.php diff --git a/Http/ReadOnlyCookieJar.php b/src/Http/ReadOnlyCookieJar.php similarity index 100% rename from Http/ReadOnlyCookieJar.php rename to src/Http/ReadOnlyCookieJar.php diff --git a/Http/Request.php b/src/Http/Request.php similarity index 100% rename from Http/Request.php rename to src/Http/Request.php diff --git a/Http/Response.php b/src/Http/Response.php similarity index 99% rename from Http/Response.php rename to src/Http/Response.php index 0d77899..7b2efb6 100644 --- a/Http/Response.php +++ b/src/Http/Response.php @@ -2,8 +2,6 @@ namespace evaisse\SimpleHttpBundle\Http; - - use evaisse\SimpleHttpBundle\Http\Exception\ErrorHttpException; use evaisse\SimpleHttpBundle\Http\Exception\InvalidResponseBodyException; diff --git a/Http/SessionCookieJar.php b/src/Http/SessionCookieJar.php similarity index 100% rename from Http/SessionCookieJar.php rename to src/Http/SessionCookieJar.php diff --git a/Http/Statement.php b/src/Http/Statement.php similarity index 99% rename from Http/Statement.php rename to src/Http/Statement.php index 02a4ec7..2fa0534 100644 --- a/Http/Statement.php +++ b/src/Http/Statement.php @@ -9,7 +9,6 @@ */ namespace evaisse\SimpleHttpBundle\Http; - use evaisse\SimpleHttpBundle\Http\Exception\RequestNotSentException; use React\Promise\Deferred; use React\Promise\Promise; @@ -37,7 +36,7 @@ class Statement /** * $error : Error * - * @var Error + * @var \Error * @access protected */ protected $error; @@ -48,6 +47,11 @@ class Statement */ protected $response; + /** + * @var Response[] + */ + protected $responses = []; + /** * @var Promise A Deferred object */ diff --git a/Http/StatementEvents.php b/src/Http/StatementEvents.php similarity index 100% rename from Http/StatementEvents.php rename to src/Http/StatementEvents.php diff --git a/Resources/config/routing.yml b/src/Resources/config/routing.yml similarity index 100% rename from Resources/config/routing.yml rename to src/Resources/config/routing.yml diff --git a/Resources/config/services.yml b/src/Resources/config/services.yml similarity index 100% rename from Resources/config/services.yml rename to src/Resources/config/services.yml diff --git a/Resources/doc/index.rst b/src/Resources/doc/index.rst similarity index 100% rename from Resources/doc/index.rst rename to src/Resources/doc/index.rst diff --git a/Resources/doc/profiler-panels.png b/src/Resources/doc/profiler-panels.png similarity index 100% rename from Resources/doc/profiler-panels.png rename to src/Resources/doc/profiler-panels.png diff --git a/Resources/doc/profiler-timeline.png b/src/Resources/doc/profiler-timeline.png similarity index 100% rename from Resources/doc/profiler-timeline.png rename to src/Resources/doc/profiler-timeline.png diff --git a/Resources/doc/profiler-toolbar.png b/src/Resources/doc/profiler-toolbar.png similarity index 100% rename from Resources/doc/profiler-toolbar.png rename to src/Resources/doc/profiler-toolbar.png diff --git a/Resources/public/libs/highlightjs/highlightjs-8.5.css b/src/Resources/public/libs/highlightjs/highlightjs-8.5.css similarity index 100% rename from Resources/public/libs/highlightjs/highlightjs-8.5.css rename to src/Resources/public/libs/highlightjs/highlightjs-8.5.css diff --git a/Resources/public/libs/highlightjs/highlightjs-8.5.js b/src/Resources/public/libs/highlightjs/highlightjs-8.5.js similarity index 100% rename from Resources/public/libs/highlightjs/highlightjs-8.5.js rename to src/Resources/public/libs/highlightjs/highlightjs-8.5.js diff --git a/Resources/public/libs/jquery/jquery-1.12.1.js b/src/Resources/public/libs/jquery/jquery-1.12.1.js similarity index 100% rename from Resources/public/libs/jquery/jquery-1.12.1.js rename to src/Resources/public/libs/jquery/jquery-1.12.1.js diff --git a/Resources/public/simple-http-bundle.css b/src/Resources/public/simple-http-bundle.css similarity index 100% rename from Resources/public/simple-http-bundle.css rename to src/Resources/public/simple-http-bundle.css diff --git a/Resources/public/simple-http-bundle.js b/src/Resources/public/simple-http-bundle.js similarity index 100% rename from Resources/public/simple-http-bundle.js rename to src/Resources/public/simple-http-bundle.js diff --git a/Resources/translations/messages.fr.xlf b/src/Resources/translations/messages.fr.xlf similarity index 100% rename from Resources/translations/messages.fr.xlf rename to src/Resources/translations/messages.fr.xlf diff --git a/Resources/views/Assets/dollardom/dollardom.min.0.9.2b.js b/src/Resources/views/Assets/dollardom/dollardom.min.0.9.2b.js similarity index 100% rename from Resources/views/Assets/dollardom/dollardom.min.0.9.2b.js rename to src/Resources/views/Assets/dollardom/dollardom.min.0.9.2b.js diff --git a/Resources/views/Assets/highlightjs/highlightjs-8.5.css b/src/Resources/views/Assets/highlightjs/highlightjs-8.5.css similarity index 100% rename from Resources/views/Assets/highlightjs/highlightjs-8.5.css rename to src/Resources/views/Assets/highlightjs/highlightjs-8.5.css diff --git a/Resources/views/Assets/highlightjs/highlightjs-8.5.js b/src/Resources/views/Assets/highlightjs/highlightjs-8.5.js similarity index 100% rename from Resources/views/Assets/highlightjs/highlightjs-8.5.js rename to src/Resources/views/Assets/highlightjs/highlightjs-8.5.js diff --git a/Resources/views/Collector/partials/auth.html.twig b/src/Resources/views/Collector/partials/auth.html.twig similarity index 100% rename from Resources/views/Collector/partials/auth.html.twig rename to src/Resources/views/Collector/partials/auth.html.twig diff --git a/Resources/views/Collector/partials/call.html.twig b/src/Resources/views/Collector/partials/call.html.twig similarity index 100% rename from Resources/views/Collector/partials/call.html.twig rename to src/Resources/views/Collector/partials/call.html.twig diff --git a/Resources/views/Collector/partials/cookies.html.twig b/src/Resources/views/Collector/partials/cookies.html.twig similarity index 100% rename from Resources/views/Collector/partials/cookies.html.twig rename to src/Resources/views/Collector/partials/cookies.html.twig diff --git a/Resources/views/Collector/partials/data.html.twig b/src/Resources/views/Collector/partials/data.html.twig similarity index 100% rename from Resources/views/Collector/partials/data.html.twig rename to src/Resources/views/Collector/partials/data.html.twig diff --git a/Resources/views/Collector/partials/error.html.twig b/src/Resources/views/Collector/partials/error.html.twig similarity index 100% rename from Resources/views/Collector/partials/error.html.twig rename to src/Resources/views/Collector/partials/error.html.twig diff --git a/Resources/views/Collector/partials/javascript.html.twig b/src/Resources/views/Collector/partials/javascript.html.twig similarity index 100% rename from Resources/views/Collector/partials/javascript.html.twig rename to src/Resources/views/Collector/partials/javascript.html.twig diff --git a/Resources/views/Collector/partials/request.html.twig b/src/Resources/views/Collector/partials/request.html.twig similarity index 100% rename from Resources/views/Collector/partials/request.html.twig rename to src/Resources/views/Collector/partials/request.html.twig diff --git a/Resources/views/Collector/partials/response.html.twig b/src/Resources/views/Collector/partials/response.html.twig similarity index 100% rename from Resources/views/Collector/partials/response.html.twig rename to src/Resources/views/Collector/partials/response.html.twig diff --git a/Resources/views/Collector/partials/summary.html.twig b/src/Resources/views/Collector/partials/summary.html.twig similarity index 100% rename from Resources/views/Collector/partials/summary.html.twig rename to src/Resources/views/Collector/partials/summary.html.twig diff --git a/Resources/views/Collector/profiler.html.twig b/src/Resources/views/Collector/profiler.html.twig similarity index 100% rename from Resources/views/Collector/profiler.html.twig rename to src/Resources/views/Collector/profiler.html.twig diff --git a/Serializer/CustomGetSetNormalizer.php b/src/Serializer/CustomGetSetNormalizer.php similarity index 100% rename from Serializer/CustomGetSetNormalizer.php rename to src/Serializer/CustomGetSetNormalizer.php diff --git a/Service/Helper.php b/src/Service/Helper.php similarity index 100% rename from Service/Helper.php rename to src/Service/Helper.php diff --git a/Twig/Extension.php b/src/Twig/Extension.php similarity index 100% rename from Twig/Extension.php rename to src/Twig/Extension.php diff --git a/Tests/Fixtures/greenimg.jpg b/tests/Fixtures/greenimg.jpg similarity index 100% rename from Tests/Fixtures/greenimg.jpg rename to tests/Fixtures/greenimg.jpg diff --git a/Tests/Unit/AbstractTests.php b/tests/Unit/AbstractTests.php similarity index 100% rename from Tests/Unit/AbstractTests.php rename to tests/Unit/AbstractTests.php diff --git a/Tests/Unit/ContainerTest.php b/tests/Unit/ContainerTest.php similarity index 100% rename from Tests/Unit/ContainerTest.php rename to tests/Unit/ContainerTest.php diff --git a/Tests/Unit/ContentTypesTest.php b/tests/Unit/ContentTypesTest.php similarity index 100% rename from Tests/Unit/ContentTypesTest.php rename to tests/Unit/ContentTypesTest.php diff --git a/Tests/Unit/CookieSessionTest.php b/tests/Unit/CookieSessionTest.php similarity index 93% rename from Tests/Unit/CookieSessionTest.php rename to tests/Unit/CookieSessionTest.php index b086553..8274737 100644 --- a/Tests/Unit/CookieSessionTest.php +++ b/tests/Unit/CookieSessionTest.php @@ -13,6 +13,7 @@ use evaisse\SimpleHttpBundle\Http\Request; use evaisse\SimpleHttpBundle\Http\Statement; use evaisse\SimpleHttpBundle\Service\Helper; +use Psr\Container\ContainerInterface; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; use Symfony\Component\DependencyInjection\Container; @@ -24,6 +25,11 @@ class CookieSessionTest extends AbstractTests public function testCookieStore() { + /** + * @var Kernel $httpKernel + * @var Helper $helper + * @var ContainerInterface $container + */ list($helper, $httpKernel, $container) = $this->createContext(); $i = (int)rand(0,100); @@ -48,7 +54,6 @@ public function testCookieStore() $this->assertEquals($cookies['tmp'], 1); - /* * Set and delete some async */ diff --git a/Tests/Unit/CurlExceptionTest.php b/tests/Unit/CurlExceptionTest.php similarity index 100% rename from Tests/Unit/CurlExceptionTest.php rename to tests/Unit/CurlExceptionTest.php diff --git a/Tests/Unit/CurlRequestGeneratorTest.php b/tests/Unit/CurlRequestGeneratorTest.php similarity index 100% rename from Tests/Unit/CurlRequestGeneratorTest.php rename to tests/Unit/CurlRequestGeneratorTest.php diff --git a/Tests/Unit/ExceptionsTest.php b/tests/Unit/ExceptionsTest.php similarity index 100% rename from Tests/Unit/ExceptionsTest.php rename to tests/Unit/ExceptionsTest.php diff --git a/Tests/Unit/FacadeTest.php b/tests/Unit/FacadeTest.php similarity index 100% rename from Tests/Unit/FacadeTest.php rename to tests/Unit/FacadeTest.php diff --git a/Tests/Unit/FileUploadsTest.php b/tests/Unit/FileUploadsTest.php similarity index 100% rename from Tests/Unit/FileUploadsTest.php rename to tests/Unit/FileUploadsTest.php diff --git a/tests/Unit/HeaderCollectorTest.php b/tests/Unit/HeaderCollectorTest.php new file mode 100644 index 0000000..66bac98 --- /dev/null +++ b/tests/Unit/HeaderCollectorTest.php @@ -0,0 +1,135 @@ +collect(null, $h); + } + $this->assertEquals(null, $collector->getCode()); + $this->assertEquals(null, $collector->getMessage()); + $this->assertEquals(null, $collector->getVersion()); + } + + public function testHttpHeaderParsing() + { + $collector = new HeaderCollector(); + $headers = [ + "HTTP/1.1 200 Ok", + "HTTP/1.1 200 Ok", + "X-Debug: foo/http/", + "User-Agent: blablablab", + ]; + foreach ($headers as $h) { + $collector->collect(null, $h); + } + + $this->assertEquals(200, $collector->getCode()); + $this->assertEquals("Ok", $collector->getMessage()); + $this->assertEquals("1.1", $collector->getVersion()); + } + + /** + * test em + */ + public function testHttpEmptyStatusHeaderParsing() + { + $collector = new HeaderCollector(); + $headers = [ + "HTTP/1.1 100 Continue", + "", + "HTTP/1.1 200 Ok", + "X-Debug: foo/http/", + "User-Agent: blablablab", + ]; + + foreach ($headers as $h) { + $collector->collect(null, $h); + } + + $this->assertEquals(200, $collector->getCode()); + $this->assertEquals("Ok", $collector->getMessage()); + $this->assertEquals("1.1", $collector->getVersion()); + + } + + public function testbadCookieHeaderParsing() + { + $collector = new HeaderCollector(); + $headers = [ + "HTTP/1.1 100 Continue", + "", + "HTTP/1.1 200 Ok", + "", + "X-Debug: foo/http/", + "HTTP/1.1 302 Found", + "X-Debug: foo/http/", + "User-Agent: blablablab", + "Set-Cookie: blabla", + ]; + + foreach ($headers as $h) { + $collector->collect(null, $h); + } + + $this->assertEquals(302, $collector->getCode()); + $this->assertEquals("Found", $collector->getMessage()); + $this->assertEquals("1.1", $collector->getVersion()); + $this->assertEquals([ + "X-Debug" => "foo/http/", + "User-Agent" => "blablablab", + ], $collector->getHeaders()); + $this->assertCount(0, $collector->getCookies()); + } + + + public function testCookieHeaderParsing() + { + + $collector = new HeaderCollector(); + $headers = [ + "HTTP/1.1 100 Continue", + "", + "HTTP/1.1 200 Ok", + "X-Debug: foo/http/", + "X-Debug: foo/http/", + "HTTP/1.1 302 Found", + "X-Debug: foo/http/", + "User-Agent: blablablab", + "Set-Cookie: blabla=1", + ]; + + foreach ($headers as $h) { + $collector->collect(null, $h); + } + + $this->assertEquals(302, $collector->getCode()); + $this->assertEquals("Found", $collector->getMessage()); + $this->assertEquals("1.1", $collector->getVersion()); + $this->assertEquals([ + "X-Debug" => "foo/http/", + "User-Agent" => "blablablab", + ], $collector->getHeaders()); + $this->assertCount(1, $collector->getCookies()); + } + +} \ No newline at end of file diff --git a/Tests/Unit/HeaderManipulationTest.php b/tests/Unit/HeaderManipulationTest.php similarity index 100% rename from Tests/Unit/HeaderManipulationTest.php rename to tests/Unit/HeaderManipulationTest.php diff --git a/Tests/Unit/KernelTests.php b/tests/Unit/KernelTests.php similarity index 100% rename from Tests/Unit/KernelTests.php rename to tests/Unit/KernelTests.php diff --git a/Tests/Unit/OAuthClientTest.php b/tests/Unit/OAuthClientTest.php similarity index 100% rename from Tests/Unit/OAuthClientTest.php rename to tests/Unit/OAuthClientTest.php diff --git a/Tests/Unit/ParrallelExecutionTest.php b/tests/Unit/ParrallelExecutionTest.php similarity index 100% rename from Tests/Unit/ParrallelExecutionTest.php rename to tests/Unit/ParrallelExecutionTest.php diff --git a/Tests/Unit/PromisesTest.php b/tests/Unit/PromisesTest.php similarity index 100% rename from Tests/Unit/PromisesTest.php rename to tests/Unit/PromisesTest.php diff --git a/Tests/Unit/RequestBodyTest.php b/tests/Unit/RequestBodyTest.php similarity index 100% rename from Tests/Unit/RequestBodyTest.php rename to tests/Unit/RequestBodyTest.php diff --git a/Tests/Unit/ReturnCodeTest.php b/tests/Unit/ReturnCodeTest.php similarity index 100% rename from Tests/Unit/ReturnCodeTest.php rename to tests/Unit/ReturnCodeTest.php diff --git a/Tests/Unit/SimpleRoutingTest.php b/tests/Unit/SimpleRoutingTest.php similarity index 100% rename from Tests/Unit/SimpleRoutingTest.php rename to tests/Unit/SimpleRoutingTest.php diff --git a/Tests/Unit/SslTest.php b/tests/Unit/SslTest.php similarity index 100% rename from Tests/Unit/SslTest.php rename to tests/Unit/SslTest.php diff --git a/Tests/Unit/TimeoutTest.php b/tests/Unit/TimeoutTest.php similarity index 100% rename from Tests/Unit/TimeoutTest.php rename to tests/Unit/TimeoutTest.php diff --git a/Tests/autoload.php.dist b/tests/autoload.php.dist similarity index 100% rename from Tests/autoload.php.dist rename to tests/autoload.php.dist