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

Update http4s-circe, http4s-dsl to 0.23.18 #468

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion project/ProjectPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object ProjectPlugin extends AutoPlugin {
object V {
lazy val cats = "2.9.0"
lazy val catsEffect = "2.5.5"
lazy val http4s = "0.21.34"
lazy val http4s = "0.23.18"
lazy val circe = "0.14.2"
lazy val log4s = "1.7.0"
lazy val scalatest = "3.2.15"
Expand Down
7 changes: 4 additions & 3 deletions server/src/main/scala/org/scalaexercises/evaluator/auth.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import org.log4s.getLogger
import pdi.jwt.{Jwt, JwtAlgorithm}

import scala.util.{Failure, Success}
import org.typelevel.ci.CIString

object auth {

Expand All @@ -50,18 +51,18 @@ object auth {

type HeaderT = `X-Scala-Eval-Api-Token`

def name: CaseInsensitiveString = CaseInsensitiveString("x-scala-eval-api-token")
def name: CIString = CIString("x-scala-eval-api-token")

override def parse(s: String): ParseResult[`X-Scala-Eval-Api-Token`] =
ParseResult.success(`X-Scala-Eval-Api-Token`(s))

def matchHeader(header: Header): Option[HeaderT] =
def matchHeader(header: Header.Raw): Option[HeaderT] =
if (header.name == name) Some(`X-Scala-Eval-Api-Token`(header.value))
else None

}

final case class `X-Scala-Eval-Api-Token`(token: String) extends Header.Parsed {
final case class `X-Scala-Eval-Api-Token`(token: String) extends Header.Raw.Parsed {
override def key = `X-Scala-Eval-Api-Token`
override def renderValue(writer: Writer): writer.type =
writer.append(token)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,24 @@ import io.circe.syntax._
import org.http4s._
import org.http4s.dsl._
import org.http4s.headers.Allow
import org.http4s.server.blaze._
import org.http4s.blaze.server._
import org.http4s.syntax.kleisli.http4sKleisliResponseSyntaxOptionT
import org.log4s.getLogger
import org.scalaexercises.evaluator.codecs._

import scala.concurrent.duration._
import org.typelevel.ci._

object services {

import EvalResponse.messages._

val corsHeaders = Seq(
Header("Vary", "Origin,Access-Control-Request-Methods"),
Header("Access-Control-Allow-Methods", "POST"),
Header("Access-Control-Allow-Origin", "*"),
Header("Access-Control-Allow-Headers", "x-scala-eval-api-token, Content-Type"),
Header("Access-Control-Max-Age", 1.day.toSeconds.toString())
Header.Raw(ci"Vary", "Origin,Access-Control-Request-Methods"),
Header.Raw(ci"Access-Control-Allow-Methods", "POST"),
Header.Raw(ci"Access-Control-Allow-Origin", "*"),
Header.Raw(ci"Access-Control-Allow-Headers", "x-scala-eval-api-token, Content-Type"),
Header.Raw(ci"Access-Control-Max-Age", 1.day.toSeconds.toString())
)

def service[F[_]: ConcurrentEffect: ContextShift: Timer: Sync](evaluator: Evaluator[F]) = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import org.scalatest.Assertion
import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.should.Matchers
import pdi.jwt.{Jwt, JwtAlgorithm}
import org.http4s.syntax.literals._

class EvalEndpointSpec extends AnyFunSpec with Matchers with Implicits {

Expand All @@ -43,10 +44,10 @@ class EvalEndpointSpec extends AnyFunSpec with Matchers with Implicits {

val server = auth[IO](service[IO](evaluator))

def serve(evalRequest: EvalRequest, authHeader: Header): Response[IO] =
def serve(evalRequest: EvalRequest, authHeader: Header.Raw): Response[IO] =
server
.run(
Request[IO](POST, Uri(path = "/eval"))
Request[IO](POST, Uri(path = path"/eval"))
.withEntity(evalRequest)
.putHeaders(authHeader)
)
Expand Down