Skip to content

Conversation

cnlangzi
Copy link
Member

@cnlangzi cnlangzi commented Feb 16, 2025

Changed

Fixed

  • added support to X-Forwarded-Proto in https checking

Added

  • added Deploy section on README.md

Tests

Tasks to complete before merging PR:

  • Ensure unit tests are passing. If not run make unit-test to check for any regressions 📋
  • Ensure lint tests are passing. if not run make lint to check for any issues
  • Ensure codecov/patch is passing for changes.

Summary by Sourcery

Add support for X-Forward-Proto header and document the deployment process. Update the HTTPS checking logic to handle the X-Forward-Proto header, enabling proper identification of HTTPS requests when the application is deployed behind a proxy. Include a new section in the README explaining how to deploy the application using embedded static assets and configuration files for a simplified and portable deployment process.

Bug Fixes:

  • Added support for the X-Forward-Proto header in HTTPS checking logic to correctly identify HTTPS requests behind a proxy.

Documentation:

  • Added a "Deploy" section to the README.md file, explaining how to deploy the application using embedded resources and the //go:embed directive for self-contained binaries.

Copy link

sourcery-ai bot commented Feb 16, 2025

Reviewer's Guide by Sourcery

This pull request adds support for the X-Forwarded-Proto header when checking for HTTPS, updates the request logging to include the port number, adds a deployment section to the README, and fixes a typo. The X-Forwarded-Proto header is now checked in both the HSTS middleware and the request logging to accurately determine if a connection is secure when behind a proxy. A deployment section was added to the README to explain how to deploy the application using the embed package.

Sequence diagram for HTTPS check with X-Forwarded-Proto

sequenceDiagram
    participant Client
    participant Proxy
    participant Server

    Client->>Proxy: GET /resource
    Proxy->>Server: GET /resource X-Forwarded-Proto: https
    Server->>Server: Check r.TLS != nil || r.Header.Get("X-Forwarded-Proto") == "https"
    Server-->>Proxy: Response
    Proxy-->>Client: Response
Loading

Updated class diagram for request logging

classDiagram
    class Context {
        Request
        Response
    }
    class Request {
        +TLS
        +Header
        +Host
        +URL
        +RemoteAddr
    }
    class Header {
        +Get(key string) string
    }

    Context -- Request : has
    Request -- Header : has
    note for Request "Added check for X-Forwarded-Proto"
Loading

Updated class diagram for HSTS middleware

classDiagram
    class Middleware {
        +WriteHeader(opts ...Option) xun.Middleware
    }
    class Context {
        Request
    }
    class Request {
        +TLS
        +Header
        +Method
    }
    class Header {
        +Get(key string) string
    }

    Middleware -- Context : uses
    Context -- Request : has
    Request -- Header : has
    note for Request "Added check for X-Forwarded-Proto"
Loading

File-Level Changes

Change Details Files
Added support for the X-Forwarded-Proto header when determining if a request is HTTPS.
  • Added a function IsHTTPs to check if a request is HTTPS by checking r.TLS or the X-Forwarded-Proto header.
  • Modified the HSTS middleware to use the IsHTTPs function to determine if the connection is secure.
  • Modified the request logging to use the IsHTTPs function to determine the port to use when logging the host.
ext/reqlog/format.go
ext/hsts/hsts.go
Added a section to the README.md file detailing how to deploy the application using the embed package.
  • Added a Deploy your application section to the README.
  • Added example code demonstrating how to use //go:embed and fs.FS to embed static assets and configuration files into the application binary.
  • Added example code demonstrating how to switch between using the local filesystem and embedded resources based on a dev flag.
README.md
Modified the request logging to include the port number in the host field.
  • Added logic to include the port number in the host field when logging requests.
  • If the host does not contain a port, the code now appends :443 for HTTPS requests and :80 for HTTP requests.
ext/reqlog/format.go
Corrected a typo in the README.md file.
  • Fixed a typo in the acl.DenyCountries configuration in the README.
README.md
Used c.Response instead of c.Writer() when setting cookies.
  • Changed http.SetCookie(c.Writer(), &cookie) to http.SetCookie(c.Response, &cookie).
README.md

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. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the 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 exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

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

Copy link

deepsource-io bot commented Feb 16, 2025

Here's the code health analysis summary for commits f7e5bca..1903201. View details on DeepSource ↗.

Analysis Summary

AnalyzerStatusSummaryLink
DeepSource Go LogoGo✅ SuccessView Check ↗

💡 If you’re a repository administrator, you can configure the quality gates from the settings.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @cnlangzi - I've reviewed your changes - here's some feedback:

Overall Comments:

  • The added Deploy section in README.md looks good, but consider adding a brief explanation of the benefits of embedding assets.
  • The changes to ext/reqlog/format.go and ext/hsts/hsts.go look good, but consider adding a comment explaining why the port is hardcoded to 80/443.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link

codecov bot commented Feb 16, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.00%. Comparing base (f7e5bca) to head (1903201).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #49      +/-   ##
==========================================
+ Coverage   93.98%   94.00%   +0.01%     
==========================================
  Files          54       54              
  Lines        2196     2203       +7     
==========================================
+ Hits         2064     2071       +7     
  Misses         98       98              
  Partials       34       34              
Flag Coverage Δ
Unit-Tests 94.00% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cnlangzi cnlangzi changed the title fix(ext): added support to X-Forward-Proto in https checking fix(ext): added support to X-Forwarded-Proto in https checking Feb 16, 2025
@cnlangzi cnlangzi merged commit 642af94 into main Feb 16, 2025
7 checks passed
@cnlangzi cnlangzi deleted the chore/deploy branch February 16, 2025 05:21
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.

1 participant