Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 删除“;“到期”;HTTP标头(用于流文件)_Java_Micronaut - Fatal编程技术网

Java 删除“;“到期”;HTTP标头(用于流文件)

Java 删除“;“到期”;HTTP标头(用于流文件),java,micronaut,Java,Micronaut,在micronaut过滤器中,我指定自己的标题,例如。G我使用“max age”指令设置“Cache Control”头。因此,我想删除“Expires”头,因为通过使用“Cache Control”忽略“Expires”头 从筛选器返回StreamedFile时,“Expires”和“Date”标题由FileTypeHandler设置,我不知道如何更改 有没有办法改变这一点 例如: @Filter("/**") public class MyFilter implement

在micronaut过滤器中,我指定自己的标题,例如。G我使用“max age”指令设置“Cache Control”头。因此,我想删除“Expires”头,因为通过使用“Cache Control”忽略“Expires”头

从筛选器返回StreamedFile时,“Expires”和“Date”标题由FileTypeHandler设置,我不知道如何更改

有没有办法改变这一点

例如:

@Filter("/**")
public class MyFilter implements HttpServerFilter {

    @Inject
    ImageService imageService;

    @Override
    public Publisher<MutableHttpResponse<?>> doFilter(HttpRequest<?> request, ServerFilterChain chain) {
        File image = imageService.getImage(request);

        return Publishers.just(
                HttpResponse.ok(new StreamedFile(new FileInputStream(image), MediaType.IMAGE_JPEG_TYPE))
                        .header("Cache-Control", "max-age=31449600")
                        .header("Access-Control-Allow-Methods", "GET")
                        .header("Referrer-Policy",  "same-origin")
        );
    }

}
@过滤器(“/**”)
公共类MyFilter实现HttpServerFilter{
@注入
影像服务影像服务;
@凌驾

public Publisher不确定为什么要从筛选器返回文件

如果只是您标识的方法妨碍您生成此标头,您可以直接覆盖它:

@Singleton
@替换(FileTypeHandler.class)
公共类CustomFileTypeHandler扩展FileTypeHandler{
公共CustomFileTypeHandler(FileTypeHandler配置){
超级(配置);
}
@凌驾
受保护的void setDateAndCacheHeaders(可变HttpResponse响应,long lastModified){
//无所事事
}
}

谢谢,这很有效。我想控制器当然会更好。我发现我可以使用“@controller({+path}”),因为“/**”在控制器注释中不起作用。