From 65e4bd28fd50b4894c3ed0c2dad5beddf022bc26 Mon Sep 17 00:00:00 2001 From: Ruan Kunliang Date: Tue, 28 Feb 2023 21:11:23 +0800 Subject: [PATCH] allow custom Content-Length for HEAD method --- .../jersey/netty/httpserver/NettyResponseWriter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/containers/netty-http/src/main/java/org/glassfish/jersey/netty/httpserver/NettyResponseWriter.java b/containers/netty-http/src/main/java/org/glassfish/jersey/netty/httpserver/NettyResponseWriter.java index e2a4931bb8..97a0da6ecf 100644 --- a/containers/netty-http/src/main/java/org/glassfish/jersey/netty/httpserver/NettyResponseWriter.java +++ b/containers/netty-http/src/main/java/org/glassfish/jersey/netty/httpserver/NettyResponseWriter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2019 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2023 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -105,7 +105,7 @@ public synchronized OutputStream writeResponseStatusAndHeaders(long contentLengt if (contentLength == -1) { HttpUtil.setTransferEncodingChunked(response, true); - } else { + } else if (req.method() != HttpMethod.HEAD || !response.headers().contains(HttpHeaderNames.CONTENT_LENGTH)) { response.headers().set(HttpHeaderNames.CONTENT_LENGTH, contentLength); }