How-To/更新 Header 与 Cookie

How-To

How support response header manipulate

support change header value of the response

It's very simple and doesn't require any additional settings.

In your service implementation, you can set the desired response object, including the body and headers. It's super easy to implement!

Implement

Java
private static HttpCookie buildCookie(final String jwt){
  return
          ResponseCookie.from("Authorization",jwt)
                  .path("/")
                  .maxAge(Duration.ofDays(1))
                  .httpOnly(true).build();
}

@Override
public void login(
    final SimpleResultBuilder<LoginResponse> builder, final LoginRequest loginRequest) {
      //...
      builder.body().header(HttpHeaders.SET_COOKIE, buildCookie(jwt).toString());
      //....
}

As demo, we will set cookie in the HTTP response.

😆 Video Guide

  1. ApiHug101-Bilibili
  2. ApiHug101-Youtube
Copyright © 2026 ApiHug·AI-native Enterprise Architecture Factory