mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #38569 from thaJeztah/forget_about_it
Add Cache-Control headers to disable caching /_ping endpoint
This commit is contained in:
commit
393838ca5e
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 {
|
||||
w.Header().Add("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||
w.Header().Add("Pragma", "no-cache")
|
||||
|
||||
builderVersion := build.BuilderVersion(*s.features)
|
||||
if bv := builderVersion; bv != "" {
|
||||
w.Header().Set("Builder-Version", string(bv))
|
||||
|
|
|
@ -7115,10 +7115,23 @@ paths:
|
|||
Docker-Experimental:
|
||||
type: "boolean"
|
||||
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:
|
||||
description: "server error"
|
||||
schema:
|
||||
$ref: "#/definitions/ErrorResponse"
|
||||
headers:
|
||||
Cache-Control:
|
||||
type: "string"
|
||||
default: "no-cache, no-store, must-revalidate"
|
||||
Pragma:
|
||||
type: "string"
|
||||
default: "no-cache"
|
||||
tags: ["System"]
|
||||
/commit:
|
||||
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
|
||||
|
||||
* `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/{id}` now returns `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…
Reference in a new issue