Giter Club home page Giter Club logo

http4s-jetty's Introduction

Http4s Build Status Maven Central Typelevel library Cats friendly

Http4s is a minimal, idiomatic Scala interface for HTTP services. Http4s is Scala's answer to Ruby's Rack, Python's WSGI, Haskell's WAI, and Java's Servlets.

val http = HttpRoutes.of {
  case GET -> Root / "hello" =>
    Ok("Hello, better world.")
}

Learn more at http4s.org.

If you run into any difficulties please enable partial unification in your build.sbt (not needed for Scala 2.13 and beyond, because Scala 2.13.0+ has partial unification switched on by default)

scalacOptions ++= Seq("-Ypartial-unification")

Requirements

Running the blaze backend requires a modern, supported version of the JVM to build and run, as it relies on server APIs unavailable before JDK8u252. Any JDK newer than JDK8u252, including 9+ is supported.

Code of Conduct

http4s is proud to be a Typelevel project. We are committed to providing a friendly, safe and welcoming environment for all, and ask that the community adhere to the Scala Code of Conduct.

License

This software is licensed under the Apache 2 license, quoted below.

Copyright 2013-2021 http4s [https://http4s.org]

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

[http://www.apache.org/licenses/LICENSE-2.0]

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Acknowledgments

YourKit

Special thanks to YourKit for supporting this project's ongoing performance tuning efforts with licenses to their excellent product.

http4s-jetty's People

Contributors

aeons avatar amiguez avatar armanbilge avatar bplommer avatar christopherdavenport avatar cquiroz avatar danicheg avatar guizmaii avatar hamnis avatar http4s-steward[bot] avatar igosuki avatar indiscriminatecoding avatar luisdeltoro avatar m-sp avatar mergify[bot] avatar nigredo-tori avatar peterbecich avatar richashworth avatar rnd4222 avatar rossabaker avatar satorg avatar scala-steward avatar taig avatar vasilmkd avatar yanns avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

http4s-jetty's Issues

idleTimeout does not work with Jetty backend

When a service yields a task that takes a long time to produce a response (see /slow in the code below), the Blaze backend will drop the socket after idleTimeout has elapsed. The Jetty backend:

  1. Keeps the connection open for 30 seconds, ignoring idleTimeout.
  2. Then returns a 200 OK with no body.
import scala.concurrent.duration._

import scalaz.concurrent._

import org.http4s.dsl._
import org.http4s.server._

object JettyTest extends App {
  val service = HttpService {
    case GET -> Root / "slow" => for {
      _    <- Task.delay { Thread.sleep(45*1000) }
      resp <- InternalServerError("finally!")
    } yield resp

    case GET -> Root / "fail" => Task.fail(new RuntimeException)
  }

  val js = org.http4s.server.jetty.JettyBuilder
    .withIdleTimeout(1.second)
    .bindHttp(8080, "0.0.0.0")
    .mountService(service)

  val bs = org.http4s.server.blaze.BlazeBuilder
    .withIdleTimeout(1.second)
    .bindHttp(8180, "0.0.0.0")
    .mountService(service)

  js.run
  bs.run
}

Using http4s 0.8.2.

Router handling prefix incorrectly when using Jetty server

If I use a Router where the prefix includes a forward slash, I would expect the whole prefix to be stripped from the request before matching on the inner routes. More specifically, if I have routes like this:

org.http4s.server.Router(
  "pref-a/pref-b" -> myRoutes
)

And I make a request to pref-a/pref-b/my-resource, I would expect to be able to match Root / "my-resource" within myRoutes.

This appears to work as expected if I use blaze as the server, but if I use jetty it only removes the first segment of the prefix, meaning that I have to match Root / "pref-b" / "my-resource".

Not sure how good a job I did explaining that, so I have reproduced it in this repo. It spins up jetty on 8080 and blaze on 8081 serving the same routes. You can see that we get the expected behaviour from blaze but not from jetty.

Flaky `JettyServerSuite`

==> X org.http4s.jetty.server.JettyServerSuite.ChannelOptions should route requests on the service executor  8.35s java.io.IOException: Server returned HTTP response code: 500 for URL: http://127.0.0.1:40987/thread/routing
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1897)
    at sun.net.www.protocol.http.HttpURLConnection.access$200(HttpURLConnection.java:92)
    at sun.net.www.protocol.http.HttpURLConnection$9.run(HttpURLConnection.java:1487)
    at sun.net.www.protocol.http.HttpURLConnection$9.run(HttpURLConnection.java:1485)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessController.doPrivilegedWithCombiner(AccessController.java:784)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1484)
    at java.net.URL.openStream(URL.java:1093)
    at scala.io.Source$.fromURL(Source.scala:144)
    at org.http4s.jetty.server.JettyServerSuite.$anonfun$get$1(JettyServerSuite.scala:69)
    at blocking @ org.http4s.jetty.server.JettyServerSuite.get(JettyServerSuite.scala:71)
    at map @ org.http4s.jetty.server.JettyServerSuite.$anonfun$new$1(JettyServerSuite.scala:86)
    at flatMap @ munit.CatsEffectAssertions.assertIO(CatsEffectAssertions.scala:52)

https://github.com/http4s/http4s/runs/4141739369?check_suite_focus=true

Jetty client sometimes uses chunked transfer encoding for GET requests

When sending a GET request (no body) using the Jetty client sometimes it sends multiple network-level requests and uses Transfer-Encoding: chunked. From local testing manually setting content-length to 0 means this issue does not occur.

I've tried to produce a test with TestContext from cats-effect but trying to use the Jetty client leads to a deadlock (I can create it and tear it down with no issues).

If I had to guess I would say this is due to a race between the Jetty request being sent and the content for that request being populated, the lines are here:

https://github.com/http4s/http4s/blob/30798ab62e4d4739249692e7e80a8831654aa28a/jetty-client/src/main/scala/org/http4s/client/jetty/JettyClient.scala#L28

If the request sends (jReq.send(rl)) before the delayed content has written (dcp.write(req), dcp is a StreamRequestContentProvider) the request will be chunked.

Possibly just inverting these lines might mean the race is less likely? Unless are that way around for a reason (send before write).

http4s version: 0.21.0-M5. Sorry, only just realised this isn't the latest but I think there have been no changes between versions.

Function to configure HttpConfiguration

We can bring our own HttpConfiguration, but we can't configure the one that's there. JettyBuilder should have something like:

transformJettyHttpConfiguration(f: HttpConfiguration => HttpConfiguration)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.