Skip to content

Commit

Permalink
Merge pull request #99 from http4s/update/http4s-1.0.0-M31
Browse files Browse the repository at this point in the history
Update to http4s 1.0.0-M31
  • Loading branch information
armanbilge authored Feb 4, 2022
2 parents b2daaf3 + aba880c commit f074c01
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 25 deletions.
14 changes: 1 addition & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
scala: [2.12.15, 3.1.1, 2.13.8]
scala: [3.1.1, 2.13.8]
java: [temurin@8]
browser: [Chrome, Firefox]
exclude:
- scala: 2.12.15
browser: Firefox
- scala: 3.1.1
browser: Firefox
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -134,16 +132,6 @@ jobs:
~/Library/Caches/Coursier/v1
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Download target directories (2.12.15, Chrome)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.12.15-Chrome

- name: Inflate target directories (2.12.15, Chrome)
run: |
tar xf targets.tar
rm targets.tar
- name: Download target directories (3.1.1, Chrome)
uses: actions/download-artifact@v2
with:
Expand Down
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ ThisBuild / githubWorkflowTargetBranches := Seq("main")
ThisBuild / tlCiReleaseBranches := Seq("main")
ThisBuild / tlSitePublishBranch := Some("series/0.2")

ThisBuild / crossScalaVersions := Seq("2.12.15", "3.1.1", "2.13.8")
ThisBuild / crossScalaVersions := Seq("3.1.1", "2.13.8")
ThisBuild / githubWorkflowJavaVersions := Seq(JavaSpec.temurin("8"))
ThisBuild / githubWorkflowBuildMatrixAdditions += "browser" -> List("Chrome", "Firefox")
ThisBuild / githubWorkflowBuildSbtStepPreamble += s"set Global / useJSEnv := JSEnv.$${{ matrix.browser }}"
Expand Down Expand Up @@ -105,7 +105,7 @@ ThisBuild / Test / jsEnv := {

val catsEffectVersion = "3.3.5"
val fs2Version = "3.2.4"
val http4sVersion = buildinfo.BuildInfo.http4sVersion // share version with build project
val http4sVersion = "1.0.0-M31"
val scalaJSDomVersion = "2.1.0"
val circeVersion = "0.15.0-M1"
val munitVersion = "0.7.29"
Expand Down
10 changes: 8 additions & 2 deletions dom/src/main/scala/org/http4s/dom/FetchClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ private[dom] object FetchClient {
requestTimeout: Duration,
options: FetchOptions
)(implicit F: Async[F]): Client[F] = Client[F] { (req: Request[F]) =>
Resource.eval(req.body.chunkAll.filter(_.nonEmpty).compile.last).flatMap { body =>
Resource.eval {
req.entity match {
case Entity.Empty => None.pure
case Entity.Strict(chunk) => Some(chunk).pure
case default => default.body.chunkAll.filter(_.nonEmpty).compile.last
}
} flatMap { body =>
Resource
.makeCaseFull { (poll: Poll[F]) =>
F.delay(new AbortController()).flatMap { abortController =>
Expand All @@ -51,7 +57,7 @@ private[dom] object FetchClient {

init.method = req.method.name.asInstanceOf[HttpMethod]
init.headers = new Headers(toDomHeaders(req.headers))
body.foreach { body => init.body = body.toJSArrayBuffer }
body.foreach { body => init.body = body.toUint8Array }
init.signal = abortController.signal
mergedOptions.cache.foreach(init.cache = _)
mergedOptions.credentials.foreach(init.credentials = _)
Expand Down
15 changes: 9 additions & 6 deletions dom/src/main/scala/org/http4s/dom/ServiceWorker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import cats.effect.std.Supervisor
import cats.effect.unsafe.IORuntime
import cats.syntax.all._
import fs2.Chunk
import fs2.Stream
import org.scalajs.dom.Fetch
import org.scalajs.dom.ResponseInit
import org.scalajs.dom.FetchEvent
Expand Down Expand Up @@ -78,14 +77,18 @@ object ServiceWorker {
method <- OptionF.fromEither(Method.fromString(req.method.toString))
uri <- OptionF.fromEither(Uri.fromString(req.url))
headers = fromDomHeaders(req.headers)
body = Stream
.evalUnChunk(F.fromPromise(F.delay(req.arrayBuffer())).map(Chunk.jsArrayBuffer))
.covary[F]
request = Request(method, uri, headers = headers, body = body)
body <- OptionT.liftF(F.fromPromise(F.delay(req.arrayBuffer())))
chunk = Chunk.jsArrayBuffer(body)
request = Request[F](method, uri, headers = headers, entity = Entity.Strict(chunk))
.withAttribute(key, FetchEventContext(event, supervisor))
response <- routes(request)
body <- OptionT.liftF(
response.body.chunkAll.filter(_.nonEmpty).map(_.toJSArrayBuffer).compile.last
response.entity match {
case Entity.Empty => None.pure
case Entity.Strict(chunk) => Some(chunk.toUint8Array).pure
case default =>
default.body.chunkAll.filter(_.nonEmpty).map(_.toUint8Array).compile.last
}
)
} yield new DomResponse(
body.getOrElse(null),
Expand Down
2 changes: 1 addition & 1 deletion dom/src/main/scala/org/http4s/dom/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ package object dom {
Response[F](
status = status,
headers = fromDomHeaders(response.headers),
body = fromReadableStream(response.body)
entity = Entity(fromReadableStream(response.body), None)
)
}

Expand Down
2 changes: 1 addition & 1 deletion tests/src/main/scala/org/http4s/dom/TestRoutes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object TestRoutes {
}

val post = Some(request).filter(_.method == Method.POST).map { r =>
F.delay(Response(body = r.body))
F.delay(Response(entity = r.entity))
}

get.orElse(post).getOrElse(F.delay(Response[F](NotFound)))
Expand Down

0 comments on commit f074c01

Please sign in to comment.