[undertow-dev] ResourceHandler give 0 byte Content-Length for HEAD

Bernd Eckenfels ecki at zusammenkunft.net
Fri Mar 13 15:47:20 EDT 2015


Hello,

with all versions I tried (including 1.2.0.Beta9) undertow-core will
return content-length: 0 if a HEAD request is made.

I am using a simple handler:

        FileResourceManager frm = new FileResourceManager(new File(".").getCanonicalFile(), 16*1024);
        ResourceHandler res = new ResourceHandler();
        res.setResourceManager(frm);
        res.setAllowed(Predicates.truePredicate());
        res.setDirectoryListingEnabled(true);
        PathHandler path = Handlers.path(errorHandler);
        path.addPrefixPath("/res", res);
        GracefulShutdownHandler shutdownHandler = Handlers.gracefulShutdown(path);
        Undertow server = Undertow.builder().addHttpListener(8080, null)
                        .setServerOption(UndertowOptions.RECORD_REQUEST_START_TIME, Boolean.TRUE)
                        .setServerOption(UndertowOptions.ALWAYS_SET_DATE, Boolean.TRUE) // default
                        .setWorkerThreads(2).setHandler(shutdownHandler).build();
        server.start();

If I request the GET method the content is found:

curl -v http://localhost:8080/webdav/pom.xml
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /res/pom.xml HTTP/1.1
> User-Agent: curl/7.30.0
> Host: localhost:8080
> Accept: */*
>
< HTTP/1.1 200 OK
< Connection: keep-alive
< Last-Modified: Fri, 13 Mar 2015 19:24:58 GMT
< Content-Length: 1155
< Content-Type: text/xml
< Date: Fri, 13 Mar 2015 19:39:24 GMT
<
...
curl -v -XHEAD http://localhost:8080/webdav/pom.xml
* Connected to localhost (127.0.0.1) port 8080 (#0)
> HEAD /webdav/pom.xml HTTP/1.1
> User-Agent: curl/7.30.0
> Host: localhost:8080
> Accept: */*
>
< HTTP/1.1 200 OK
< Connection: keep-alive
< Last-Modified: Fri, 13 Mar 2015 19:24:58 GMT
< Content-Length: 0
< Content-Type: text/xml
< Date: Fri, 13 Mar 2015 19:40:51 GMT
<
* Connection #0 to host localhost left intact

According to RFC2616 sc 14.13 this needs to be non-null.



More information about the undertow-dev mailing list