Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from caddyserver:master #29

Merged
merged 1 commit into from
Jan 2, 2025

Conversation

pull[bot]
Copy link

@pull pull bot commented Jan 2, 2025

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.1)

Can you help keep this open source service alive? 💖 Please sponsor : )

Summary by Sourcery

Bug Fixes:

  • Fix an issue where requests to PHP-FPM over FastCGI would hang if the request body contained data and the Content-Length header was not set correctly.

* buffer requests for fastcgi by default

* fix import cycle

* fix the return value of bufferedBody

* more comments about fastcgi buffering

---------

Co-authored-by: Matt Holt <[email protected]>
@pull pull bot added the ⤵️ pull label Jan 2, 2025
@pull pull bot merged commit 1bd567d into mr-narender:master Jan 2, 2025
Copy link

sourcery-ai bot commented Jan 2, 2025

Reviewer's Guide by Sourcery

This PR introduces a change in the reverse proxy handler to enable request buffering for FastCGI if it is not explicitly configured. It also includes a minor update to the bufferedBody function to handle cases where the body size exceeds the specified limit.

Sequence diagram for FastCGI request buffering flow

sequenceDiagram
    participant Client
    participant ReverseProxy
    participant FastCGI
    participant PHP_FPM

    Client->>ReverseProxy: HTTP Request
    Note over ReverseProxy: Check if transport is FastCGI
    Note over ReverseProxy: Enable request buffering
    Note over ReverseProxy: Buffer size = 4096
    ReverseProxy->>FastCGI: Buffered Request
    FastCGI->>PHP_FPM: Request with Content-Length
    PHP_FPM-->>FastCGI: Response
    FastCGI-->>ReverseProxy: Response
    ReverseProxy-->>Client: HTTP Response
Loading

Class diagram for Handler modifications

classDiagram
    class Handler {
        +Transport http.RoundTripper
        +RequestBuffers int
        +Provision(ctx caddy.Context) error
        +bufferedBody(originalBody io.ReadCloser, limit int64) (io.ReadCloser, int64)
    }
    note for Handler "Added automatic request buffering for FastCGI"

    class bodyReadCloser {
        +Reader io.Reader
        +buf *bytes.Buffer
        +body io.ReadCloser
    }
Loading

File-Level Changes

Change Details Files
Enable request buffering for FastCGI by default. modules/caddyhttp/reverseproxy/reverseproxy.go
Update error handling in bufferedBody function.
  • Modified the io.CopyN logic to handle potential errors and cases where the number of bytes read reaches the specified limit.
  • Changed the return value of the function to include the number of bytes written to the buffer.
  • Updated the error handling to account for the possibility of partial reads when the body size exceeds the limit.
  • Added a variable written to track the number of bytes written to the buffer and use it in the return and conditional checks for clarity and correctness.
modules/caddyhttp/reverseproxy/reverseproxy.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

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

Successfully merging this pull request may close these issues.

1 participant