Add GNU Terry Pratchett to your Spring Boot 3.0 project

Add GNU Terry Pratchett to your Spring Boot 3.0 project

Add GNU Terry Pratchett to your Spring Boot 3.0 project

No Comments on Add GNU Terry Pratchett to your Spring Boot 3.0 project 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!

Related Posts

Leave a Reply

Back to Top