by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 12:17
    scala-steward opened #3637
  • 06:53
    scala-steward opened #442
  • 06:51
    scala-steward opened #3636
  • 06:51
    scala-steward opened #3635
  • 06:48
    scala-steward opened #432
  • 04:33

    rossabaker on gh-pages

    updated site (compare)

  • 04:30

    rossabaker on gh-pages

    updated site (compare)

  • 04:25

    rossabaker on v1.0.0-M4

    (compare)

  • 04:24

    rossabaker on master

    Release notes for v1.0.0-M4 Merge pull request #3632 from r… (compare)

  • 04:24
    rossabaker closed #3632
  • 04:20
    scala-steward opened #441
  • 04:17

    rossabaker on gh-pages

    updated site (compare)

  • 04:13

    rossabaker on gh-pages

    updated site (compare)

  • 04:10

    rossabaker on gh-pages

    updated site (compare)

  • 04:08
    rossabaker ready_for_review #3632
  • 04:08
    rossabaker synchronize #3632
  • 04:06
    rossabaker closed #3565
  • 04:06

    rossabaker on master

    Update dsl.md As `Year.of` can… Bring Client Request/Response M… Add tests for error and cancela… and 30 more (compare)

  • 04:04

    rossabaker on gh-pages

    updated site (compare)

  • 04:01

    rossabaker on gh-pages

    updated site (compare)

gitleet
@gitleet
anyone else getting http4s sbt template errors?
Ashwin Bhaskar
@ashwinbhaskar
is it possible to have a varargs as path parameter in routes? Something like this
case Get -> Root /  foo1 / foo2 / foo3 /../ foon
Ross A. Baker
@rossabaker
@ashwinbhaskar Try /: (right associative) instead of /, and lose the Root:
case Get -> foo1 /: foo2 /: fooRest => // fooRest is a Seq
12 replies
@gitleet No, but it looks like you're on MacOS. Perhaps someone else could try and see if it's a problem there.
@GrafBlutwurst Blaze does not support proxies, though there's a dated, half-baked PR for it. AHC definitely supports it. I think everything but Blaze and maybe Ember do. All of the other backends delegate to other backends instead of being from scratch, and would get their proxy support through that.
Ross A. Baker
@rossabaker
@Taig It's CPU bound, so if you use global for your CPU-bound work, it's a good choice. A fixed pool is theoretically better. I've never measured a significant win, but Daniel Spiewak has measured dramatic wins in other contexts, and has good theoretical justification for it.
Exposing that parameter has caused a lot of confusion, and it's regrettable that it's there at all: it leaks an implementation detail of blaze. The reason we don't default it to global is that a lot of cats-effect apps carefully avoid initializing the global pool. But if that doesn't bother you, it's probably a fine choice.
Dominic Egger
@GrafBlutwurst
@rossabaker yeah i am playing with AHC now and it works-ish I am actually hitting this particular isseus (but only in testing, it seems to work fine when i just deploy the service and work with it) http4s/http4s#3527 I'm currenlty throwing ideas at the proverbial wall and see what sticks to figure out what is causing this
Dominic Egger
@GrafBlutwurst
well in my case it was improper usage of Resource that so happened to work with BlazeClient but not AHC
Christopher Davenport
@ChristopherDavenport
All these threads have me completely lost. Please try to avoid them.
Ross A. Baker
@rossabaker
Sorry, I participated in a thread without realizing what I'd done.
I have been one of the leading whiners about them on the phone, and blindly did it in the browser.
Christopher Davenport
@ChristopherDavenport
It really would be fine if phone had any support for the
amesgen
@amesgen
@GrafBlutwurst If you are still looking for a backend with proxy support: https://jdk-http-client.http4s.org/stable/#custom-clients
Ross A. Baker
@rossabaker
We desperately need to build that matrix of feature support.
If the JDK11 requirement doesn't bother you, that one ticks most of the rest of the boxes.
Gavin Bisesi
@Daenyth
I think I opened a ticket about that
Ross A. Baker
@rossabaker
I think so, too.
I think I've been furiously treading water just reviewing all the (good!) PRs.
vmanpuria
@vmanpuria
Hi Folks - I am new to http4s. I have noticed that with a large payload (over 6k bytes), https connections are being shutdown after the response is processed. I am using an Http Blaze client with connection pool. The http protocol version is 1.1.
With smaller payloads (like 3kb payloads), the https connection stays alive and is re-usable for the next https call. With larger payloads, the connection is being shutdown by http4s client.
Kai(luo) Wang
@kailuowang
Is there a solution for doing more advanced form data parsing in http4s like this former decoder in Play https://www.playframework.com/documentation/2.8.x/ScalaForms?
Christopher Davenport
@ChristopherDavenport
Presently there's UrlForm which you should be able to validate. Not sure from the top level what advanced decoder behavior your referring to. But you can do very cool things with http4s UrlForms.
@vmanpuria That seems like perhaps an idle timeout bug. If you could create an issue with the logs on highest level when it occurs we can try to figure out what's killing the connection.
Kai(luo) Wang
@kailuowang
@ChristopherDavenport I'll take another look at UrlForm I thought all it can do is to parse the body to Map[String, Chain[String]].
Here is an example of more advanced decoder in play, the Form in play can decode into ADTs like this
val userFormNested: Form[UserAddressData] = Form(
  mapping(
    "name" -> text,
    "address" -> mapping(
      "street" -> text,
      "city"   -> text
    )(AddressData.apply)(AddressData.unapply)
  )(UserAddressData.apply)(UserAddressData.unapply)
)
vmanpuria
@vmanpuria
@ChristopherDavenport - Thanks. I have created an issue with logs: http4s/http4s#3628
Christopher Davenport
@ChristopherDavenport
@kailuowang I can have a lib up by tomorrow if what's there isn't nice enough. That one a fairly straightforward to make happen if you want me to throw something together.
Saif Addin
@saif-ellafi
Hi
I am making a very simple webserver, and I am getting a CORS issue on the browser, while making a GET request from ajax
I have did this but no luck:
    HttpRoutes.of[IO] {
      case GET -> Root / "employees" =>
        try {
          val answer = queries.getEmployees
          Ok(Json.obj(("employees", answer.map(_.asJson).asJson)))
            .map(_.putHeaders(Header("Origin", "*")))
        }
sherzod
@sherzodv
@saif-ellafi You can use CORS middleware to allow access from any origin
Saif Addin
@saif-ellafi
Thanks, I am trying to follow and understand the docs.
But the examples are valid only if making the requests from http4s itself
My service kickstarter looks like this:
  def stream(managementRoutes: ManagementRoutes)(implicit T: Timer[IO], C: ContextShift[IO]): Stream[IO, Nothing] = {
    for {
      _ <- BlazeClientBuilder[IO](global).stream

      service = managementRoutes.getTransportInformation
      corsService = CORS(service, methodConfig)
      httpApp = corsService.orNotFound

      finalHttpApp = Logger.httpApp(true, true)(httpApp)

      exitCode <- BlazeServerBuilder[IO](global)
        .bindHttp(8080, "0.0.0.0")
        .withHttpApp(finalHttpApp)
        .serve
    } yield exitCode
  }.drain
3 replies
with
  private val methodConfig = CORSConfig(
    anyOrigin = true,
    anyMethod = false,
    allowedMethods = Some(Set("GET", "POST")),
    allowCredentials = true,
    maxAge = 1.day.toSeconds)
and then my end point routes are:
    HttpRoutes.of[IO] {
      case GET -> Root / "employees" =>
        try {
          val answer = queries.getEmployees
          Ok(Json.obj(("employees", answer.map(_.asJson).asJson)))
            .map(_.putHeaders(Header("Origin", "localhost")))
        }
        catch {
          case e: Throwable =>
            println(e.getMessage)
            InternalServerError(s"Something went wrong:\n${e.getMessage}")
        }
5 replies
and I get
Access to XMLHttpRequest at 'localhost:8080/employees' from origin 'http://localhost:63342' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome-extension, edge, https.
So I used middleware to start the service with cors configuration, and added the Origin header response in my /employees route
Saif Addin
@saif-ellafi
Thanks, I must be doing something else wrong. I am getting a error status code 0 on the browser. Must be something really silly
13 replies
$(document).ready(function(){
    $.ajax({
        url: 'localhost:8080/employees',
        type: 'GET',
        success: function (response) {
            console.log("Hello");
            console.log(response);
            var trHTML = '';
            $.each(response, function (i, employee) {
                trHTML += '<tr><td>' + employee.name + '</td><td>' + employee.created + '</td><td>' + employee.modified + '</td></tr>';
            });
            $('#employees').append(trHTML);
        },
        error: function (xhr, status, error) {
            console.log(xhr.status);
            console.log(xhr.statusText);
        }
    });
});
Kai(luo) Wang
@kailuowang
HI @ChristopherDavenport thanks so much for your offering. I didn't mean to request a feature though. Just thought that there might be already a solution before I ask someone to hold my beer. I'd love to submit a PR, is that something worth adding to http4s?
Henri Cook
@henricook
image.png
Sorry to ask something I think must have been asked before, but I seem unable to google it. I've got a play JSON JsValue that I want to POST with an http4s Client the first stumbling block is that it seems impossible to figure out what POST accepts as parameters in this example, it's so obfuscated that I don't seem to be able to find it and neither can IntelliJ!
Do I have to use circe to convert it? I'd rather just chuck it in as a string with a json content-type tbh if that's the case

Oop, found an old project where i'd done it. I needed this custom dsl for monix Task:

object task extends Http4sClientDsl[Task]
and:
import org.http4s.play._
from: "org.http4s" %% "http4s-play-json" % http4sVersion,

I couldn't find anything in the docs on how to do this

Henri Cook
@henricook
And I still don't know how to see the definition of POST's params :sweat_smile:
Paul Snively
@paul-snively
@henricook: What does the squiggle indicate?
Gabriel Volpe
@gvolpe
@henricook rewriting it temporarily as POST.apply will show you the expected arguments
Paul Snively
@paul-snively
@henricook: It's likely you're missing an import to get the EntityEncoder instance for JsValue.