Skip to content
Snippets Groups Projects
Unverified Commit a9f17f07 authored by Will McCutchen's avatar Will McCutchen Committed by GitHub
Browse files

Merge pull request #50 from mccutchen/delay-cancelation

Send 499 status when client cancels /delay
parents 493d7aab 20fff771
No related branches found
No related tags found
No related merge requests found
......@@ -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)
# =============================================================================
......
// 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
......
......@@ -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):
}
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment