-
-
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
fix(net/gclient): using the wrong header to update file #3775
Open
oldme-git
wants to merge
5
commits into
master
Choose a base branch
from
fix/3748
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. | ||
// | ||
// This Source Code Form is subject to the terms of the MIT License. | ||
// If a copy of the MIT was not distributed with this file, | ||
// You can obtain one at https://github.com/gogf/gf. | ||
|
||
package gclient_test | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/gogf/gf/v2/frame/g" | ||
"github.com/gogf/gf/v2/net/gclient" | ||
"github.com/gogf/gf/v2/net/ghttp" | ||
"github.com/gogf/gf/v2/test/gtest" | ||
"github.com/gogf/gf/v2/util/guid" | ||
) | ||
|
||
func Test_Issue3748(t *testing.T) { | ||
s := g.Server(guid.S()) | ||
s.BindHandler("/", func(r *ghttp.Request) { | ||
r.Response.Write( | ||
r.GetBody(), | ||
) | ||
}) | ||
s.SetDumpRouterMap(false) | ||
s.Start() | ||
defer s.Shutdown() | ||
|
||
clientHost := fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()) | ||
time.Sleep(100 * time.Millisecond) | ||
|
||
gtest.C(t, func(t *gtest.T) { | ||
client := gclient.New() | ||
client.SetHeader("Content-Type", "application/json") | ||
data := map[string]interface{}{ | ||
"name": "@file:", | ||
"value": "json", | ||
} | ||
client.SetPrefix(clientHost) | ||
content := client.PostContent(ctx, "/", data) | ||
t.Assert(content, `{"name":"@file:","value":"json"}`) | ||
}) | ||
|
||
gtest.C(t, func(t *gtest.T) { | ||
client := gclient.New() | ||
client.SetHeader("Content-Type", "application/xml") | ||
data := map[string]interface{}{ | ||
"name": "@file:", | ||
"value": "xml", | ||
} | ||
client.SetPrefix(clientHost) | ||
content := client.PostContent(ctx, "/", data) | ||
t.Assert(content, `<doc><name>@file:</name><value>xml</value></doc>`) | ||
}) | ||
|
||
gtest.C(t, func(t *gtest.T) { | ||
client := gclient.New() | ||
client.SetHeader("Content-Type", "application/x-www-form-urlencoded") | ||
data := map[string]interface{}{ | ||
"name": "@file:", | ||
"value": "x-www-form-urlencoded", | ||
} | ||
client.SetPrefix(clientHost) | ||
content := client.PostContent(ctx, "/", data) | ||
contentSlice := strings.Split(content, "&") | ||
t.Assert(len(contentSlice), 2) | ||
t.Assert(strings.Contains(content, `name=@file:`), true) | ||
t.Assert(strings.Contains(content, `value=x-www-form-urlencoded`), true) | ||
}) | ||
|
||
gtest.C(t, func(t *gtest.T) { | ||
client := gclient.New() | ||
data := "@file:" | ||
client.SetPrefix(clientHost) | ||
_, err := client.Post(ctx, "/", data) | ||
t.AssertNil(err) | ||
}) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
等等,我看了下这个issue #3748 只是提了会报
panic
,应该是参数处理不严谨。而你这个pr做了一些枚举来允许文件上传,好像是两码事了诶?!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.
之前这块的上传逻辑不严谨,如果
header content-type
头是json
或者xml
这种不允许上传文件的头,应该将其做为一个普通的字符串上传