From 674f4be24db25e66b5e16875bb6e6d1666287b4a Mon Sep 17 00:00:00 2001 From: Dreamacro <305009791@qq.com> Date: Tue, 7 Aug 2018 14:45:16 +0800 Subject: [PATCH] Fix: add JSON Content-Type for stream api to avoid buffer in swift --- hub/server.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/hub/server.go b/hub/server.go index 7d7a35d6f..009b122dd 100644 --- a/hub/server.go +++ b/hub/server.go @@ -44,8 +44,8 @@ func newHub(signal chan struct{}) { r.Use(cors.Handler) - r.Get("/traffic", traffic) - r.Get("/logs", getLogs) + r.With(jsonContentType).Get("/traffic", traffic) + r.With(jsonContentType).Get("/logs", getLogs) r.Mount("/configs", configRouter()) r.Mount("/proxies", proxyRouter()) r.Mount("/rules", ruleRouter()) @@ -56,6 +56,14 @@ func newHub(signal chan struct{}) { } } +func jsonContentType(next http.Handler) http.Handler { + fn := func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + next.ServeHTTP(w, r) + } + return http.HandlerFunc(fn) +} + func traffic(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK)