Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dead references to AsyncStream #1274

Merged
merged 1 commit into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions core/src/test/scala/io/finch/FinchSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import cats.Eq
import cats.data.NonEmptyList
import cats.effect.{Effect, IO}
import cats.instances.AllInstances
import com.twitter.concurrent.AsyncStream
import com.twitter.finagle.http._
import com.twitter.io.Buf
import com.twitter.util._
Expand Down Expand Up @@ -177,14 +176,6 @@ trait FinchSpec extends AnyFlatSpec with Matchers with Checkers with AllInstance
a <- Arbitrary.arbitrary[A]
} yield Output.Payload(a, st, cs, hs, c)

def genAsyncStreamOutput[A: Arbitrary]: Gen[Output[AsyncStream[A]]] = Gen.oneOf(
genEmptyOutput,
for {
(st, cs, hs, c) <- genOutputMeta
a <- Arbitrary.arbitrary[A]
} yield Output.Payload(AsyncStream.of(a), st, cs, hs, c)
)

def genOutput[A: Arbitrary]: Gen[Output[A]] = Gen.oneOf(
genPayloadOutput[A],
genFailureOutput,
Expand Down Expand Up @@ -381,9 +372,6 @@ trait FinchSpec extends AnyFlatSpec with Matchers with Checkers with AllInstance

implicit def arbitraryOutput[A: Arbitrary]: Arbitrary[Output[A]] = Arbitrary(genOutput[A])

implicit def arbitraryAsyncStreamOutput[A: Arbitrary]: Arbitrary[Output[AsyncStream[A]]] =
Arbitrary(genAsyncStreamOutput[A])

implicit def arbitraryRequestItem: Arbitrary[items.RequestItem] =
Arbitrary(genRequestItem)

Expand Down
8 changes: 0 additions & 8 deletions core/src/test/scala/io/finch/ServerSentEventSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package io.finch
import java.nio.charset.{Charset, StandardCharsets}

import cats.Show
import com.twitter.concurrent.AsyncStream
import com.twitter.io.Buf
import io.finch.internal.HttpContent
import org.scalacheck.Gen.Choose
Expand Down Expand Up @@ -51,13 +50,6 @@ class ServerSentEventSpec extends AnyFlatSpec with Matchers with Checkers {
retry <- Choose.chooseLong.choose(-1000, 1000)
} yield sse.copy(retry = Some(retry))

def streamDataOnlyGenerator: Gen[AsyncStream[ServerSentEvent[String]]] = for {
strs <- Gen.nonEmptyListOf(dataOnlySse)
} yield AsyncStream.fromSeq(strs)

implicit def arbitrarySse: Arbitrary[AsyncStream[ServerSentEvent[String]]] =
Arbitrary(streamDataOnlyGenerator)

val encoder = encodeEventStream[String](Show.fromToString)

it should "encode the event when only 'data' is present" in {
Expand Down
23 changes: 1 addition & 22 deletions docs/mdoc/cookbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,26 +85,6 @@ val file: Endpoint[IO, Buf] = get("file") {
content given their _dynamic_ nature. Instead, a static HTTP server (i.e., [Nginx][nginx]) would be
the perfect fit.

It's also possible to _stream_ the file content to the client using [`AsyncStream`][as].

```scala mdoc:silent:nest
import io.finch._
import io.finch.catsEffect._
import com.twitter.conversions.StorageUnitOps._
import com.twitter.concurrent.AsyncStream
import com.twitter.finagle.Http
import com.twitter.io.{Buf, BufReader, Reader}

import java.io.File

val reader: Reader[Buf] = Reader.fromFile(new File("/dev/urandom"))

val file: Endpoint[IO, AsyncStream[Buf]] = get("stream-of-file") {
val chunkedReader = BufReader.chunked(reader, chunkSize = 512.kilobytes.inBytes.toInt)
Ok(Reader.toAsyncStream(chunkedReader))
}
```

### Converting `Errors` into JSON

Finch's own errors are often accumulated in the product `Endpoint` and represented as
Expand Down Expand Up @@ -432,7 +412,7 @@ e(Input.get("/foo")).awaitValueUnsafe()
### Server Sent Events

Finch offers support for [Server Sent Events][server-sent-events] through the `finch-sse` sub-project.
Server Sent Events are represented as `AsyncStream`s and streamed over the chunked HTTP transport.
Server Sent Events are represented as `Stream`s and streamed over the chunked HTTP transport.

The `ServerSentEvent` case class carries an arbitrary `data` field and it's possible to encode any
`ServerSentEvent[A]` for which `cats.Show[A]` is defined.
Expand Down Expand Up @@ -531,7 +511,6 @@ call. See finagle-http-auth's README for more usage details.
[loadbalancing]: http://twitter.github.io/finagle/guide/Clients.html#load-balancing
[futures]: http://twitter.github.io/finagle/guide/Futures.html
[bijection]: https://github.com/twitter/bijection
[as]: https://github.com/twitter/util/blob/develop/util-core/src/main/scala/com/twitter/concurrent/AsyncStream.scala
[cors-filter]: https://github.com/twitter/finagle/blob/develop/finagle-http/src/main/scala/com/twitter/finagle/http/filter/Cors.scala
[cors]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
[server-sent-events]: https://en.wikipedia.org/wiki/Server-sent_events
Expand Down
5 changes: 0 additions & 5 deletions docs/mdoc/user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,6 @@ bodies in a single step.
- `jsonBody(Option)[A]` - an alias for `body[A, Application.Json]`.
- `textBody(Option)[A]` - an alias for `body[A, Text.Plain]`

Chunked bodies:

- `asyncBody` - chunked/streamed (only matches chunked requests) body represented as an
`AsyncStream[Buf]`.

#### Multipart

Finch supports reading file uploads and attributes from the `multipart/form-data` HTTP bodies with
Expand Down