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

✨ feat: Add support for CookieConfig in Redirect #3076

Closed
wants to merge 19 commits into from
Closed

Conversation

gaby
Copy link
Member

@gaby gaby commented Jul 16, 2024

Description

  • Added support for CookieConfig in the RedirectConfig struct. This allows the user to fully configure the Cookies used by the Redirect feature.
  • Added support for configuring the cookie name.
  • Added unit-tests for CookieConfig
  • Added Redirect section to the "What's new" document.
  • Update all the sections in the Redirect documentation.

Changes introduced

List the new features or adjustments introduced in this pull request. Provide details on benchmarks, documentation updates, changelog entries, and if applicable, the migration guide.

  • Documentation Update: Detail the updates made to the documentation and links to the changed files.
  • Changelog/What's New: Include a summary of the additions for the upcoming release notes.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • Enhancement (improvement to existing features and functionality)
  • Documentation update (changes to documentation)

@gaby gaby requested a review from a team as a code owner July 16, 2024 02:45
@gaby gaby requested review from sixcolors, ReneWerner87 and efectn and removed request for a team July 16, 2024 02:45
Copy link
Contributor

coderabbitai bot commented Jul 16, 2024

Important

Review skipped

More than 25% of the files skipped due to max files limit. The review is being skipped to prevent a low-quality review.

40 files out of 97 files are above the max files limit of 50. Please upgrade to Pro plan to get higher limits.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The updates streamline the redirect functionality in Fiber, introduce improved cookie configuration, and refine documentation for ease of understanding. Major modifications include adding a CookieConfig to manage cookies during redirection, enhancing test coverage, and refining the Makefile. The documentation now better details redirect methods and includes new features like flash messages and input preservation, ensuring a more robust and user-friendly experience.

Changes

Files Change Summary
Makefile Replaced duplicated format target with markdown target, impacting linting and formatting commands.
docs/api/redirect.md Refined documentation for redirect methods, added examples, and clarified usage of Status, RedirectConfig, Flash Message, and WithInput.
docs/whats_new.md Documented changes in Route chaining, subapp registration, redirect features, static middleware usage, and CORS configuration.
redirect.go Added CookieConfig struct and default configuration, updated Redirect and RedirectConfig structs, and modified methods to handle cookies and flash messages.
redirect_test.go Enhanced test cases with new CookieConfig settings including HttpOnly, Secure, and SameSite attributes.
router.go Updated conditional check within request handling to use values from request redirection configuration.

Poem

In the land of Fiber bright,
Redirects take a smoother flight.
Cookies now with care we set,
Flash messages you won’t forget.
Markdown targets in the fray,
Making work a breezy day.
New features, clear and bold,
A tale of code joyfully told.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Jul 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.08%. Comparing base (58d07f0) to head (acedda3).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3076      +/-   ##
==========================================
- Coverage   83.10%   83.08%   -0.03%     
==========================================
  Files         115      115              
  Lines        8321     8334      +13     
==========================================
+ Hits         6915     6924       +9     
- Misses       1076     1079       +3     
- Partials      330      331       +1     
Flag Coverage Δ
unittests 83.08% <100.00%> (-0.03%) ⬇️

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.

@gaby gaby changed the title v3: Add support for CookieConfig in Redirect ✨ feat: Add support for CookieConfig in Redirect Jul 16, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Outside diff range, codebase verification and nitpick comments (2)
Makefile (1)

32-32: Install and configure markdownlint-cli2

The Makefile includes a target that uses markdownlint-cli2, but there is no evidence of its installation or configuration in the repository. To avoid build failures, please ensure that markdownlint-cli2 is installed and configured correctly.

  • Add markdownlint-cli2 installation steps, for example, in the Makefile or a setup script.
  • Create a .markdownlint.json configuration file if needed.
Analysis chain

Verify the installation and configuration of markdownlint-cli2.

Ensure that markdownlint-cli2 is installed and configured correctly in the development environment to avoid build failures.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if markdownlint-cli2 is installed and configured correctly.

# Test: Search for markdownlint-cli2 installation and configuration.
which markdownlint-cli2
cat .markdownlint.json

Length of output: 174


Script:

#!/bin/bash
# Description: Check if markdownlint-cli2 is listed as a dependency in package.json and search for markdownlint configuration files.

# Search for markdownlint-cli2 in package.json
rg "markdownlint-cli2" package.json

# Search for markdownlint configuration files
fd --type f --name "*.markdownlint*"

Length of output: 378


Script:

#!/bin/bash
# Description: Search for markdownlint configuration files and check for markdownlint-cli2 in Makefile or shell script files.

# Corrected search for markdownlint configuration files
fd --type f ".markdownlint"

# Search for markdownlint-cli2 in Makefile and shell script files
rg "markdownlint-cli2" Makefile
fd --type f -e sh | xargs rg "markdownlint-cli2"

Length of output: 195


Script:

#!/bin/bash
# Description: Search for any scripts or methods that install markdownlint-cli2.

# Search for installation commands in Makefile and shell script files
rg "install" Makefile
fd --type f -e sh | xargs rg "install"

Length of output: 523

docs/api/redirect.md (1)

15-15: Documentation updates are clear and align with code changes.

The updates in the documentation are consistent with the new functionalities introduced in the code, such as the CookieConfig struct and its usage.

Consider simplifying the phrase 'in conjunction with'.

The phrase "in conjunction with" could be simplified to "with" to enhance readability.

- This method is used in conjunction with [**To**](#to), [**Route**](#route) and [**Back**](#back) methods.
+ This method is used with [**To**](#to), [**Route**](#route) and [**Back**](#back) methods.

Also applies to: 18-18, 51-51, 54-54, 92-92, 95-95, 127-127, 143-143, 154-154, 158-158, 160-160, 162-162, 164-164, 166-166, 167-167, 168-168, 186-186, 190-190, 198-198, 205-205, 213-213, 220-220, 228-228, 235-235, 243-243, 250-250, 258-258, 262-262, 269-269, 278-278, 282-282

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 58d07f0 and a19709a.

Files selected for processing (6)
  • Makefile (1 hunks)
  • docs/api/redirect.md (7 hunks)
  • docs/whats_new.md (8 hunks)
  • redirect.go (9 hunks)
  • redirect_test.go (4 hunks)
  • router.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • router.go
Additional context used
LanguageTool
docs/api/redirect.md

[style] ~127-~127: ‘in conjunction with’ might be wordy. Consider a shorter alternative.
Context: ... redirect. :::info This method is used in conjunction with To, Route and ...

(EN_WORDINESS_PREMIUM_IN_CONJUNCTION_WITH)

Additional comments not posted (6)
Makefile (1)

32-32: Change of target from format to markdown is appropriate.

The change aligns with the PR's objectives to enhance the documentation and markdown linting capabilities.

redirect.go (1)

27-33: Structural and functional changes in redirect.go are well-implemented.

The additions and modifications in the Redirect and CookieConfig structs are consistent with the PR's objectives to enhance cookie handling in redirects.

Ensure secure cookie settings when SameSite=None.

The implementation correctly sets the Secure flag when SameSite is set to None. This is crucial for preventing security issues related to cookies.

Also applies to: 44-48, 53-58, 60-65, 75-75, 208-208, 214-216, 218-220, 222-224, 226-231, 233-235, 283-283, 296-296, 328-333

docs/whats_new.md (1)

245-257: Enhancements to the Redirect feature are well-documented.

The documentation clearly outlines the new capabilities related to flash messages, old input data, and customizable HTTP status codes, providing a comprehensive overview of the improvements.

Verify the backend implementation for cookie storage.

Ensure that the backend implementation correctly handles cookie storage as described, particularly the use of CookieConfig in the RedirectConfig struct.

Also applies to: 259-259

Verification successful

Backend implementation for cookie storage is correctly handled.

The redirect.go file contains the necessary implementations for CookieConfig within the RedirectConfig struct, confirming that the backend handles cookie storage as described in the documentation.

  • redirect.go: Multiple references to CookieConfig including default configuration, struct definition, and various assignments and checks.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the backend implementation for cookie storage.

# Test: Search for the implementation of CookieConfig in RedirectConfig.
rg --type go 'CookieConfig' 'redirect.go'

Length of output: 895

redirect_test.go (3)

186-186: Duplicate issue: Ensure consistent cookie string representation in assertions.

This is a repeat of the previous issue where the test checks for two possible string representations of the cookie. As mentioned earlier, consider a robust method for parsing and asserting cookie properties to avoid flakiness.


229-229: Duplicate issue: Ensure consistent cookie string representation in assertions.

Again, this test faces the same issue with potential flakiness due to checking two possible string representations of the cookie. It's crucial to address this across all tests to ensure reliability.


245-302: Review comprehensive test cases for different CookieConfig settings.

The test suite here is well-structured and covers a variety of scenarios for the CookieConfig, which is crucial for ensuring that all configurations behave as expected. However, ensure that the test names and expected values accurately reflect the intended cookie settings, especially regarding security attributes like HttpOnly and Secure.

@@ -45,7 +45,7 @@ func Test_Redirect_To_WithFlashMessages(t *testing.T) {
require.Equal(t, 302, c.Response().StatusCode())
require.Equal(t, "http://example.com", string(c.Response().Header.Peek(HeaderLocation)))

equal := c.GetRespHeader(HeaderSetCookie) == "fiber_flash=success:1,message:test; path=/; SameSite=Lax" || c.GetRespHeader(HeaderSetCookie) == "fiber_flash=message:test,success:1; path=/; SameSite=Lax"
equal := c.GetRespHeader(HeaderSetCookie) == "fiber_flash=success:1,message:test; path=/; HttpOnly; SameSite=Lax" || c.GetRespHeader(HeaderSetCookie) == "fiber_flash=message:test,success:1; path=/; HttpOnly; SameSite=Lax"
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure consistent cookie string representation in assertions.

The test checks for two possible string representations of the cookie, which could lead to flakiness if the order of the cookie attributes isn't guaranteed by the implementation. Consider using a more robust method to parse and assert the properties of the cookie.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a19709a and acedda3.

Files selected for processing (1)
  • redirect_test.go (6 hunks)
Files skipped from review as they are similar to previous changes (1)
  • redirect_test.go

Copy link
Member

@ReneWerner87 ReneWerner87 left a comment

Choose a reason for hiding this comment

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

just 1 minor task

Comment on lines +208 to +234
cfg := RedirectConfig{CookieConfig: CookieConfigDefault}

if len(config) > 0 {
cfg = config[0]
}

if cfg.CookieConfig == (CookieConfig{}) {
cfg.CookieConfig = CookieConfigDefault
}

if cfg.CookieConfig.Name == "" {
cfg.CookieConfig.Name = CookieConfigDefault.Name
}

if cfg.CookieConfig.SameSite == "" {
cfg.CookieConfig.SameSite = CookieConfigDefault.SameSite
}

// RFC6265: If SameSite=None, the Secure attribute must be set
// https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-14#name-storage-model
// Section 5.6.19
if utils.ToLower(cfg.CookieConfig.SameSite) == "none" {
cfg.CookieConfig.Secure = true // Ensure Secure is true if SameSite=None
}

// Set the cookie configuration in the Redirect struct
r.cookieConfig = cfg.CookieConfig
Copy link
Member

Choose a reason for hiding this comment

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

since the part with the configurations has become larger, we can move this to a private function for creating the configuration, so that it becomes more usable again

gaby and others added 14 commits July 25, 2024 08:41
* Improve performance of adaptor middleware by over 50%

* Update whats_new documentation

* Remove fasthttp.Request pool

* Update whats_new.md
* added startup default probe endpoint

* added test case

* updated docs

* updated test order

* added test case

* fixed go fmt and md lint

* fixed go fmt and md lint

* updated doc as per coderabbitai suggestions

* changed healhtcheck route register to use default const instead of string for test cases

* updated whats new with healthcheck content

* updated whats new doc with coderabbitai sugg

* updated migration guide
* feat: add rebuild tree method

* docs: add newline at the end of app.md

* docs: add an example of dynamic defined routes

* docs: remove tabs from example code on app.md

* Update docs/api/app.md

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update app.md

* docs: add RebuildTree to what's new documentation

* fix: markdown errors in documentation

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* refactor: add mutex lock to the addRoute function

* refactor: remove mutex lock from addRoute

* refactor: fix mutex deadlock in addRoute

---------

Co-authored-by: Juan Calderon-Perez <[email protected]>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
* test(ctx_test): Fix race condition

* chore: Release ctx resource after sending file

* refactor: sendFileBodyReader function

Refactor the `sendFileBodyReader` function to remove the unnecessary `app` parameter. This simplifies the function signature and improves code readability.
* Refactor benchmarks workflow

* Use full semver tag

* Add fetch depth
We should only fail during a PR, not during a merge
…ger Middleware (#3066)

* logger: Use Content-Length header for BytesReceived and BytesSent tags

* Use strconv.AppendInt instead of fasthttp.AppendUint
…duce Memory Usage (#3079)

* Use composites for internal structures. Fix alignment of structures across Fiber

* Update struct alignment in test files

* Enable alignment check with govet

* Fix ctx autoformat unit-test

* Revert app Config struct. Add betteralign to Makefile

* Disable comment on alert since it wont work for forks

* Update benchmark.yml

* Update benchmark.yml

* Remove warning from using positional fields

* Update router.go
* Improve performance of helper functions

* Fix issue with PR comments from forks
* feat: add max calculator to limiter middleware

* docs: update docs including the new parameter

* refactor: add new line before go code in docs

* fix: use crypto/rand instead of math/rand on tests

* test: add new test with zero set as limit

* fix: repeated tests failing when generating random limits

* fix: wrong type of MaxCalculator in docs

* feat: include max calculator in limiter_sliding

* refactor: rename MaxCalculator to MaxFunc

* docs: update docs with MaxFunc parameter

* tests: rename tests and add test for limiter sliding
Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](actions/checkout@v3...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
ReneWerner87 and others added 3 commits July 25, 2024 08:42
* Use utils Trim functions instead of the strings/bytes functions

* rename Test and Benchmark functions with same name
@gaby
Copy link
Member Author

gaby commented Jul 26, 2024

Will finish this during the weekend.

@ReneWerner87
Copy link
Member

Will finish this during the weekend.

what is the state here ?

@gaby
Copy link
Member Author

gaby commented Aug 23, 2024

Blocked by #3099 both PR's are doing massive changes to the same file.

@ReneWerner87
Copy link
Member

@gaby can you update the PR

@ReneWerner87
Copy link
Member

@gaby friendly ping

@gaby
Copy link
Member Author

gaby commented Sep 15, 2024

I'm going to create a new branch/PR. The merge conflicts are impossible to deal with.

@gaby gaby closed this Sep 15, 2024
@ReneWerner87
Copy link
Member

I'm going to create a new branch/PR. The merge conflicts are impossible to deal with.

Do not forget
Is this a breaking change? Then we should definitely implement it first

@gaby
Copy link
Member Author

gaby commented Sep 18, 2024

@ReneWerner87 It's not, the changes for adding msgpack a few PR's ago were in the same lines that this one was modifying.

@ReneWerner87
Copy link
Member

ok

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

Successfully merging this pull request may close these issues.

6 participants