spinoco / fs2-http Goto Github PK
View Code? Open in Web Editor NEWHttp Server and client using fs2
License: MIT License
Http Server and client using fs2
License: MIT License
Hi guys!
I've tried to use client as it shown in README and find out that bodyAsString
is waiting connection closing (end of stream). My server doesn't close connection by itself, it waiting closing by client. I've write some code to show what I mean.
val request = HttpRequest.get[Task](Uri.https("fomkin.org", "/hello-world.txt"))
val startTime = System.currentTimeMillis
client.request(request).flatMap { resp =>
val task = resp.body.runFold(ByteBuffer.allocate(resp.bodySize.get.toInt)) {
case (buffer, byte) =>
val t = System.currentTimeMillis - startTime
println(s"${t}ms: ${byte.toChar}")
buffer.put(byte)
buffer
}
Stream.eval(task)
}.runLog.map { xs =>
val t = System.currentTimeMillis - startTime
println(s"${t}ms: --")
println(xs.map(x => new String(x.array())))
}
It prints something like
1033ms: H
1033ms: e
1033ms: l
1033ms: l
1033ms: o
1033ms:
1033ms: W
1033ms: o
1033ms: r
1033ms: l
1033ms: d
6624ms: --
Hello World
Last two line prints only when I reboot nginx.
Can't seem to make the little client example from the README to work.
I'd need to use fs2-http with fs2 v2.0.0, but I'm getting the following runtime error:
Exception in thread "specs2.user-14" java.lang.NoSuchMethodError: fs2.io.tcp.package$.client$default$2()Z
at spinoco.fs2.http.websocket.WebSocket$.$anonfun$client$1(WebSocket.scala:98)
at spinoco.fs2.http.websocket.WebSocket$.$anonfun$client$1$adapted(WebSocket.scala:97)
at fs2.Stream$.$anonfun$flatMap$1(Stream.scala:1091)
at fs2.internal.FreeC$$anon$1.cont(FreeC.scala:31)
at fs2.internal.FreeC$ViewL$$anon$9$$anon$10.cont(FreeC.scala:239)
at fs2.internal.FreeC$ViewL$.mk(FreeC.scala:228)
at fs2.internal.FreeC$ViewL$.apply(FreeC.scala:220)
at fs2.internal.FreeC.viewL(FreeC.scala:77)
at fs2.internal.Algebra$.fs2$internal$Algebra$$go$1(Algebra.scala:228)
at fs2.internal.Algebra$$anon$2.$anonfun$out$1(Algebra.scala:279)
at fs2.internal.Algebra$.$anonfun$compileLoop$1(Algebra.scala:247)
at cats.effect.internals.IORunLoop$.cats$effect$internals$IORunLoop$$loop(IORunLoop.scala:139)
at cats.effect.internals.IORunLoop$RestartCallback.signal(IORunLoop.scala:355)
at cats.effect.internals.IORunLoop$RestartCallback.run(IORunLoop.scala:366)
at cats.effect.internals.Trampoline.cats$effect$internals$Trampoline$$immediateLoop(Trampoline.scala:70)
at cats.effect.internals.Trampoline.startLoop(Trampoline.scala:36)
at cats.effect.internals.TrampolineEC$JVMTrampoline.super$startLoop(TrampolineEC.scala:93)
at cats.effect.internals.TrampolineEC$JVMTrampoline.$anonfun$startLoop$1(TrampolineEC.scala:93)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
...
this is with v0.4.1.
Failed to decode value: cannot acquire 16526844176 bits from a vector that contains 728 bits, content: ByteVector(95 bytes, 0x7b2274223a6e756c6c2c2273223a6e756c6c2c226f70223a31302c2264223a7b226865617274626561745f696e74657276616c223a34313235302c225f7472616365223a5b22676174657761792d7072642d6d61696e2d6b673677225d7d7d)
at spinoco.fs2.http.websocket.WebSocket$impl$.decode$1(WebSocket.scala:323)
I'm using websockets here and here.
A test on your end can be done like so:
object Main extends IOApp {
override def run(args: List[String]): IO[ExitCode] = {
implicit val ag = AsynchronousChannelGroup.withThreadPool(Executors.newCachedThreadPool())
Stream
.eval(Queue.unbounded[IO, Event])
.flatMap(queue => {
Client[IO]("TOKEN_HERE") { in =>
in.flatMap(e => {
println(s"Received: $e")
Stream.empty
})
}.login(queue, Sharding.Single())
})
.compile
.drain
.as(ExitCode.Success)
}
}
Replacing TOKEN_HERE
with a Bot token you get from the Discord Developer Console.
in master and series 0.2 (which I hoped to bump to the M8 release of fs2)
! ChunkedEncoding.encode-decode: Falsified after 3 passed tests.
! util.decodes.base64: Falsified after 3 passed tests.
fiddling around a bit with the tests, to give me vectors of code units to have something printable:
[info] > Labels of failing property:
[info] Expected Vector(Right(Vector(62875, 60936, 24080))) but got Vector(Right(Vector(63, 63, 63)))
Note that code unit 63 encodes ?
, and 62875 and 60936 are in the private use area.
When the chunk contains more than one frame, only first one is pulled to stream. Next frames awaits new chunk.
The createSSLEngine
call fails to handshake properly for a lot of smaller websites. Bug Location
This can be fixed by adding a reference to the host and port that is being secured. sslContext.createSSLEngine(host, port)
In websockets, mergeDrainL
has become concurrently
such that a mergeDrainL b
is b concurrently a
.
After receiving close message from a client, server keeps sending ping messages and eventually fails after three unconfirmed attempts. According to RFC it should gracefully close the connection immediately after the close message.
Hi, guys!
I want add this feature to your project. That is my plan:
multipart/form-data
codec to headers packageFormData
type and codec to http protocol packagewithFormData
and bodyAsFormData
methods to HttpRequestOrResponseWhat do you think about it?
Implemented by #37
Could not get a string body: Media Type must be text, but is DefaultMediaType(application,json,true,true,WrappedArray(json))
at org.discordscala.core.util.RequestUtil$.$anonfun$stringBodyFromResponse$2(RequestUtil.scala:64)
at cats.syntax.EitherOps$.leftMap$extension(either.scala:144)
at org.discordscala.core.util.RequestUtil$.$anonfun$stringBodyFromResponse$1(RequestUtil.scala:64)
Hey guys,
I found out about your set of libraries because I recently switched to doobie. Could you create comparison chart that compares fs2-http and akka-http (both client and server side) ? I'm long time user of spray (now akka-http) but I'm always interested if any new frameworks/libraries come up.
I could be looking in the wrong place, but I expected to find a stringify
Op for Uri
.
I assume you must do this somewhere, because you'll construct the string somewhere.
If you change spinoco.fs2.http.internal.HttpClientApp
to hit http://httpbin.org/html
(content length 3741) it will constantly take 60 seconds to complete. Hitting http://httpbin.org/get
(content length ~159) returns in the time you would expect. Chunked responses are unaffected.
Hi,
It looks, that WebSocket client is unable to handle SSL errors, when initial connection has been established. For example, when we connect to non-ssl host with wss:// protocol, client should raise error, but it doesn't (I think, similar problem exists for other ssl errors, like untrusted certifcate).
How to reproduce:
edit line:
WebSocketRequest.wss("echo.websocket.org", 80, "/", QueryParameter.single("encoding", "text"))
(use wss method instead of ws and explicitly set port to 80)
and run the test. I would expect, that client will raise error, but actual client will hang forever.
Headers received
Host: localhost:8181
Sec-WebSocket-Key: U3RyZWFtKDIsID8p
Sec-WebSocket-Version: 13
Connection: upgrade
Upgrade: websocket
Base64.decode("U3RyZWFtKDIsID8p") == "Stream(2, ?)"
following the example at https://github.com/Spinoco/fs2-http#http-client and using the 8 lines of imports I am getting
could not find implicit value for parameter AG: java.nio.channels.AsynchronousChannelGroup
[error] http.client[Task]().flatMap { client =>
are you sure this is the full list of imports?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.