- 
    Bug 
- 
    Resolution: Fixed
- 
     P4 P4
- 
    8, 11, 12
- 
        b15
- 
        generic
- 
        generic
- 
        Verified
| Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build | 
|---|---|---|---|---|---|---|
| JDK-8212693 | 11.0.2 | Michael McMahon | P4 | Resolved | Fixed | b02 | 
                    A DESCRIPTION OF THE PROBLEM :
This violates RFC7230:
- "A server MUST NOT send a Content-Length header field in any response
with a status code of 1xx (Informational) or 204 (No Content)."
and com.sun.net.httpserver.HttpExchange#sendResponseHeaders JavaDocs:
- "if {@literal <= -1}, then no response body length is specified and no response body may be written."
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached source code and then:
curl -i "http://localhost:8000/"
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
HTTP/1.1 204 No Content
Date: Sun, 30 Sep 2018 17:08:29 GMT
ACTUAL -
HTTP/1.1 204 No Content
Date: Sun, 30 Sep 2018 17:08:29 GMT
Content-length: 0
---------- BEGIN SOURCE ----------
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import java.io.IOException;
import java.net.InetSocketAddress;
public class Test {
public static void main(String[] args) throws Exception {
HttpServer server = HttpServer.create(new InetSocketAddress(8000), 0);
server.createContext("/", new MyHandler());
server.setExecutor(null);
server.start();
}
static class MyHandler implements HttpHandler {
@Override
public void handle(HttpExchange t) throws IOException {
t.sendResponseHeaders(204, -1);
}
}
}
---------- END SOURCE ----------
FREQUENCY : always
            
This violates RFC7230:
- "A server MUST NOT send a Content-Length header field in any response
with a status code of 1xx (Informational) or 204 (No Content)."
and com.sun.net.httpserver.HttpExchange#sendResponseHeaders JavaDocs:
- "if {@literal <= -1}, then no response body length is specified and no response body may be written."
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached source code and then:
curl -i "http://localhost:8000/"
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
HTTP/1.1 204 No Content
Date: Sun, 30 Sep 2018 17:08:29 GMT
ACTUAL -
HTTP/1.1 204 No Content
Date: Sun, 30 Sep 2018 17:08:29 GMT
Content-length: 0
---------- BEGIN SOURCE ----------
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import java.io.IOException;
import java.net.InetSocketAddress;
public class Test {
public static void main(String[] args) throws Exception {
HttpServer server = HttpServer.create(new InetSocketAddress(8000), 0);
server.createContext("/", new MyHandler());
server.setExecutor(null);
server.start();
}
static class MyHandler implements HttpHandler {
@Override
public void handle(HttpExchange t) throws IOException {
t.sendResponseHeaders(204, -1);
}
}
}
---------- END SOURCE ----------
FREQUENCY : always
- backported by
- 
                    JDK-8212693 com.sun.net.httpserver.HttpServer returns Content-length header for 204 response code -           
- Resolved
 
-         
- relates to
- 
                    JDK-8211437 java.net.http.HttpClient hangs on 204 reply without Content-length 0 -           
- Closed
 
-         
- 
                    JDK-8211858 java.net.http.HttpClient fails to timely recognize 204 response -           
- Closed
 
-