Skip to content

Commit

Permalink
Add readme, license and some tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
danielkurecka committed May 6, 2020
1 parent 4097f24 commit 10013af
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 6 deletions.
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2020 Daniel Kurečka

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Nette Bluescreen for Guzzle
This extension adds a new panel to Tracy Bluescreen for Guzzle HTTP client.

When Guzzle exception occures, it will log full request/response body and headers.
It will also pretty print the body when the content type is application/json.

[![Nette Guzzle Bluescreen](https://danielkurecka.github.io/nette-guzzle-bluescreen/guzzle-bluescreen.png)](https://danielkurecka.github.io/nette-guzzle-bluescreen/guzzle-bluescreen.png)

# Installation
`composer require daku/nette-guzzle-bluescreen`

## Usage
Register the extension in config.neon:
```neon
extensions:
guzzleBluescreen: Daku\Nette\Guzzle\GuzzleBlueScreenExtension
```

## Configuration
```neon
guzzleBluescreen:
# Set maximum body length (in kB) that will be logged, if exceeded the body will be truncted. Default is 100 kB.
maxBodyLength: 200
# Enable/disable pretty print of json responses. Default is true.
prettyPrint: false
```

## Requirements
PHP >= 7.1\
Nette >= 2.4
10 changes: 10 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
{
"name": "daku/nette-guzzle-bluescreen",
"type": "library",
"description": "This extension adds a new panel to Tracy Bluescreen for Guzzle. ",
"keywords": ["nette", "tracy-panel", "guzzle"],

"license": "MIT",
"authors": [
{
"name": "Daniel Kurečka",
"email": "[email protected]"
}
],

"require": {
"php": ">=7.1.0",
Expand Down
10 changes: 6 additions & 4 deletions src/GuzzleBlueScreenExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
class GuzzleBlueScreenExtension extends CompilerExtension
{

/** @var int The maximum body length that will be logged, if exceeded it will be truncted. */
public static $maxBodyLength = 100 * 1024;
/** @var int Max body lenght in kB, if exceeded it will be truncated. */
public static $maxBodyLength = 100;

public static $prettyPrint = true;

Expand Down Expand Up @@ -84,10 +84,12 @@ public static function formatBody(?MessageInterface $message)

} else {
$body->rewind();
$maxLength = self::$maxBodyLength * 1024;

if ($body->getSize() > self::$maxBodyLength) {
$content = $body->read(self::$maxBodyLength);
if ($body->getSize() > $maxLength) {
$content = $body->read($maxLength);
$truncated = true;

} else {
$content = $body->getContents();
}
Expand Down
4 changes: 2 additions & 2 deletions tests/testApp/app/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ extensions:
guzzleBluescreen: Daku\Nette\Guzzle\GuzzleBlueScreenExtension

guzzleBluescreen:
# maxBodyLength: 20
# prettyPrint: true
# maxBodyLength: 0.1
# prettyPrint: false

0 comments on commit 10013af

Please sign in to comment.