summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--api/handlers.go10
-rw-r--r--main.go2
2 files changed, 10 insertions, 2 deletions
diff --git a/api/handlers.go b/api/handlers.go
index 04fcc23..93f605e 100644
--- a/api/handlers.go
+++ b/api/handlers.go
@@ -258,6 +258,8 @@ func (h *Handler) GetArticle(w http.ResponseWriter, r *http.Request) {
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
b, _ := io.ReadAll(resp.Body)
+ resp.Body.Close()
+
log.Printf("article request failed: user=%s article=%s status=%d body=%s (%dms)",
username, article, resp.StatusCode, string(b), elapsed)
h.db.LogApiCall(ctx, &db.ApiLogEntry{
@@ -268,7 +270,13 @@ func (h *Handler) GetArticle(w http.ResponseWriter, r *http.Request) {
Error: string(b),
RequestURL: queryURL,
})
- http.Error(w, string(b), resp.StatusCode)
+
+ w.Header().Set("Content-Type", "application/json")
+ w.WriteHeader(resp.StatusCode)
+ w.Write(b) //nolint:errcheck
+ if f, ok := w.(http.Flusher); ok {
+ f.Flush()
+ }
return
}
diff --git a/main.go b/main.go
index 341a175..1633e96 100644
--- a/main.go
+++ b/main.go
@@ -94,7 +94,7 @@ func main() {
Addr: addr,
Handler: mux,
ReadTimeout: 5 * time.Second,
- WriteTimeout: 10 * time.Second,
+ WriteTimeout: 45 * time.Second,
IdleTimeout: 120 * time.Second,
}