-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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(net/ghttp): add AutoDecodingBody
configuration for ghttp.Server
#4197
base: master
Are you sure you want to change the base?
Conversation
} | ||
if body[0] == '<' && body[len(body)-1] == '>' { | ||
r.bodyMap, _ = gxml.DecodeWithoutRoot(body) | ||
} |
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.
为什么后面两个if不是else if
r.bodyMap, _ = gxml.DecodeWithoutRoot(body) | ||
return |
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.
保留错误应该会更好?
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.
Pull Request Overview
This PR introduces an AutoDecodingBody configuration option to ghttp.Server and updates the request body parsing logic accordingly.
- Updated the ServerConfig structure to include AutoDecodingBody with a default value.
- Enhanced the parseBody function in ghttp_request_param.go to perform auto-decoding for JSON and XML based on the new configuration.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
net/ghttp/ghttp_server_config.go | Added a new AutoDecodingBody field and updated its default value. |
net/ghttp/ghttp_request_param.go | Modified body parsing to support auto-decoding based on the new configuration. |
} | ||
// XML format checks. | ||
if len(body) > 5 && bytes.EqualFold(body[:5], xmlHeaderBytes) { | ||
if gstr.Contains(contentType, "/xml") { | ||
r.bodyMap, _ = gxml.DecodeWithoutRoot(body) |
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.
After decoding XML in the AutoDecodingBody block, consider adding a return statement to prevent falling through to the default decoding logic, which may inadvertently override the XML decoding result.
Copilot is powered by AI, so mistakes are possible. Review output carefully before use.
No description provided.