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: support custom formvalue function #1453
feat: support custom formvalue function #1453
Conversation
3a67d42
to
efe5988
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have a real world example of this going wrong or is it something you think might go wrong?
server.go
Outdated
return defaultFormValue(ctx, key) | ||
} | ||
|
||
type FormValue func(*RequestCtx, string) []byte |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type FormValue func(*RequestCtx, string) []byte | |
type FormValueFunc func(*RequestCtx, string) []byte |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
server.go
Outdated
|
||
// SetStandardFormValueFunc sets FormValue function implementation to get form value. | ||
// Consistent behaviour with net/http. POST and PUT body parameters take precedence over URL query string values. | ||
func SetStandardFormValueFunc() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func SetStandardFormValueFunc() { | |
func SetNetHttpFormValueFunc() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
efe5988
to
011607d
Compare
Yes, there was a problem with the code in the real environment and I noticed the difference. the front end passes the same parameters and different values in the http body and query and result in an unintended bug... |
faf8119
to
f58e4ab
Compare
server.go
Outdated
@@ -412,6 +412,7 @@ type Server struct { | |||
concurrencyCh chan struct{} | |||
perIPConnCounter perIPConnCounter | |||
serverName atomic.Value | |||
FormValueFunc FormValueFunc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This field needs some documentation since it's exposed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks and done
server.go
Outdated
if len(vv) > 0 { | ||
return []byte(vv[0]) | ||
|
||
// NetHttpFormValueFunc Consistent behaviour with net/http. POST and PUT body parameters take precedence over URL query string values. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// NetHttpFormValueFunc Consistent behaviour with net/http. POST and PUT body parameters take precedence over URL query string values. | |
// NetHttpFormValueFunc gives consistent behavior with net/http. POST and PUT body parameters take precedence over URL query string values. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks
e8e52d2
to
56a135e
Compare
56a135e
to
09b5fcc
Compare
Thanks! |
Some gin or net/http services have a different formvalue function when migrating to fasthttp.
it maybe causes some bugs.
net/http:
The user can customize a formvalue function to avoid this problem, but it would be better if the framework provided this switch.