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

🔥 Customize the source of session_id #1159

Merged

Conversation

leozhantw
Copy link
Contributor

Please provide enough information so that others can review your pull request:

Try to support the need of #1110.

Explain the details for making this change. What existing problem does the pull request solve?

I refer to gofiber/session and fasthttp/session to implement this requirement.

Commit formatting

Use emojis on commit messages so it provides an easy way of identifying the purpose or intention of a commit. Check out the emoji cheatsheet here: https://gitmoji.carloscuesta.me/

Copy link
Contributor

@hi019 hi019 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

Comment on lines 174 to 198

if s.config.Source == SourceHeader {
s.ctx.Request().Header.SetBytesV(s.config.CookieName, []byte(s.id))
s.ctx.Response().Header.SetBytesV(s.config.CookieName, []byte(s.id))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

A cookie will still be set even if the source is Header. We should put the above code in an if statement to prevent this. We should also rename the function to setSession or similar

Copy link
Contributor Author

@leozhantw leozhantw Apr 4, 2021

Choose a reason for hiding this comment

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

Thanks! It has been adjusted to setSession.

And also put the above code in an if statement.

middleware/session/session.go Outdated Show resolved Hide resolved
middleware/session/session_test.go Outdated Show resolved Hide resolved
middleware/session/store.go Outdated Show resolved Hide resolved
middleware/session/store.go Outdated Show resolved Hide resolved
@hi019 hi019 marked this pull request as draft February 21, 2021 23:05
@ReneWerner87 ReneWerner87 linked an issue Mar 21, 2021 that may be closed by this pull request
@leozhantw leozhantw force-pushed the feature/customize-session-ID-source branch 2 times, most recently from 55911fa to fec56d5 Compare April 4, 2021 06:59
@leozhantw
Copy link
Contributor Author

Hi,

I'm a bit busy recently, sorry to reply to you so late.

And I have made some adjustments, plz help me to confirm it again, thanks!

@leozhantw leozhantw marked this pull request as ready for review April 10, 2021 08:20
@hi019
Copy link
Contributor

hi019 commented Apr 20, 2021

Apologies for the delay, will review this tomorrow

@ReneWerner87
Copy link
Member

@leozhantw could you refresh the pull request and solve the change request ?

then we can also merge this slowly^^

@ReneWerner87
Copy link
Member

will do the review tonight

@leozhantw leozhantw force-pushed the feature/customize-session-ID-source branch from fec56d5 to fc28aa1 Compare May 19, 2021 15:29
@leozhantw leozhantw requested a review from hi019 May 19, 2021 15:34
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.

not sure about one part i have marked in the review, otherwise the whole thing looks very good

although i think you could still optimize some things by adding benchmarks and look that you reduce the allocations

like for example when splitting the string, you could look instead of split with index checks, but that should be insignificant, because it is before the process of the requests and only affects the configuration

good work and thx

}

if s.source == SourceURLQuery {
id = c.FormValue(s.sessionName)
Copy link
Member

Choose a reason for hiding this comment

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

this should be the wrong function or ? if we want to get it from the query parameters it should be c.Query(s.sessionName)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Although c.FormValue() will search the value from query string first,

but you are right, it should only search from query string.

Changed here to use c.Query(). Thanks you!

Ref

https://github.com/valyala/fasthttp/blob/v1.23.0/server.go#L1004-L1036

@leozhantw leozhantw force-pushed the feature/customize-session-ID-source branch 2 times, most recently from d3f4fcb to a630124 Compare May 23, 2021 16:25
middleware/session/config.go Show resolved Hide resolved
@hi019
Copy link
Contributor

hi019 commented May 27, 2021

Thank you for the PR! Looks good 👍

@ReneWerner87
Copy link
Member

@leozhantw can you update the pull request again with the master, i had unfortunately produced an incorrect test in the master in the meantime

after that i will start the tests from PR again and merge them directly if they were successful

@leozhantw leozhantw force-pushed the feature/customize-session-ID-source branch from 8c0348b to 6fa4f0e Compare May 28, 2021 15:45
@leozhantw
Copy link
Contributor Author

@leozhantw can you update the pull request again with the master, i had unfortunately produced an incorrect test in the master in the meantime

after that i will start the tests from PR again and merge them directly if they were successful

Done~!

@ReneWerner87 ReneWerner87 merged commit 9b3662e into gofiber:master May 29, 2021
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.

Can i custom session_id position?🤗
4 participants