Skip to content

Commit

Permalink
Add the Access-Control-Expose-Headers header to the agent config re…
Browse files Browse the repository at this point in the history
…sponse. (elastic#2918) (elastic#2919) (elastic#2920)

To enable caching on the RUM agent. 

Fixes elastic#2915
  • Loading branch information
jalvz authored Nov 18, 2019
1 parent ff8148e commit 23581fb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
1 change: 1 addition & 0 deletions beater/api/config/agent/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func Handler(client kibana.Client, config *config.AgentConfig) request.Handler {
// configuration successfully fetched
c.Header().Set(headers.CacheControl, cacheControl)
c.Header().Set(headers.Etag, fmt.Sprintf("\"%s\"", result.Source.Etag))
c.Header().Set(headers.AccessControlExposeHeaders, headers.Etag)

if result.Source.Etag != "" && result.Source.Etag == ifNoneMatch(c) {
c.Result.SetDefault(request.IDResponseValidNotModified)
Expand Down
1 change: 1 addition & 0 deletions beater/api/config/agent/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ func TestAgentConfigRum(t *testing.T) {
h(ctx)
var actual map[string]string
json.Unmarshal(w.Body.Bytes(), &actual)
assert.Equal(t, headers.Etag, w.Header().Get(headers.AccessControlExposeHeaders))
assert.Equal(t, http.StatusOK, w.Code, w.Body.String())
assert.Equal(t, map[string]string{"transaction_sample_rate": "0.5"}, actual)
}
Expand Down
37 changes: 19 additions & 18 deletions beater/headers/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,23 @@ package headers

// http header keys
const (
Accept = "Accept"
AccessControlAllowHeaders = "Access-Control-Allow-Headers"
AccessControlAllowMethods = "Access-Control-Allow-Methods"
AccessControlAllowOrigin = "Access-Control-Allow-Origin"
AccessControlMaxAge = "Access-Control-Max-Age"
Authorization = "Authorization"
Bearer = "Bearer"
CacheControl = "Cache-Control"
Connection = "Connection"
ContentEncoding = "Content-Encoding"
ContentLength = "Content-Length"
ContentType = "Content-Type"
Etag = "Etag"
IfNoneMatch = "If-None-Match"
Origin = "Origin"
UserAgent = "User-Agent"
Vary = "Vary"
XContentTypeOptions = "X-Content-Type-Options"
Accept = "Accept"
AccessControlAllowHeaders = "Access-Control-Allow-Headers"
AccessControlAllowMethods = "Access-Control-Allow-Methods"
AccessControlAllowOrigin = "Access-Control-Allow-Origin"
AccessControlExposeHeaders = "Access-Control-Expose-Headers"
AccessControlMaxAge = "Access-Control-Max-Age"
Authorization = "Authorization"
Bearer = "Bearer"
CacheControl = "Cache-Control"
Connection = "Connection"
ContentEncoding = "Content-Encoding"
ContentLength = "Content-Length"
ContentType = "Content-Type"
Etag = "Etag"
IfNoneMatch = "If-None-Match"
Origin = "Origin"
UserAgent = "User-Agent"
Vary = "Vary"
XContentTypeOptions = "X-Content-Type-Options"
)
2 changes: 1 addition & 1 deletion beater/middleware/cors_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func CORSMiddleware(allowedOrigins []string) Middleware {
c.Header().Set(headers.AccessControlAllowMethods, supportedMethods)
c.Header().Set(headers.AccessControlAllowHeaders, supportedHeaders)

c.Header().Set("Access-Control-Expose-Headers", headers.Etag)
c.Header().Set(headers.AccessControlExposeHeaders, headers.Etag)

c.Header().Set(headers.ContentLength, "0")

Expand Down

0 comments on commit 23581fb

Please sign in to comment.