mirror of
https://github.com/cupcakearmy/codecrafters-http-server-go.git
synced 2024-12-22 08:06:27 +00:00
fix headers
This commit is contained in:
parent
a0c57541c2
commit
49e5c8105d
@ -67,6 +67,9 @@ func Respond(conn net.Conn, req Request, res Response) {
|
|||||||
if res.Headers == nil {
|
if res.Headers == nil {
|
||||||
res.Headers = make(map[string]string)
|
res.Headers = make(map[string]string)
|
||||||
}
|
}
|
||||||
|
if req.Headers["Accept-Encoding"] == "gzip" {
|
||||||
|
res.Headers["Content-Encoding"] = "gzip"
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Fprintf(conn, "%s %d %s%s", res.Version, res.Code.Code, res.Code.Message, HTTPDelimiter)
|
fmt.Fprintf(conn, "%s %d %s%s", res.Version, res.Code.Code, res.Code.Message, HTTPDelimiter)
|
||||||
bodySize := 0
|
bodySize := 0
|
||||||
@ -82,10 +85,6 @@ func Respond(conn net.Conn, req Request, res Response) {
|
|||||||
fmt.Fprintf(conn, "%s: %s%s", header, value, HTTPDelimiter)
|
fmt.Fprintf(conn, "%s: %s%s", header, value, HTTPDelimiter)
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.Headers["Accept-Encoding"] == "gzip" {
|
|
||||||
res.Headers["Content-Encoding"] = "gzip"
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Fprint(conn, HTTPDelimiter)
|
fmt.Fprint(conn, HTTPDelimiter)
|
||||||
if bodySize > 0 {
|
if bodySize > 0 {
|
||||||
if res.Body != "" {
|
if res.Body != "" {
|
||||||
|
@ -66,19 +66,19 @@ func TestEcho(t *testing.T) {
|
|||||||
}})
|
}})
|
||||||
}
|
}
|
||||||
|
|
||||||
// func TestEchoGzip(t *testing.T) {
|
func TestEchoGzip(t *testing.T) {
|
||||||
// input := "abc"
|
input := "abc"
|
||||||
// req, _ := http.NewRequest("GET", fmt.Sprintf("http://localhost:4221/echo/%s", input), nil)
|
req, _ := http.NewRequest("GET", fmt.Sprintf("http://localhost:4221/echo/%s", input), nil)
|
||||||
// req.Header.Set("Accept-Encoding", "gzip")
|
req.Header.Set("Accept-Encoding", "gzip")
|
||||||
// client := &http.Client{}
|
client := &http.Client{}
|
||||||
// res, _ := client.Do(req)
|
res, _ := client.Do(req)
|
||||||
|
|
||||||
// checkResponse(t, res, Expected{status: 200, body: input, headers: map[string]string{
|
checkResponse(t, res, Expected{status: 200, body: input, headers: map[string]string{
|
||||||
// // "Content-Length": strconv.Itoa(len(input)),
|
"Content-Length": strconv.Itoa(len(input)),
|
||||||
// "Content-Type": "text/plain",
|
"Content-Type": "text/plain",
|
||||||
// "Content-Encoding": "gzip",
|
"Content-Encoding": "gzip",
|
||||||
// }})
|
}})
|
||||||
// }
|
}
|
||||||
|
|
||||||
func TestUserAgent(t *testing.T) {
|
func TestUserAgent(t *testing.T) {
|
||||||
input := "CodeCrafters/1.0"
|
input := "CodeCrafters/1.0"
|
||||||
|
Loading…
Reference in New Issue
Block a user