定制 jhoffland/guzzle-formatter 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jhoffland/guzzle-formatter

Composer 安装命令:

composer require jhoffland/guzzle-formatter

包简介

PHP Guzzle request/response to HTTP message formatter

README 文档

README

Tests status StyleCI status

PHP library for formatting Guzzle requests and responses to HTTP messages.

Installation

Latest stable version Total downloads

Install this library directly with Composer:

composer require jhoffland/guzzle-formatter

Add --dev if this library is not needed in a production environment.

Usage

use GuzzleFormatter\RequestFormatter;
use GuzzleFormatter\ResponseFormatter;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;

$request = new Request('GET', 'https://github.com/jhoffland/guzzle-formatter');
echo (new RequestFormatter())->http($request); // Results in the formatted HTTP request message.

$response = (new Client())->send($request);
echo (new ResponseFormatter())->http($response); // Results in the formatted HTTP response message.

Using middleware

Logging all requests performed and/or responses received by a Guzzle client, using middleware.

The HTTP request and/or response messages are written to the file, specified when creating the HttpFormatterMiddleware class instance.

use GuzzleFormatter\Middleware\HttpFormatterMiddleware;
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;

$formatterMiddleware = new HttpFormatterMiddleware('/path/to/output-file.txt');

$handlerStack = HandlerStack::create();

$handlerStack->after('prepare_body', $formatterMiddleware->requests(), 'http_request_formatter');
$handlerStack->after('prepare_body', $formatterMiddleware->responses(), 'http_response_formatter');

$client = new Client([
    'handler' => $handlerStack,
]);
$client->get('https://github.com/jhoffland/guzzle-formatter');

Available options

1. End of Line character

Available when creating an instance of RequestFormatter & ResponseFormatter.

2. Hide sensitive headers

Available for when formatting an HTTP message with RequestFormatter & ResponseFormatter & when creating an instance of HttpFormatterMiddleware.
The headers seen as sensitive can be found in the array Formatter::SENSITIVE_HEADERS.

Supported PHP & package versions

PHP version Guzzle version

This library is tested with PHP 7.4, 8.0 and 8.1.
Check the composer.json file for the supported package versions.

Feel free to add support for additional versions to this library.

Contributing

Feel free to contribute to this library. Contribute by forking the GitHub repository and opening a pull request.
When opening a pull request, please make sure that:

  • The pull request has a clear title;
  • The pull request does not consist of too many (unnecessary/small) commits;
  • The StyleCI analysis pass;
  • The PHPUnit tests pass.

ToDo's

  • Add test for formatting request when making an request to an URL without path (e.g. to https://google.com instead of to https://google.com/).
  • Add test for hiding and not-hiding sensitive headers when using the HttpFormatterMiddleware.
  • Add cURL formatter.

统计信息

  • 总下载量: 259
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 1

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-03-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固