Skip to content

How to do the following tasks in a WebFilter? #10242

@asarkar

Description

@asarkar

I've a WebFilter in a functional web app where I want to do the following. Unfortunately, the Javadoc is reminiscent of this, and the more I try, the more I get the application messed up.

  1. Session management - Create if one doesn't already exist. I'm getting the session out of ServerWebExchange and calling isStarted on it - is this the way?
  2. Send redirect without processing rest of the filter chain - I'm setting a Location header in the response and status 307, then calling setComplete, but the desired endpoint is never invoked.
  3. Set request headers - I want to set a request header. Following is how I'm doing it which seems overly complicated for such a simple task.
val modifiedExchange = exchange.mutate().request(
     exchange.request.mutate().header(SESSION_ID, sessionId).build())
    .build()
    .also { it.response.beforeCommit { session.save() } }

chain.filter(modifiedExchange)

1 and 2 are suited for Spring security, but then, I couldn't find any docs for using that with the functional model.

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: stackoverflowA question that's better suited to stackoverflow.com

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions