mirror of
https://github.com/mailgun/groupcache.git
synced 2024-11-16 14:10:04 +00:00
Use PathEscape instead of QueryEscape (#49)
This commit is contained in:
parent
a139af4144
commit
3c50bed6df
6
http.go
6
http.go
@ -271,8 +271,8 @@ func (h *httpGetter) makeRequest(ctx context.Context, m string, in request, b io
|
||||
u := fmt.Sprintf(
|
||||
"%v%v/%v",
|
||||
h.baseURL,
|
||||
url.QueryEscape(in.GetGroup()),
|
||||
url.QueryEscape(in.GetKey()),
|
||||
url.PathEscape(in.GetGroup()),
|
||||
url.PathEscape(in.GetKey()),
|
||||
)
|
||||
req, err := http.NewRequestWithContext(ctx, m, u, b)
|
||||
if err != nil {
|
||||
@ -300,7 +300,7 @@ func (h *httpGetter) Get(ctx context.Context, in *pb.GetRequest, out *pb.GetResp
|
||||
defer res.Body.Close()
|
||||
if res.StatusCode != http.StatusOK {
|
||||
msg, _ := ioutil.ReadAll(io.LimitReader(res.Body, 1024*1024)) // Limit reading the error body to max 1 MiB
|
||||
return fmt.Errorf("server returned: %v, %v", res.Status, msg)
|
||||
return fmt.Errorf("server returned: %v, %v", res.Status, string(msg))
|
||||
}
|
||||
b := bufferPool.Get().(*bytes.Buffer)
|
||||
b.Reset()
|
||||
|
@ -174,6 +174,15 @@ func TestHTTPPool(t *testing.T) {
|
||||
if !bytes.Equal(setValue, getValue.ByteSlice()) {
|
||||
t.Fatal(errors.New(fmt.Sprintf("incorrect value retrieved after set: %s", getValue)))
|
||||
}
|
||||
|
||||
// Key with non-URL characters to test URL encoding roundtrip
|
||||
key = "a b/c,d"
|
||||
if err := g.Get(ctx, key, StringSink(&value)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if suffix := ":" + key; !strings.HasSuffix(value, suffix) {
|
||||
t.Errorf("Get(%q) = %q, want value ending in %q", key, value, suffix)
|
||||
}
|
||||
}
|
||||
|
||||
func testKeys(n int) (keys []string) {
|
||||
|
Loading…
Reference in New Issue
Block a user