-
Notifications
You must be signed in to change notification settings - Fork 2k
confighttp: add ExposedHeaders to CORSConfig #15119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # Use this changelog template to create an entry for release notes. | ||
|
|
||
| # One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
| change_type: enhancement | ||
|
|
||
| # The name of the component, or a single word describing the area of concern, (e.g. receiver/otlp) | ||
| component: pkg/confighttp | ||
|
|
||
| # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
| note: Add `ExposedHeaders` field to `CORSConfig` to allow setting the `Access-Control-Expose-Headers` response header. | ||
|
|
||
| # One or more tracking issues or pull requests related to the change | ||
| issues: [15119] | ||
|
|
||
| # (Optional) One or more lines of additional information to render under the primary note. | ||
| # These lines will be padded with 2 spaces and then inserted directly into the document. | ||
| # Use pipe (|) for multiline entries. | ||
| subtext: | ||
|
|
||
| # Optional: The change log or logs in which this entry should be included. | ||
| # e.g. '[user]' or '[user, api]' | ||
| # Include 'user' if the change is relevant to end users. | ||
| # Include 'api' if there is a change to a library API. | ||
| # Default: '[user]' | ||
| change_logs: [user, api] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -455,6 +455,39 @@ func TestHTTPCorsWithSettings(t *testing.T) { | |
| assert.Equal(t, "*", rec.Header().Get("Access-Control-Allow-Origin")) | ||
| } | ||
|
|
||
| func TestHTTPCorsExposedHeaders(t *testing.T) { | ||
| sc := &ServerConfig{ | ||
| NetAddr: confignet.AddrConfig{ | ||
| Endpoint: "localhost:0", | ||
| Transport: confignet.TransportTypeTCP, | ||
| }, | ||
| CORS: configoptional.Some(CORSConfig{ | ||
| AllowedOrigins: []string{"http://allowed.com"}, | ||
| ExposedHeaders: []string{"X-Custom-Header", "X-Another-Header"}, | ||
| }), | ||
|
Comment on lines
+458
to
+467
|
||
| } | ||
|
|
||
| ln, err := sc.ToListener(context.Background()) | ||
| require.NoError(t, err) | ||
|
|
||
| startServer(t, sc, ln, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { | ||
| w.WriteHeader(http.StatusOK) | ||
| })) | ||
|
|
||
| url := "http://" + ln.Addr().String() | ||
|
|
||
| // ExposedHeaders are returned on actual requests, not preflight. | ||
| req, err := http.NewRequest(http.MethodGet, url, http.NoBody) | ||
| require.NoError(t, err) | ||
| req.Header.Set("Origin", "http://allowed.com") | ||
|
|
||
| resp, err := http.DefaultClient.Do(req) | ||
| require.NoError(t, err) | ||
| require.NoError(t, resp.Body.Close()) | ||
|
|
||
| assert.Equal(t, "X-Custom-Header, X-Another-Header", resp.Header.Get("Access-Control-Expose-Headers")) | ||
| } | ||
|
|
||
| func TestHTTPServerHeaders(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
|
|
@@ -1146,6 +1179,8 @@ func TestServerUnmarshalYAMLComprehensiveConfig(t *testing.T) { | |
| assert.Equal(t, expectedOrigins, serverConfig.CORS.Get().AllowedOrigins) | ||
| corsHeaders := []string{"Content-Type", "Accept"} | ||
| assert.Equal(t, corsHeaders, serverConfig.CORS.Get().AllowedHeaders) | ||
| exposedHeaders := []string{"X-Request-Id", "X-Trace-Id"} | ||
| assert.Equal(t, exposedHeaders, serverConfig.CORS.Get().ExposedHeaders) | ||
| assert.Equal(t, 7200, serverConfig.CORS.Get().MaxAge) | ||
|
|
||
| // Verify response headers | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CORSConfiggainedExposedHeaders, but the package’sconfig.schema.yamlstill definescors_configwithout anexposed_headersproperty. This will make the new setting invisible/invalid for schema-driven tooling. Updateconfig/confighttp/config.schema.yamlto includeexposed_headers(type array of strings) with a matching description.