Skip to content

Commit 028fdb0

Browse files
alnrclaude
andcommitted
fix(client): send Ory-RateLimit-Action header on project HTTP client
The ORY_RATE_LIMIT_HEADER value was only attached to the Ory Network SDK client, not to the project HTTP client used by the wrapped Ory Kratos and Ory Hydra admin CLI commands (identity import/get/list, etc.). As a result those admin API calls were still subject to rate limiting during E2E tests. Attach the header to the project HTTP client too. No-op unless the env var is set. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 2f39e16 commit 028fdb0

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

cmd/cloudx/client/http_client.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,18 @@ func newOAuth2TokenClient(token oauth2.TokenSource) *http.Client {
1919
Timeout: time.Second * 30,
2020
}
2121
}
22+
23+
// setHeaderTransport sets a fixed header on every outgoing request. It is used
24+
// to attach the Ory-RateLimit-Action header (see ORY_RATE_LIMIT_HEADER) to the
25+
// project HTTP client so that admin API calls issued by the wrapped Ory Kratos
26+
// and Ory Hydra CLI commands are not rate limited during E2E tests.
27+
type setHeaderTransport struct {
28+
base http.RoundTripper
29+
key, value string
30+
}
31+
32+
func (t *setHeaderTransport) RoundTrip(req *http.Request) (*http.Response, error) {
33+
req = req.Clone(req.Context())
34+
req.Header.Set(t.key, t.value)
35+
return t.base.RoundTrip(req)
36+
}

cmd/cloudx/client/sdks.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ func (h *CommandHelper) newProjectHTTPClient(ctx context.Context) (*http.Client,
125125
Base: c.Transport,
126126
Source: tokenSource,
127127
}
128+
if rateLimitHeader != "" {
129+
c.Transport = &setHeaderTransport{base: c.Transport, key: "Ory-RateLimit-Action", value: rateLimitHeader}
130+
}
128131

129132
return c, baseURL, nil
130133
}

0 commit comments

Comments
 (0)