Skip to content

Commit 9c77d02

Browse files
committed
add content-len
1 parent bd2af2b commit 9c77d02

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

internals/server/http.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package server
33
import (
44
"encoding/json"
55
"net/http"
6+
"strconv"
67
"time"
78

89
"github.com/codeshelldev/gotl/pkg/logger"
@@ -40,14 +41,21 @@ func httpHandler(w http.ResponseWriter, req *http.Request) {
4041
"client_id": clientID,
4142
}
4243

43-
w.Header().Set("Content-Type", "application/json")
44-
json.NewEncoder(w).Encode(resp)
44+
respBytes, err := json.Marshal(resp)
45+
46+
if err != nil {
47+
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
48+
}
4549

4650
logger.Debug("Sending client_id to client")
4751

52+
w.Header().Set("Content-Type", "application/json")
53+
w.Header().Set("Content-Length", strconv.Itoa(len(respBytes)))
54+
w.Write(respBytes)
55+
4856
f, ok := w.(http.Flusher)
49-
if ok {
50-
f.Flush()
57+
if ok {
58+
f.Flush()
5159
}
5260

5361
logger.Debug("Waiting for client to establish websocket connection")

0 commit comments

Comments
 (0)