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(net/ghttp): add AutoDecodingBody configuration for ghttp.Server #4197

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

gqcn
Copy link
Member

@gqcn gqcn commented Mar 13, 2025

No description provided.

}
if body[0] == '<' && body[len(body)-1] == '>' {
r.bodyMap, _ = gxml.DecodeWithoutRoot(body)
}
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

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

保留错误应该会更好?

@houseme houseme requested a review from Copilot March 28, 2025 03:53
Copy link

@Copilot Copilot AI left a 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)
Copy link
Preview

Copilot AI Mar 28, 2025

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.

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.

3 participants