mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Add Cache-Control headers to disable caching /_ping endpoint
The result of this endpoint should not be cached, so it's better to explicitly disable caching. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
beef00cb26
commit
5f788fbf56
4 changed files with 48 additions and 0 deletions
|
@ -27,6 +27,9 @@ func optionsHandler(ctx context.Context, w http.ResponseWriter, r *http.Request,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *systemRouter) pingHandler(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
func (s *systemRouter) pingHandler(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||||
|
w.Header().Add("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||||
|
w.Header().Add("Pragma", "no-cache")
|
||||||
|
|
||||||
builderVersion := build.BuilderVersion(*s.features)
|
builderVersion := build.BuilderVersion(*s.features)
|
||||||
if bv := builderVersion; bv != "" {
|
if bv := builderVersion; bv != "" {
|
||||||
w.Header().Set("Builder-Version", string(bv))
|
w.Header().Set("Builder-Version", string(bv))
|
||||||
|
|
|
@ -7107,10 +7107,23 @@ paths:
|
||||||
Docker-Experimental:
|
Docker-Experimental:
|
||||||
type: "boolean"
|
type: "boolean"
|
||||||
description: "If the server is running with experimental mode enabled"
|
description: "If the server is running with experimental mode enabled"
|
||||||
|
Cache-Control:
|
||||||
|
type: "string"
|
||||||
|
default: "no-cache, no-store, must-revalidate"
|
||||||
|
Pragma:
|
||||||
|
type: "string"
|
||||||
|
default: "no-cache"
|
||||||
500:
|
500:
|
||||||
description: "server error"
|
description: "server error"
|
||||||
schema:
|
schema:
|
||||||
$ref: "#/definitions/ErrorResponse"
|
$ref: "#/definitions/ErrorResponse"
|
||||||
|
headers:
|
||||||
|
Cache-Control:
|
||||||
|
type: "string"
|
||||||
|
default: "no-cache, no-store, must-revalidate"
|
||||||
|
Pragma:
|
||||||
|
type: "string"
|
||||||
|
default: "no-cache"
|
||||||
tags: ["System"]
|
tags: ["System"]
|
||||||
/commit:
|
/commit:
|
||||||
post:
|
post:
|
||||||
|
|
|
@ -17,6 +17,9 @@ keywords: "API, Docker, rcli, REST, documentation"
|
||||||
|
|
||||||
[Docker Engine API v1.40](https://docs.docker.com/engine/api/v1.40/) documentation
|
[Docker Engine API v1.40](https://docs.docker.com/engine/api/v1.40/) documentation
|
||||||
|
|
||||||
|
* `GET /_ping` now sets `Cache-Control` and `Pragma` headers to prevent the result
|
||||||
|
from being cached. This change is not versioned, and affects all API versions
|
||||||
|
if the daemon has this patch.
|
||||||
* `GET /services` now returns `Sysctls` as part of the `ContainerSpec`.
|
* `GET /services` now returns `Sysctls` as part of the `ContainerSpec`.
|
||||||
* `GET /services/{id}` now returns `Sysctls` as part of the `ContainerSpec`.
|
* `GET /services/{id}` now returns `Sysctls` as part of the `ContainerSpec`.
|
||||||
* `POST /services/create` now accepts `Sysctls` as part of the `ContainerSpec`.
|
* `POST /services/create` now accepts `Sysctls` as part of the `ContainerSpec`.
|
||||||
|
|
29
integration/system/ping_test.go
Normal file
29
integration/system/ping_test.go
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
package system // import "github.com/docker/docker/integration/system"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/docker/docker/internal/test/request"
|
||||||
|
"gotest.tools/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPingCacheHeaders(t *testing.T) {
|
||||||
|
defer setupTest(t)()
|
||||||
|
|
||||||
|
res, _, err := request.Get("/_ping")
|
||||||
|
assert.NilError(t, err)
|
||||||
|
assert.Equal(t, res.StatusCode, http.StatusOK)
|
||||||
|
|
||||||
|
assert.Equal(t, hdr(res, "Cache-Control"), "no-cache, no-store, must-revalidate")
|
||||||
|
assert.Equal(t, hdr(res, "Pragma"), "no-cache")
|
||||||
|
}
|
||||||
|
|
||||||
|
func hdr(res *http.Response, name string) string {
|
||||||
|
val, ok := res.Header[http.CanonicalHeaderKey(name)]
|
||||||
|
if !ok || len(val) == 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return strings.Join(val, ", ")
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue