Skip to content

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

if len(body) > 5 && bytes.EqualFold(body[:5], xmlHeaderBytes) {
if gstr.Contains(contentType, "/xml") {
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
Contributor

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

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 uses AI. Check for mistakes.
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.

4 participants