Implement HTTP timeout configurations and enhance API documentation
- Added optional HTTP server timeout configurations (`HNHMAP_READ_TIMEOUT`, `HNHMAP_WRITE_TIMEOUT`, `HNHMAP_IDLE_TIMEOUT`) to `.env.example` and updated the server initialization in `main.go` to utilize these settings. - Enhanced API documentation for the `rebuildZooms` endpoint to clarify its background processing and polling mechanism for status updates. - Updated `configuration.md` to include new timeout environment variables for better configuration guidance. - Improved error handling in the client for large request bodies, ensuring appropriate responses for oversized payloads.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package handlers_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
@@ -677,3 +678,38 @@ func TestClientRouter_InvalidToken(t *testing.T) {
|
||||
t.Fatalf("expected 401, got %d", rr.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClientRouter_PositionUpdate_BodyTooLarge(t *testing.T) {
|
||||
env := newTestEnv(t)
|
||||
env.createUser(t, "alice", "pass", app.Auths{app.AUTH_UPLOAD})
|
||||
tokens := env.auth.GenerateTokenForUser(context.Background(), "alice")
|
||||
if len(tokens) == 0 {
|
||||
t.Fatal("expected token")
|
||||
}
|
||||
// Body larger than maxClientBodySize (2MB)
|
||||
bigBody := bytes.Repeat([]byte("x"), 2*1024*1024+1)
|
||||
req := httptest.NewRequest(http.MethodPost, "/client/"+tokens[0]+"/positionUpdate", bytes.NewReader(bigBody))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
rr := httptest.NewRecorder()
|
||||
env.h.ClientRouter(rr, req)
|
||||
if rr.Code != http.StatusRequestEntityTooLarge {
|
||||
t.Fatalf("expected 413, got %d: %s", rr.Code, rr.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestClientRouter_MarkerUpdate_BodyTooLarge(t *testing.T) {
|
||||
env := newTestEnv(t)
|
||||
env.createUser(t, "alice", "pass", app.Auths{app.AUTH_UPLOAD})
|
||||
tokens := env.auth.GenerateTokenForUser(context.Background(), "alice")
|
||||
if len(tokens) == 0 {
|
||||
t.Fatal("expected token")
|
||||
}
|
||||
bigBody := bytes.Repeat([]byte("x"), 2*1024*1024+1)
|
||||
req := httptest.NewRequest(http.MethodPost, "/client/"+tokens[0]+"/markerUpdate", bytes.NewReader(bigBody))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
rr := httptest.NewRecorder()
|
||||
env.h.ClientRouter(rr, req)
|
||||
if rr.Code != http.StatusRequestEntityTooLarge {
|
||||
t.Fatalf("expected 413, got %d: %s", rr.Code, rr.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user