From 3e21b5982bbb3133fd9d7de443eb30be2decb50d Mon Sep 17 00:00:00 2001 From: Bogdan U Date: Tue, 12 Oct 2021 22:35:19 +0300 Subject: [PATCH] add png content-type headers (#169) --- swagger.go | 2 ++ swagger_test.go | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/swagger.go b/swagger.go index 7fb3462..b34d2f3 100644 --- a/swagger.go +++ b/swagger.go @@ -99,6 +99,8 @@ func CustomWrapHandler(config *Config, handler *webdav.Handler) gin.HandlerFunc c.Header("Content-Type", "text/css; charset=utf-8") case ".js": c.Header("Content-Type", "application/javascript") + case ".png": + c.Header("Content-Type", "image/png") case ".json": c.Header("Content-Type", "application/json; charset=utf-8") } diff --git a/swagger_test.go b/swagger_test.go index aa6a0d1..3b8c54f 100644 --- a/swagger_test.go +++ b/swagger_test.go @@ -3,7 +3,6 @@ package ginSwagger import ( "net/http/httptest" "os" - "path/filepath" "testing" "github.com/gin-contrib/gzip" @@ -39,6 +38,7 @@ func TestWrapCustomHandler(t *testing.T) { w1 := performRequest("GET", "/index.html", router) assert.Equal(t, 200, w1.Code) + assert.Equal(t, w1.Header()["Content-Type"][0], "text/html; charset=utf-8") w2 := performRequest("GET", "/doc.json", router) assert.Equal(t, 500, w2.Code) @@ -50,9 +50,18 @@ func TestWrapCustomHandler(t *testing.T) { w3 := performRequest("GET", "/favicon-16x16.png", router) assert.Equal(t, 200, w3.Code) + assert.Equal(t, w3.Header()["Content-Type"][0], "image/png") - w4 := performRequest("GET", "/notfound", router) - assert.Equal(t, 404, w4.Code) + w4 := performRequest("GET", "/swagger-ui.css", router) + assert.Equal(t, 200, w4.Code) + assert.Equal(t, w4.Header()["Content-Type"][0], "text/css; charset=utf-8") + + w5 := performRequest("GET", "/swagger-ui-bundle.js", router) + assert.Equal(t, 200, w5.Code) + assert.Equal(t, w5.Header()["Content-Type"][0], "application/javascript") + + w6 := performRequest("GET", "/notfound", router) + assert.Equal(t, 404, w6.Code) } func TestDisablingWrapHandler(t *testing.T) { @@ -200,7 +209,3 @@ func TestDefaultModelsExpandDepth(t *testing.T) { configFunc(&cfg) assert.Equal(t, expected, cfg.DefaultModelsExpandDepth) } - -func TestDeepLinking2(t *testing.T) { - t.Logf("extension: %s", filepath.Ext("/asas/index.html")) -}