Why does Jetty serve css with text / html content type

I am using the embedded Jetty server in a Scalatra application. The problem is that it serves for files csswith a content type text/html:

Here is the main way:

package yard.web

import org.eclipse.jetty.server.Server
import org.eclipse.jetty.webapp.WebAppContext
import org.scalatra.servlet.ScalatraListener

object JettyMain {
  def main(args: Array[String]) {
    val server = new Server(9080)
    val context: WebAppContext = new WebAppContext("src/main/webapp", "/")
    context.setServer(server)
    context.setInitParameter(ScalatraListener.LifeCycleKey, "yard.web.ScalatraBootstrap")
    context.addEventListener(new ScalatraListener())
    server.setHandler(context)

    server.start()

    println("Press ENTER to stop server")
    Console.readLine()
    server.stop()
    server.join()
  }
}

The file is located in src/main/webapp/libs/bootstrap/css/bootstrap.cssand serves with:

$ curl --head http://localhost:9080/libs/bootstrap/css/bootstrap.css
HTTP/1.1 200 OK
Content-Type: text/html;charset=UTF-8
Last-Modified: Sat, 06 Apr 2013 14:30:35 GMT
Content-Length: 127247
Accept-Ranges: bytes
Server: Jetty(8.1.10.v20130312)

Why does Jetty consider this html file?


Here is the class ScalatraBootstrapfor completeness:

package yard.web

import org.scalatra.LifeCycle
import javax.servlet.ServletContext
import yard.Settings
import yard.db.Store

class ScalatraBootstrap extends LifeCycle {
  override def init(context: ServletContext) {

    val settings = Settings.default
    val db = Store(settings).db

    context mount (new MainServlet, "/")
  }
}

Update: use ResourceHandlercauses css to be served with the correct content type. However, the application does not work: (

+2
source share
1 answer

A CSS file is usually served with org.eclipse.jetty.servlet.DefaultServlet.

What is declared in the file etc/webdefault.xmlin the distribution.

, , WebAppContext.setDefaultsDescriptor(String) etc/webdefault.xml.

, , mime DefaultServlet mime.properties, Jetty Classloader.getResource("/org/eclipse/jetty/http/mime.properties").

. mime.properties jetty-http-8.1.10.v20130312.jar.

+5

Source: https://habr.com/ru/post/1547374/


All Articles