Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 06:26
    RaasAhsan commented #5382
  • 05:31
    SevDan starred http4s/http4s
  • 04:59

    rossabaker on 0.23

    Update fs2-core, fs2-io, ... to… Set buffer size to 1 Merge pull request #5406 from s… (compare)

  • 04:59
    rossabaker closed #5406
  • 04:29

    rossabaker on 0.22

    Add upgrade docs over +? goign … Merge pull request #5379 from z… (compare)

  • 04:29
    rossabaker closed #5379
  • 04:27

    rossabaker on 0.22

    Add server connection suite Add TestClient class for reuse scalafmt and 4 more (compare)

  • 04:27
    rossabaker closed #5382
  • 04:24
    rossabaker commented #5382
  • 04:23
    rossabaker synchronize #5431
  • 04:23

    rossabaker on non-trivial-2021-10-20-0.23

    Merge branch 'series/0.22' into… (compare)

  • 04:20
    rossabaker synchronize #5406
  • 04:10
    rossabaker synchronize #5431
  • 04:10

    rossabaker on non-trivial-2021-10-20-0.23

    Merge branch 'series/0.22' into… (compare)

  • 03:07
    rossabaker synchronize #5431
  • 03:07

    rossabaker on non-trivial-2021-10-20-0.23

    Merge branch 'series/0.22' into… (compare)

  • 02:45
    rossabaker opened #5431
  • 02:44

    rossabaker on non-trivial-2021-10-20-0.23

    Merge branch 'series/0.22' into… (compare)

  • 00:53
    rossabaker closed #247
  • 00:53

    rossabaker on 1.0

    http4s-0.21.29 Merge pull request #235 from ht… Merge pull request #236 from ht… and 16 more (compare)

Ross A. Baker
@rossabaker
@jozi-k Have a look at fetch: def fetch[A](req: Request[F])(f: Response[F] => F[A]): F[A]
Julien Truffaut
@julien-truffaut
thanks Ross
Ross A. Baker
@rossabaker
The status codes are extractors, so you can things like case Ok(resp) =>. And there are extractors for the classes, so you can do things like case ClientError(resp) =>. And then you can write something like resp.as[Foo] to decode. expect can be implemented in terms of fetch, in fact.
Jozef Koval
@jozanek
@rossabaker will try that, thanks
David Walend
@dwalend

We're using IO.shift(someIoBoundContext) to get work off of the execution context we use to respond to http requests. I'd like to keep that concern with the io-bound part of the system, and IO.shift back to the calling context after the slow work is done. IO.bracket() seems like the right method . The missing piece is the current execution context.

Is there some API to get the current execution context from IO?

Fabio Labella
@SystemFw
the api you're looking for is evalOn
it will do the shift and shift back for you
that being said, there is a catch: it can only shift back to the "main" EC, i.e. ultimately what you use to back your IOApp. It cannot keep track of several jumps across different ECs
ah, wait though

to get work off of the execution context we use to respond to http requests.

Why are you doing that? is the IO you are dealing with actually blocking?

David Walend
@dwalend

@SystemFw - what will happen if I don't have an IOApp? The system runs in a servlet, so my guess is it'll use the context specified there.

Some parts are blocking (old slick database code - IO.fromFuture), some are more blocking (even older squyril database code - no Future (in so many ways)), some are really blocking (deeply buried http request/responses) and some are ridiculously blocking (http request/response to someone else's system with a 30-second timeout).

But I think IO.evalOn() should do well. I can just take responsibility to always use IO.evalOn() when I want to protect http4s' server from something awful.
David Walend
@dwalend
Is this right? It seems baroque and awkward:
    IO.contextShift(ExecutionContexts.slowExecutionContext).evalOn(ExecutionContexts.slowExecutionContext){
      IO(creakyOldBlockingCode())
    }
Gunnar Lilleaasen
@heksesang
@rossabaker Thanks, I’ll have a look at those. :)
Dmitry Polienko
@nigredo-tori
@dwalend, mostly you just make a ContextShift[IO] once, and pass it everywhere implicitly. Than you just do ContextShift[IO].evalOn(slowExecutionContext)(IO(creakyOldBlockingCode())). Still clunky, but at least the libraries support this style.
David Walend
@dwalend

Thanks @nigredo-tori . "pass it everywhere implicitly" is 9 layers deep in this code base. Implicit cake is too hard to do. (I'm also skeptical of the clarity of the code that would result even if it were feasible.)

Is there any harm in making a new ContextShift precisely where it's used?

Andi Miller
@andimiller
if you want a dedicated EC you're going to need to create it somewhere, and destroy it somewhere
so you might need to still bubble up shutdown methods
David Walend
@dwalend
I currently tunnel it through a scala object, lazy init, shutdown via the servlet.
Dmitry Polienko
@nigredo-tori
@dwalend, since creating ContextShift[IO] is pure - no harm whatsoever. But since you would still need to pass the ExecutionContext somehow, you can just as well add ExecutionContexts.Implicits.contextShiftIO, and use that.
David Walend
@dwalend
Thanks @nigredo-tori . That's the reassurance I needed.
Brian P. Holt
@bpholt

Is there a MediaType literal parser like Uri.uri or do I have to wait until runtime to parse those?

Relatedly, is there an easy way to override the media types used by the JSON codecs? I'm writing a client for an API that uses application/vnd.dwolla.v1.hal+json (and specifically rejects application/json) so I want it to specify that media type as my Content-Type and Accept headers any time I ask for or provide circe Json objects.

(This is in 0.20.0-M6, fwiw)
Darren Gibson
@zarthross
@Tomczik76 There is a release of Rho on the latest Http4s milestone v0.19.0-M7. There should be hardly any changes in the Rho dsl that will require changes. The http4s scalafix will change any http4s specific changes you need made.
Ross A. Baker
@rossabaker
@bpholt There is not a literal macro for that, but I would love to have one. Creating them is messy.
There is jsonOfWithMedia which could help on the decoder side.
And I guess you'd call withContentType on the encoder.
So I suppose don't import the implicits, but forward to those methods with your own implicits for Json, providing your own custom media type.
Brian P. Holt
@bpholt
Ok, thanks. I think that’s pretty much where I ended up.
Gunnar Lilleaasen
@heksesang
It seems one can do either req.as[A] with for yield, or one can do req.decode[A](f) to acheive the same result. Is either of them recommended over the other?
Ross A. Baker
@rossabaker
I think the decode was more Play inspired. I always do as. And .as doesn't need to be in a for comprehension.
Jozef Koval
@jozanek
I would like to add my 2 cents to this cool project. To be more specific I want to implement counter metrics for http status codes. Today, there is bunch of timer metrics and only one counter of active requests. Any feedback is appreciated.
Gavin Bisesi
@Daenyth
@jozi-k I glanced over the metrics middleware before, I think that should be fairly easy to implement
Andi Miller
@andimiller
does it not already do that?
I know the client one buckets into 1xx, 2xx, etc.
to count them
Jozef Koval
@jozanek
@Daenyth yes, should be straightforward
@andimiller currently it does not, there are only Timers for 1xx, 2xx...
Andi Miller
@andimiller
a timer comes with a counter, if it's the dropwizard one
Jozef Koval
@jozanek
I see, will rethink that.
Christopher Davenport
@ChristopherDavenport
@rossabaker How do we presently tell whether the body bites have been read in the client pool for the reuse phase.
I ran, rather accidentally, into the case where I got the body from the last response when I tried the new pool.
Ross A. Baker
@rossabaker
@ChristopherDavenport It's a Resource.
Starts about here
Toby Thain
@toby5box
Has anyone done rich parse error reporting for a JSON library fronting http4s? [i happen to be using Argonaut]
are there hooks or is this a rabbit hole too deep?
toby5box @toby5box pokes around
toby5box @toby5box ponders hm, i guess it's just a custom EntityDecoder…?
Toby Thain
@toby5box
ok , i seem to be blocked here because MessageFailure and all subclasses are sealed
the default impl suppresses any detail of failed parse afaict and i cannot override