fix headers

This commit is contained in:
Nazar Kanaev
2021-04-26 15:16:26 +01:00
parent 87b53fb8ec
commit 36e359c881
2 changed files with 30 additions and 2 deletions

View File

@@ -1,8 +1,13 @@
package server
import (
"io"
"log"
"net/http/httptest"
"os"
"testing"
"github.com/nkanaev/yarr/src/storage"
)
func TestStatic(t *testing.T) {
@@ -43,3 +48,26 @@ func TestStaticBanTemplates(t *testing.T) {
t.FailNow()
}
}
func TestIndexGzipped(t *testing.T) {
log.SetOutput(io.Discard)
db, _ := storage.New(":memory:")
log.SetOutput(os.Stderr)
handler := NewServer(db, "127.0.0.1:8000").handler()
url := "/"
recorder := httptest.NewRecorder()
request := httptest.NewRequest("GET", url, nil)
request.Header.Set("accept-encoding", "gzip")
handler.ServeHTTP(recorder, request)
response := recorder.Result()
if response.StatusCode != 200 {
t.FailNow()
}
if response.Header.Get("content-encoding") != "gzip" {
t.Errorf("invalid content-encoding header: %#v", response.Header.Get("content-encoding"))
}
if response.Header.Get("content-type") != "text/html" {
t.Errorf("invalid content-type header: %#v", response.Header.Get("content-type"))
}
}