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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/custom headers (issue #169) #323

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

SpencerWightman
Copy link

@SpencerWightman SpencerWightman commented Mar 15, 2024

This PR implements the ability to add custom headers to responses. It follows the steps outlined in #169 except it does not use var EnvVars = map[string]string{ and instead references the .env variable in the config.yaml, because custom headers need a custom key ('apiKey' for example) and this seemed the most straightforward and user-friendly solution. All tests passed and the lint passed.

I'm not sure how to best implement ApplyCustomHeaders in routes.go. Right now the custom headers attach to every response, which does not seem right. Any direction and help finalizing would be much appreciated!


馃殌 This PR description was created by Ellipsis for commit 135b0dd.

Summary:

This PR adds the ability to include custom headers in server responses, defined in config.yaml, and applies them to every response via a new middleware function ApplyCustomHeaders.

Key points:

  • Added CustomHeaders field in ServerConfig struct in config/models.go
  • Defined custom headers in config.yaml
  • Implemented ApplyCustomHeaders function in pkg/server/middleware.go to add custom headers to responses
  • Added ApplyCustomHeaders to middleware stack in pkg/server/routes.go

Generated with 鉂わ笍 by ellipsis.dev

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

馃憤 Looks good to me!

  • Reviewed the entire pull request up to 135b0dd
  • Looked at 91 lines of code in 4 files
  • Took 1 minute and 7 seconds to review
More info
  • Skipped 0 files when reviewing.
  • Skipped posting 2 additional comments because they didn't meet confidence threshold of 50%.
1. pkg/server/routes.go:72:
  • Assessed confidence : 100%
  • Grade: 0%
  • Comment:
    The ApplyCustomHeaders middleware is currently applied to all routes, which may not be appropriate. Consider applying this middleware selectively, based on the specific requirements of each route.
  • Reasoning:
    The PR author has added a new middleware function ApplyCustomHeaders in middleware.go which adds custom headers to the response. This function is then used in routes.go to apply the custom headers to all routes. The author has expressed uncertainty about this approach, as it applies the custom headers to every response, which may not be appropriate. I agree with the author's concern. Custom headers should be applied selectively, based on the specific requirements of each route. Applying them globally could lead to unintended consequences, such as exposing sensitive information on routes where it's not needed.
2. pkg/server/middleware.go:36:
  • Assessed confidence : 100%
  • Grade: 20%
  • Comment:
    There's no error handling for the case where an environment variable is not set or is empty. Consider adding error handling to ensure that the environment variable is set and is not empty.
  • Reasoning:
    The ApplyCustomHeaders function in middleware.go checks if a custom header value starts with 'env:' and if so, it fetches the actual value from the environment variable. However, there's no error handling in case the environment variable is not set. This could lead to unexpected behavior if the environment variable is not set or is empty. It would be better to add error handling to ensure that the environment variable is set and is not empty.

Workflow ID: wflow_ZGmG4RfvBRhFd4Tn


Not what you expected? You can customize the content of the reviews using rules. Learn more here.

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.

None yet

1 participant