mirror of
https://github.com/nkanaev/yarr.git
synced 2025-05-24 00:33:14 +00:00
fix headers
This commit is contained in:
parent
87b53fb8ec
commit
36e359c881
@ -29,15 +29,15 @@ func (c *Context) JSON(status int, data interface{}) {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
c.Out.WriteHeader(status)
|
||||
c.Out.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
c.Out.WriteHeader(status)
|
||||
c.Out.Write(body)
|
||||
c.Out.Write([]byte("\n"))
|
||||
}
|
||||
|
||||
func (c *Context) HTML(status int, tmpl *template.Template, data interface{}) {
|
||||
c.Out.WriteHeader(status)
|
||||
c.Out.Header().Set("Content-Type", "text/html")
|
||||
c.Out.WriteHeader(status)
|
||||
tmpl.Execute(c.Out, data)
|
||||
}
|
||||
|
||||
|
@ -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"))
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user