File tree 8 files changed +21
-13
lines changed
8 files changed +21
-13
lines changed Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2023 CloudWeGo Authors
2
+ * Copyright 2024 CloudWeGo Authors
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -82,10 +82,14 @@ func (g *gzipClientMiddleware) ClientMiddleware(next client.Endpoint) client.End
82
82
83
83
err = next (ctx , req , resp )
84
84
if err != nil {
85
- return
85
+ return err
86
86
}
87
87
if fn := g .DecompressFnForClient ; fn != nil && strings .EqualFold (resp .Header .Get ("Content-Encoding" ), "gzip" ) {
88
- fn (next )
88
+ f := fn (next )
89
+ err = f (ctx , req , resp )
90
+ if err != nil {
91
+ return err
92
+ }
89
93
}
90
94
return nil
91
95
}
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2023 CloudWeGo Authors
2
+ * Copyright 2024 CloudWeGo Authors
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2023 CloudWeGo Authors
2
+ * Copyright 2024 CloudWeGo Authors
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2023 CloudWeGo Authors
2
+ * Copyright 2024 CloudWeGo Authors
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2023 CloudWeGo Authors
2
+ * Copyright 2024 CloudWeGo Authors
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -405,11 +405,12 @@ func TestNoGzipForClient(t *testing.T) {
405
405
func TestDecompressGzipForClient (t * testing.T ) {
406
406
h := server .Default (server .WithHostPorts ("127.0.0.1:2338" ))
407
407
408
+ h .Use (Gzip (DefaultCompression , WithDecompressFn (DefaultDecompressHandle )))
408
409
h .GET ("/" , func (ctx context.Context , c * app.RequestContext ) {
409
410
c .Header ("Content-Length" , strconv .Itoa (len (testResponse )))
410
411
c .String (200 , testResponse )
411
412
})
412
- h . Use ( Gzip ( DefaultCompression , WithDecompressFn ( DefaultDecompressHandle )))
413
+
413
414
go h .Spin ()
414
415
415
416
time .Sleep (time .Second )
@@ -425,6 +426,7 @@ func TestDecompressGzipForClient(t *testing.T) {
425
426
426
427
req .SetBodyString ("bar" )
427
428
req .SetRequestURI ("http://127.0.0.1:2338/" )
429
+ req .SetHeader ("Accept-Encoding" , "gzip" )
428
430
429
431
err = cli .Do (context .Background (), req , res )
430
432
if err != nil {
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2023 CloudWeGo Authors
2
+ * Copyright 2024 CloudWeGo Authors
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
41
41
package gzip
42
42
43
43
import (
44
+ "bytes"
44
45
"context"
45
46
"net/http"
46
47
"regexp"
@@ -216,7 +217,8 @@ func DefaultDecompressMiddlewareForClient(next client.Endpoint) client.Endpoint
216
217
}
217
218
resp .Header .DelBytes ([]byte ("Content-Encoding" ))
218
219
resp .Header .DelBytes ([]byte ("Content-Length" ))
219
- resp .SetBody (gunzipBytes )
220
- return next (ctx , req , resp )
220
+ resp .Header .DelBytes ([]byte ("Vary" ))
221
+ resp .SetBodyStream (bytes .NewBuffer (gunzipBytes ), len (gunzipBytes ))
222
+ return nil
221
223
}
222
224
}
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2023 CloudWeGo Authors
2
+ * Copyright 2024 CloudWeGo Authors
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2023 CloudWeGo Authors
2
+ * Copyright 2024 CloudWeGo Authors
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
You can’t perform that action at this time.
0 commit comments