diff --git a/Makefile b/Makefile index 4531336c7f1d28360fa57c3e7205263847a76f0a..eaf2521c92089fb13cad210bded949f8bdb614ad 100644 --- a/Makefile +++ b/Makefile @@ -142,11 +142,10 @@ gcloud-auth: # docker images # ============================================================================= image: - docker build -t $(DOCKER_TAG_DOCKERHUB) -t $(DOCKER_TAG_GCLOUD) . + docker build -t $(DOCKER_TAG_DOCKERHUB) . imagepush: image - docker push $(DOCKER_TAG_GCLOUD) - docker push $(DOCKER_TAG_GCLOUD) + docker push $(DOCKER_TAG_DOCKERHUB) # ============================================================================= diff --git a/httpbin/assets/assets.go b/httpbin/assets/assets.go index df339f651620b8fbb917a64b340cd9c2cfa8e5e4..d596b1023ff2902841f145ee996230613521b347 100644 --- a/httpbin/assets/assets.go +++ b/httpbin/assets/assets.go @@ -1,15 +1,15 @@ // Code generated by go-bindata. DO NOT EDIT. // sources: -// static/forms-post.html (1.398kB) -// static/image.jpeg (35.588kB) -// static/image.png (8.09kB) -// static/image.svg (8.984kB) -// static/image.webp (10.568kB) -// static/index.html (11.363kB) -// static/moby.html (3.742kB) -// static/sample.json (421B) -// static/sample.xml (522B) -// static/utf8.html (14.24kB) +// forms-post.html (1.398kB) +// image.jpeg (35.588kB) +// image.png (8.09kB) +// image.svg (8.984kB) +// image.webp (10.568kB) +// index.html (11.363kB) +// moby.html (3.742kB) +// sample.json (421B) +// sample.xml (522B) +// utf8.html (14.24kB) package assets diff --git a/httpbin/handlers.go b/httpbin/handlers.go index 1343a023b1454c83270fb66746d2039ab278af7b..5e95a9e94c0932348ef0456e0a00e51067f9f551 100644 --- a/httpbin/handlers.go +++ b/httpbin/handlers.go @@ -502,6 +502,7 @@ func (h *HTTPBin) Delay(w http.ResponseWriter, r *http.Request) { select { case <-r.Context().Done(): + w.WriteHeader(499) // "Client Closed Request" https://httpstatuses.com/499 return case <-time.After(delay): } diff --git a/httpbin/handlers_test.go b/httpbin/handlers_test.go index e93f4f033300e736edbed642a1589df24d84692a..4371a3b0d256daaeab6920630461216a09988a25 100644 --- a/httpbin/handlers_test.go +++ b/httpbin/handlers_test.go @@ -5,6 +5,7 @@ import ( "bytes" "compress/gzip" "compress/zlib" + "context" "encoding/json" "errors" "fmt" @@ -1469,6 +1470,19 @@ func TestDelay(t *testing.T) { } }) + t.Run("cancelation causes 499", func(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), 20*time.Millisecond) + defer cancel() + + r, _ := http.NewRequestWithContext(ctx, "GET", "/delay/1s", nil) + w := httptest.NewRecorder() + handler.ServeHTTP(w, r) + + if w.Code != 499 { + t.Errorf("expected 499 response, got %d", w.Code) + } + }) + var badTests = []struct { url string code int