Add GNU Terry Pratchett to your Spring Boot 3.0 project
April 11, 2023
written by Hylke
Hi, after adding GNU to our Symfony project, I was wondering if it would be just as simple to add to a Spring Boot project, and I found out, it is!
All we need is to add one little file, I’ve named mine XClacksOverhead, but you are free to come up with your own name
import java.io.IOException;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;
@Component
public class XClacksOverhead extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
response.setHeader("X-Clacks-Overhead", "GNU Terry Pratchett");
filterChain.doFilter(request, response);
}
}
And there you go, that’s all there is to it!
Leave a Reply