@@ -17,6 +17,7 @@ package zipkin
17
17
import (
18
18
"compress/gzip"
19
19
"fmt"
20
+ "io"
20
21
"io/ioutil"
21
22
"net/http"
22
23
"strings"
@@ -65,14 +66,12 @@ func (aH *APIHandler) RegisterRoutes(router *mux.Router) {
65
66
func (aH * APIHandler ) saveSpans (w http.ResponseWriter , r * http.Request ) {
66
67
bRead := r .Body
67
68
defer r .Body .Close ()
68
-
69
69
if strings .Contains (r .Header .Get ("Content-Encoding" ), "gzip" ) {
70
- gz , err := gzip . NewReader ( r . Body )
70
+ gz , err := gunzip ( bRead )
71
71
if err != nil {
72
72
http .Error (w , fmt .Sprintf (app .UnableToReadBodyErrFormat , err ), http .StatusBadRequest )
73
73
return
74
74
}
75
- defer gz .Close ()
76
75
bRead = gz
77
76
}
78
77
@@ -108,15 +107,23 @@ func (aH *APIHandler) saveSpans(w http.ResponseWriter, r *http.Request) {
108
107
func (aH * APIHandler ) saveSpansV2 (w http.ResponseWriter , r * http.Request ) {
109
108
bRead := r .Body
110
109
defer r .Body .Close ()
110
+ if strings .Contains (r .Header .Get ("Content-Encoding" ), "gzip" ) {
111
+ gz , err := gunzip (bRead )
112
+ if err != nil {
113
+ http .Error (w , fmt .Sprintf (app .UnableToReadBodyErrFormat , err ), http .StatusBadRequest )
114
+ return
115
+ }
116
+ bRead = gz
117
+ }
111
118
112
119
bodyBytes , err := ioutil .ReadAll (bRead )
113
120
if err != nil {
114
121
http .Error (w , fmt .Sprintf (app .UnableToReadBodyErrFormat , err ), http .StatusInternalServerError )
115
122
return
116
123
}
117
124
118
- var spans * models.ListOfSpans = & models. ListOfSpans {}
119
- if err = swag .ReadJSON (bodyBytes , spans ); err != nil {
125
+ var spans models.ListOfSpans
126
+ if err = swag .ReadJSON (bodyBytes , & spans ); err != nil {
120
127
http .Error (w , fmt .Sprintf (app .UnableToReadBodyErrFormat , err ), http .StatusBadRequest )
121
128
return
122
129
}
@@ -125,7 +132,7 @@ func (aH *APIHandler) saveSpansV2(w http.ResponseWriter, r *http.Request) {
125
132
return
126
133
}
127
134
128
- tSpans , err := spansV2ToThrift (spans )
135
+ tSpans , err := spansV2ToThrift (& spans )
129
136
if err != nil {
130
137
http .Error (w , fmt .Sprintf (app .UnableToReadBodyErrFormat , err ), http .StatusBadRequest )
131
138
return
@@ -139,6 +146,15 @@ func (aH *APIHandler) saveSpansV2(w http.ResponseWriter, r *http.Request) {
139
146
w .WriteHeader (operations .PostSpansAcceptedCode )
140
147
}
141
148
149
+ func gunzip (r io.ReadCloser ) (* gzip.Reader , error ) {
150
+ gz , err := gzip .NewReader (r )
151
+ if err != nil {
152
+ return nil , err
153
+ }
154
+ defer gz .Close ()
155
+ return gz , nil
156
+ }
157
+
142
158
func (aH * APIHandler ) saveThriftSpans (tSpans []* zipkincore.Span ) error {
143
159
if len (tSpans ) > 0 {
144
160
ctx , _ := tchanThrift .NewContext (time .Minute )
0 commit comments