Skip to content

Support callable ingress_headers for per-request context propagation#11

Merged
igalshilman merged 1 commit into
restatedev:mainfrom
yshaul:callable-headers
May 15, 2026
Merged

Support callable ingress_headers for per-request context propagation#11
igalshilman merged 1 commit into
restatedev:mainfrom
yshaul:callable-headers

Conversation

@yshaul
Copy link
Copy Markdown
Contributor

@yshaul yshaul commented May 14, 2026

Summary

Allow Config#ingress_headers and #admin_headers to accept a callable (Proc, Lambda, or any object responding to #call) in addition to a static Hash. The callable is evaluated each time Restate.client is built.

Motivation

Frameworks like Rails need to inject per-request headers (team context, shard routing, auth tokens) that vary by caller context. A static Hash configured at boot time can't capture this. A callable evaluated at Restate.client call time solves this cleanly:

Restate.configure do |c|
  c.ingress_url = "http://restate:8080"
  c.ingress_headers = -> {
    { "X-Team-Id" => Current.team_id, "X-Shard" => Current.shard }
  }
end

# Later, in a request context:
Restate.client.service(MyService).do_work(args)
# => headers are resolved fresh with the current request's team/shard

Changes

  • lib/restate.rbRestate.client now calls resolve_headers which invokes .call on callable values, or passes Hashes through unchanged.
  • lib/restate/config.rb — Updated RDoc on ingress_headers and admin_headers to document the callable option with examples.
  • spec/callable_headers_spec.rb — 8 new tests covering: static Hash passthrough, lambda/Proc evaluation per client call, fresh evaluation on each call, mixed static+callable, and arbitrary #call responders.
  • spec/introspection_spec.rb — Updated the test-local Restate.client stub to use the same resolution logic.

Backward Compatibility

Fully backward compatible — existing static Hash configs continue to work unchanged. The respond_to?(:call) check only activates for callable values.

Made with Cursor

…ntext

Allow Config#ingress_headers and #admin_headers to accept a callable
(Proc/Lambda/any #call responder) in addition to a static Hash. The
callable is evaluated each time Restate.client is built, enabling
frameworks like Rails to inject per-request context headers (team ID,
shard routing, auth tokens) that vary by caller context.

Co-authored-by: Cursor <cursoragent@cursor.com>
@igalshilman igalshilman merged commit 936f44d into restatedev:main May 15, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants