From b834017fbeb65b9f0cdb92c19b07becf71aa3365 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Sun, 3 Jul 2016 16:10:54 +0200 Subject: [PATCH 1/3] Added a formatter that shows the full header and body of the HTTP message --- src/Formatter/FullHttpMessageFormatter.php | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/Formatter/FullHttpMessageFormatter.php diff --git a/src/Formatter/FullHttpMessageFormatter.php b/src/Formatter/FullHttpMessageFormatter.php new file mode 100644 index 0000000..2560466 --- /dev/null +++ b/src/Formatter/FullHttpMessageFormatter.php @@ -0,0 +1,72 @@ + + */ +class FullHttpMessageFormatter implements Formatter +{ + /** + * The maximum length of the body. + * + * @var int + */ + private $maxBodyLendth; + + /** + * @param int $maxBodyLendth number of chars. + */ + public function __construct($maxBodyLendth = 1000) + { + $this->maxBodyLendth = $maxBodyLendth; + } + + /** + * {@inheritdoc} + */ + public function formatRequest(RequestInterface $request) + { + $message = sprintf( + "%s %s HTTP/%s\n", + $request->getMethod(), + $request->getRequestTarget(), + $request->getProtocolVersion() + ); + + foreach ($request->getHeaders() as $name => $values) { + $message .= $name.': '.implode(', ', $values)."\n"; + } + + $message .= "\n".mb_substr($request->getBody()->__toString(), 0, $this->maxBodyLendth); + + return $message; + } + + /** + * {@inheritdoc} + */ + public function formatResponse(ResponseInterface $response) + { + $message = sprintf( + "HTTP/%s %s %s\n", + $response->getProtocolVersion(), + $response->getStatusCode(), + $response->getReasonPhrase() + ); + + foreach ($response->getHeaders() as $name => $values) { + $message .= $name.': '.implode(', ', $values)."\n"; + } + + $message .= "\n".mb_substr($response->getBody()->__toString(), 0, $this->maxBodyLendth); + + return $message; + } +} From 7ec5cc9d7ac7bcd99098d17f8b6ff2319b5666af Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Sun, 3 Jul 2016 18:56:08 +0200 Subject: [PATCH 2/3] Added changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab7a8ce..6b3044d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ - #41: Response builder broke header value +### Added + +- The FullHttpMessageFormatter was added ## 1.2.0 - 2016-03-29 From 99d27b41a935596dc321bb4141c11401696a864b Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Sun, 3 Jul 2016 22:28:06 +0200 Subject: [PATCH 3/3] typos --- CHANGELOG.md | 8 ++++---- src/Formatter/FullHttpMessageFormatter.php | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b3044d..dc0b33d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,14 +2,14 @@ ## Unreleased -### Fixed - -- #41: Response builder broke header value - ### Added - The FullHttpMessageFormatter was added +### Fixed + +- #41: Response builder broke header value + ## 1.2.0 - 2016-03-29 ### Added diff --git a/src/Formatter/FullHttpMessageFormatter.php b/src/Formatter/FullHttpMessageFormatter.php index 2560466..0afe38c 100644 --- a/src/Formatter/FullHttpMessageFormatter.php +++ b/src/Formatter/FullHttpMessageFormatter.php @@ -18,14 +18,14 @@ class FullHttpMessageFormatter implements Formatter * * @var int */ - private $maxBodyLendth; + private $maxBodyLength; /** - * @param int $maxBodyLendth number of chars. + * @param int $maxBodyLength */ - public function __construct($maxBodyLendth = 1000) + public function __construct($maxBodyLength = 1000) { - $this->maxBodyLendth = $maxBodyLendth; + $this->maxBodyLength = $maxBodyLength; } /** @@ -44,7 +44,7 @@ public function formatRequest(RequestInterface $request) $message .= $name.': '.implode(', ', $values)."\n"; } - $message .= "\n".mb_substr($request->getBody()->__toString(), 0, $this->maxBodyLendth); + $message .= "\n".mb_substr($request->getBody()->__toString(), 0, $this->maxBodyLength); return $message; } @@ -65,7 +65,7 @@ public function formatResponse(ResponseInterface $response) $message .= $name.': '.implode(', ', $values)."\n"; } - $message .= "\n".mb_substr($response->getBody()->__toString(), 0, $this->maxBodyLendth); + $message .= "\n".mb_substr($response->getBody()->__toString(), 0, $this->maxBodyLength); return $message; }