BlackSheep icon indicating copy to clipboard operation
BlackSheep copied to clipboard

Routing base on header value

Open thomafred opened this issue 3 years ago • 3 comments

Note: consider using Discussions to open a conversation about new features…

🚀 Feature Request

Hi there!

It would be able to route base on header value of a specific header.

For example:

@get("/my/path/{param}", header={"X-APPLICATION-HEADER": "somevalue"})
def my_handler(request: Request):
  ...

Value patterns could also be cool:

@get("/my/path/{param}", header={"X-APPLICATION-HEADER": "pattern-{matching}"})
def my_handler(request: Request, matching: str):
  ... 

thomafred avatar Dec 15 '22 11:12 thomafred

Hi @thomafred Sorry for taking so long to reply. Currently this is not supported but I like the idea of adding support for routing based on headers.

I am working on version 2 of the framework and related libraries. Right now adding support for dependency injection to authentication handlers and authorization requirements - I also plan to add full support for dependency injection to binders. I can add support for routing based on HTTP headers (including host) and make it part of v2.

Can be related to https://github.com/Neoteroi/BlackSheep/discussions/292

RobertoPrevato avatar Dec 23 '22 09:12 RobertoPrevato

Hi @thomafred Routing based on header value is now available in version 2 (which is still alpha) https://github.com/Neoteroi/BlackSheep/releases/tag/v2.0a5

However, there is no built-in handling of dynamic parameters like in your second example pattern-{matching} - but it is easy to define a custom filter that enables that scenario. I'll document soon all new features and changes introduced with version 2.

RobertoPrevato avatar Apr 02 '23 18:04 RobertoPrevato

Awesome, thank you!

thomafred avatar Apr 11 '23 12:04 thomafred