Skip to content

Conversation

@nasrulhazim
Copy link

Description

This PR adds a new HttpCollector data collector that provides comprehensive tracking of HTTP requests and responses in Laravel Debugbar.

Changes

New Files

  • src/DataCollector/HttpCollector.php - Main collector class
  • tests/DataCollector/HttpCollectorTest.php - Complete test coverage

Features

The HttpCollector provides detailed insights into HTTP requests and responses:

Request Information

  • Full URI, HTTP method, and controller action
  • Route middleware information
  • Request headers (with configurable hidden parameters for security)
  • Request payload including file uploads
  • Session variables

Response Information

  • HTTP status codes
  • JSON response parsing and formatting
  • Plain text response handling
  • Redirect URL detection
  • View responses with extracted data
  • HTML response indication

Performance Metrics

  • Request duration calculation from LARAVEL_START
  • Peak memory usage tracking

Security & Privacy

  • Configurable hidden request headers (e.g., Authorization, API keys)
  • Configurable hidden request parameters (e.g., password, token)
  • Configurable hidden response parameters
  • Configurable ignored status codes
  • Content size limits to prevent memory issues

Model Formatting

  • Eloquent model detection and formatting
  • Extracts model class, primary key, attributes, and relations
  • Handles nested relationships

Configuration

The collector supports the following constructor parameters:

new HttpCollector(
    request: $request,
    response: $response,
    startTime: LARAVEL_START,
    hiddenRequestHeaders: ['authorization', 'php-auth-pw'],
    hiddenParameters: ['password', 'password_confirmation'],
    hiddenResponseParameters: ['token', 'api_key'],
    ignoredStatusCodes: [404],
    sizeLimit: 64 // KB
)

@parallels999
Copy link
Contributor

Wouldn't it be better to improve/complete RequestCollector.php, It already has a lot of the same information

$data['session_attributes'] = $this->session->all();

$data += [
'response' => $response->headers->get('Content-Type') ? $response->headers->get(
'Content-Type'
) : 'text/html',
'request_format' => $request->getRequestFormat(),
'request_query' => $request->query->all(),
'request_request' => $request->request->all(),
'request_headers' => $request->headers->all(),
'request_cookies' => $request->cookies->all(),
'response_headers' => $responseHeaders,
];

@barryvdh
Copy link
Owner

What is the difference with the regular collector? This collector is not registred automatically, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants