Skip to content
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

Support static headers for http interface clients #33309

Closed
hesselapplications opened this issue Aug 3, 2024 · 1 comment
Closed

Support static headers for http interface clients #33309

hesselapplications opened this issue Aug 3, 2024 · 1 comment
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@hesselapplications
Copy link

It would be nice if http interface clients had support for specifying static headers declaratively on a per method basis. Envisioning something similar to what Retrofit has here.

interface RepositoryService {

  // The part to be added
  @RequestHeaders({ 
    "X-Foo: Bar",
    "X-Ping: Pong"
  })
  @GetExchange("/repos/{owner}/{repo}")
  Repository getRepository(@PathVariable String owner, @PathVariable String repo);
	
  // Other http exchange methods with different defaults...

}

Unless I've missed something, I believe the only two ways to supply headers currently are:

  1. Via a @RequestHeader method parameter. Problem being the value must be provided every time
  2. Via global defaults set on the WebClient / RestClient / RestTemplate backing the declarative client. Problem being you may not want to have those headers applied to every call, but rather just those on a particular method

HttpExchange already has support for accept and contentType, so perhaps a generic array of headers could be accepted there as well

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Aug 3, 2024
@snicoll snicoll added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Aug 3, 2024
@simonbasle simonbasle self-assigned this Aug 9, 2024
@simonbasle simonbasle added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Aug 9, 2024
@simonbasle simonbasle added this to the 6.2.0-M7 milestone Aug 9, 2024
@simonbasle
Copy link
Contributor

The @HttpExchange route sounds like a good one. For clients, we can support simple header name-value pairs for each array entry. On the server side, this can be more flexible as this could be translated to a HeadersMappingCondition, similar to what's done with @RequestMapping#headers().

simonbasle added a commit to simonbasle/spring-framework that referenced this issue Aug 9, 2024
On the client side, supports `name=value` pairs. Placeholders in values
are resolved by the `embeddedValueResolver`.
On the server side, additionally supports `name` and `!name` syntax.

Closes spring-projectsgh-33309
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants