package com.iqser.red.service.persistence.management.v1.processor.configuration;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.AsyncHandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

@Configuration
public class WebConfiguration implements WebMvcConfigurer {

    private static final int TIMEOUT = 600000; // 10 minutes timeout;

    @Override
    public  void addInterceptors(InterceptorRegistry registry) {

        registry.addInterceptor(new AsyncHandlerInterceptor() {
            @Override
            public void afterConcurrentHandlingStarted(HttpServletRequest request,
                                                       HttpServletResponse response, Object handler) {
                request.getAsyncContext().setTimeout(TIMEOUT);
            }
        });
    }
}
