question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Javalin doesn't send content length for static files

See original GitHub issue

Actual behavior (the bug) Javalin sends the following headers for static files:

HTTP/1.1 200 OK                                                                                                                                                         
Date: Sat, 07 Mar 2020 00:49:12 GMT                                                                                                                                     
Server: Javalin                                                                                                                                                         
Cache-Control: max-age=0                                                                                                                                                
Last-Modified: Thu, 05 Mar 2020 18:41:48 GMT                                                                                                                            
ETag: W/"IrppwYhEcFYIrposSZrYkI"                                                                                                                                        
Accept-Ranges: bytes                                                                                                                                                    
Transfer-Encoding: chunked
FILE HERE

Expected behavior Should send a content length header as well

To Reproduce Create a Javalin server and serve a static file from it.

Additional context Breaks file downloads on everything but Chrome.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
vn7n24fzkqcommented, Apr 15, 2020

Seems Jetty will use chunked if http version is 1.1 or outputBufferSize is not enough to put all content in. https://github.com/eclipse/jetty.project/blob/a304fd9f351f337e7c0e2a7c28878dd536149c6c/jetty-http/src/main/java/org/eclipse/jetty/http/HttpGenerator.java#L611 https://github.com/eclipse/jetty.project/blob/a304fd9f351f337e7c0e2a7c28878dd536149c6c/jetty-http/src/main/java/org/eclipse/jetty/http/HttpGenerator.java#L342

If httpConfig.outputBufferSize is larger than static file then it will send content-length

val app = Javalin.create {config->
        config.addStaticFiles("/public")
        config.server {
             val server = Server()

             val httpConfig = HttpConfiguration()
             httpConfig.outputBufferSize = 4*1024
             val sslConnector = ServerConnector(server, getSslContextFactory(),HttpConnectionFactory(httpConfig))
             sslConnector.port = 443
             val connector = ServerConnector(server,HttpConnectionFactory(httpConfig))
             connector.port = 80
             server.connectors = arrayOf<Connector>(connector,sslConnector)
             server
         }
    }.start()

For large file it will allocate too much memory. When I set outputBufferSize = Int.MAX_VALUE


> Task :run
[main] INFO org.eclipse.jetty.util.log - Logging initialized @575ms to org.eclipse.jetty.util.log.Slf4jLog
[main] INFO io.javalin.Javalin - Static file handler added with path=/public and location=CLASSPATH. Absolute path: 'file:///home/vn7n24fzkq/g
ithub/test-jaja/build/resources/main/public/'.
[main] INFO io.javalin.Javalin -
           __                      __ _
          / /____ _ _   __ ____ _ / /(_)____
     __  / // __ `/| | / // __ `// // // __ \
    / /_/ // /_/ / | |/ // /_/ // // // / / /
    \____/ \__,_/  |___/ \__,_//_//_//_/ /_/

        https://javalin.io/documentation

[main] INFO io.javalin.Javalin - Starting Javalin ...
[main] INFO io.javalin.Javalin - Listening on http://localhost:80/
[main] INFO io.javalin.Javalin - Listening on https://localhost:443/
[main] INFO io.javalin.Javalin - Javalin started in 742ms \o/
OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000c4b00000, 993001472, 0) failed; error='Not enough space' (errno=12)
0reactions
tipsycommented, May 28, 2020

This has been fixed now!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Javalin doesn't send content length for static files #892 - GitHub
Expected behavior. Should send a content length header as well. To Reproduce Create a Javalin server and serve a static file from it....
Read more >
Documentation - A lightweight Java and Kotlin web framework
Common methods are supported directly on the Javalin class (GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS), uncommon operations (TRACE, CONNECT) are supported ...
Read more >
javalin-io/general - Gitter
Hello, I am trying to deploy a Javalin application to Heroku. ... load balancer that is sitting in front of the Java process...
Read more >
Jersey response: don't set Content-Length header if Transfer ...
@GET @Path("/path") public static Response get( @Context UriInfo uriinfo, @Context HttpHeaders httpHeaders, byte[] body ) throws Exception{ // ...
Read more >
Using OpenAPI and Swagger UI - Quarkus
The static file to serve must be a valid document conforming to the OpenAPI ... OK - fruits list content: application/json: {} post:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found