@@ -278,6 +278,12 @@ func findUnpackPB(req *http.Request, responses []serverResponse) ([]*pb.GlobMatc
278
278
return metrics , paths
279
279
}
280
280
281
+ const (
282
+ contentTypeJSON = "application/json"
283
+ contentTypeProtobuf = "application/x-protobuf"
284
+ contentTypePickle = "application/pickle"
285
+ )
286
+
281
287
func findHandler (w http.ResponseWriter , req * http.Request ) {
282
288
283
289
logger .Debugln ("request: " , req .URL .RequestURI ())
@@ -320,19 +326,19 @@ func findHandler(w http.ResponseWriter, req *http.Request) {
320
326
321
327
switch format {
322
328
case "protobuf" :
323
- w .Header ().Set ("Content-Type" , "application/protobuf" )
329
+ w .Header ().Set ("Content-Type" , contentTypeProtobuf )
324
330
var result pb.GlobResponse
325
331
query := req .FormValue ("query" )
326
332
result .Name = & query
327
333
result .Matches = metrics
328
334
b , _ := result .Marshal ()
329
335
w .Write (b )
330
336
case "json" :
331
- w .Header ().Set ("Content-Type" , "application/json" )
337
+ w .Header ().Set ("Content-Type" , contentTypeJSON )
332
338
jEnc := json .NewEncoder (w )
333
339
jEnc .Encode (metrics )
334
340
case "" , "pickle" :
335
- w .Header ().Set ("Content-Type" , "application/pickle" )
341
+ w .Header ().Set ("Content-Type" , contentTypePickle )
336
342
337
343
var result []map [string ]interface {}
338
344
@@ -397,19 +403,19 @@ func renderHandler(w http.ResponseWriter, req *http.Request) {
397
403
398
404
switch format {
399
405
case "protobuf" :
400
- w .Header ().Set ("Content-Type" , "application/protobuf" )
406
+ w .Header ().Set ("Content-Type" , contentTypeProtobuf )
401
407
b , _ := metrics .Marshal ()
402
408
w .Write (b )
403
409
404
410
case "json" :
405
411
presponse := createRenderResponse (metrics , nil )
406
- w .Header ().Set ("Content-Type" , "application/json" )
412
+ w .Header ().Set ("Content-Type" , contentTypeJSON )
407
413
e := json .NewEncoder (w )
408
414
e .Encode (presponse )
409
415
410
416
case "" , "pickle" :
411
417
presponse := createRenderResponse (metrics , pickle.None {})
412
- w .Header ().Set ("Content-Type" , "application/pickle" )
418
+ w .Header ().Set ("Content-Type" , contentTypePickle )
413
419
e := pickle .NewEncoder (w )
414
420
e .Encode (presponse )
415
421
}
@@ -597,7 +603,7 @@ func infoHandler(w http.ResponseWriter, req *http.Request) {
597
603
598
604
switch format {
599
605
case "protobuf" :
600
- w .Header ().Set ("Content-Type" , "application/protobuf" )
606
+ w .Header ().Set ("Content-Type" , contentTypeProtobuf )
601
607
var result pb.ZipperInfoResponse
602
608
result .Responses = make ([]* pb.ServerInfoResponse , len (infos ))
603
609
for s , i := range infos {
@@ -609,7 +615,7 @@ func infoHandler(w http.ResponseWriter, req *http.Request) {
609
615
b , _ := result .Marshal ()
610
616
w .Write (b )
611
617
case "" , "json" :
612
- w .Header ().Set ("Content-Type" , "application/json" )
618
+ w .Header ().Set ("Content-Type" , contentTypeJSON )
613
619
jEnc := json .NewEncoder (w )
614
620
jEnc .Encode (infos )
615
621
}
0 commit comments