From 4b4a34685f09273613bca6a39734f260d6530a86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Madsen?= Date: Sat, 27 Oct 2018 20:57:24 +0200 Subject: [PATCH 01/10] Deprecate Http4s, Http4sInstances and Http4sFunctions --- core/src/main/scala/org/http4s/Http4s.scala | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/src/main/scala/org/http4s/Http4s.scala b/core/src/main/scala/org/http4s/Http4s.scala index dc3c8200cbc..ad198289a46 100644 --- a/core/src/main/scala/org/http4s/Http4s.scala +++ b/core/src/main/scala/org/http4s/Http4s.scala @@ -1,9 +1,12 @@ package org.http4s +@deprecated("Use org.http4s.implicits._ instead", "0.20.0-M2") trait Http4s extends Http4sInstances with Http4sFunctions with syntax.AllSyntax +@deprecated("Use org.http4s.implicits._ instead", "0.20.0-M2") object Http4s extends Http4s +@deprecated("Import from or use EntityDecoder/EntityEncoder directly instead", "0.20.0-M2") trait Http4sInstances extends EntityDecoderInstances with HttpVersionInstances @@ -13,8 +16,11 @@ trait Http4sInstances with MethodInstances with StatusInstances +@deprecated("Import from or use EntityDecoder/EntityEncoder directly instead", "0.20.0-M2") object Http4sInstances extends Http4sInstances +@deprecated("Use org.http4s.qvalue._ or org.http4s.Uri._ instead", "0.20.0-M2") trait Http4sFunctions extends QValueFunctions with UriFunctions +@deprecated("Use org.http4s.qvalue._ or org.http4s.Uri._ instead", "0.20.0-M2") object Http4sFunctions extends Http4sFunctions From ef897761e0c48db7cc7dcf1a30d0f5d3c8fd6562 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Madsen?= Date: Sat, 27 Oct 2018 21:28:00 +0200 Subject: [PATCH 02/10] Inline some instances, don't mix in Http4s in Dsl --- .../main/scala/org/http4s/CharsetRange.scala | 13 +++----- core/src/main/scala/org/http4s/Http4s.scala | 7 +---- .../main/scala/org/http4s/HttpVersion.scala | 10 +++---- core/src/main/scala/org/http4s/Method.scala | 15 ++++------ core/src/main/scala/org/http4s/QValue.scala | 30 ++++++++----------- core/src/main/scala/org/http4s/Status.scala | 10 ++----- core/src/main/scala/org/http4s/Uri.scala | 25 ++++++++-------- .../main/scala/org/http4s/dsl/Http4sDsl.scala | 4 +-- 8 files changed, 44 insertions(+), 70 deletions(-) diff --git a/core/src/main/scala/org/http4s/CharsetRange.scala b/core/src/main/scala/org/http4s/CharsetRange.scala index ab2fe38295f..7d1ef2dff65 100644 --- a/core/src/main/scala/org/http4s/CharsetRange.scala +++ b/core/src/main/scala/org/http4s/CharsetRange.scala @@ -1,6 +1,6 @@ package org.http4s -import cats._ +import cats.{Eq, Show} import org.http4s.util._ sealed abstract class CharsetRange extends HasQValue with Renderable { @@ -20,7 +20,7 @@ sealed abstract class CharsetRange extends HasQValue with Renderable { } } -object CharsetRange extends CharsetRangeInstances { +object CharsetRange { sealed case class `*`(qValue: QValue) extends CharsetRange { final override def withQValue(q: QValue): CharsetRange.`*` = copy(qValue = q) @@ -43,12 +43,7 @@ object CharsetRange extends CharsetRangeInstances { } implicit def fromCharset(cs: Charset): CharsetRange.Atom = cs.toRange -} - -trait CharsetRangeInstances { - implicit val http4sEqForCharsetRange: Eq[CharsetRange] = - Eq.fromUniversalEquals - implicit val http4sShowForCharsetRange: Show[Charset] = - Show.fromToString + implicit val http4sCharsetRangeEq: Eq[CharsetRange] = Eq.fromUniversalEquals + implicit val http4sCharsetRangeShow: Show[CharsetRange] = Show.fromToString } diff --git a/core/src/main/scala/org/http4s/Http4s.scala b/core/src/main/scala/org/http4s/Http4s.scala index ad198289a46..751b85b1dd2 100644 --- a/core/src/main/scala/org/http4s/Http4s.scala +++ b/core/src/main/scala/org/http4s/Http4s.scala @@ -9,18 +9,13 @@ object Http4s extends Http4s @deprecated("Import from or use EntityDecoder/EntityEncoder directly instead", "0.20.0-M2") trait Http4sInstances extends EntityDecoderInstances - with HttpVersionInstances with EntityEncoderInstances - with CharsetRangeInstances - with QValueInstances - with MethodInstances - with StatusInstances @deprecated("Import from or use EntityDecoder/EntityEncoder directly instead", "0.20.0-M2") object Http4sInstances extends Http4sInstances @deprecated("Use org.http4s.qvalue._ or org.http4s.Uri._ instead", "0.20.0-M2") -trait Http4sFunctions extends QValueFunctions with UriFunctions +trait Http4sFunctions extends UriFunctions @deprecated("Use org.http4s.qvalue._ or org.http4s.Uri._ instead", "0.20.0-M2") object Http4sFunctions extends Http4sFunctions diff --git a/core/src/main/scala/org/http4s/HttpVersion.scala b/core/src/main/scala/org/http4s/HttpVersion.scala index 919e260f299..ac1afeb3646 100644 --- a/core/src/main/scala/org/http4s/HttpVersion.scala +++ b/core/src/main/scala/org/http4s/HttpVersion.scala @@ -1,8 +1,8 @@ package org.http4s -import cats._ import cats.data.{Writer => _} import cats.implicits._ +import cats.{Order, Show} import org.http4s.internal.parboiled2._ import org.http4s.parser._ import org.http4s.util._ @@ -20,7 +20,7 @@ final case class HttpVersion private[HttpVersion] (major: Int, minor: Int) (this.major, this.minor).compare((that.major, that.minor)) } -object HttpVersion extends HttpVersionInstances { +object HttpVersion { val `HTTP/1.0` = new HttpVersion(1, 0) val `HTTP/1.1` = new HttpVersion(1, 1) val `HTTP/2.0` = new HttpVersion(2, 0) @@ -50,9 +50,7 @@ object HttpVersion extends HttpVersionInstances { else if (minor < 0) ParseResult.fail("Invalid HTTP version", s"major must be > 0: $minor") else if (minor > 9) ParseResult.fail("Invalid HTTP version", s"major must be <= 9: $minor") else ParseResult.success(new HttpVersion(major, minor)) -} -trait HttpVersionInstances { - implicit val HttpVersionShow = Show.fromToString[HttpVersion] - implicit val HttpVersionOrder = Order.fromOrdering[HttpVersion] + implicit val http4sHttpVersionOrder: Order[HttpVersion] = Order.fromOrdering[HttpVersion] + implicit val http4sHttpVersionShow: Show[HttpVersion] = Show.fromToString[HttpVersion] } diff --git a/core/src/main/scala/org/http4s/Method.scala b/core/src/main/scala/org/http4s/Method.scala index 7b53c2405d2..2c269030a87 100644 --- a/core/src/main/scala/org/http4s/Method.scala +++ b/core/src/main/scala/org/http4s/Method.scala @@ -1,10 +1,10 @@ package org.http4s -import cats._ import cats.implicits._ +import cats.{Eq, Show} +import org.http4s.Method.Semantics import org.http4s.parser.Rfc2616BasicRules import org.http4s.util.{Renderable, Writer} -import org.http4s.Method.Semantics /** * An HTTP method. @@ -16,7 +16,7 @@ sealed abstract case class Method private (name: String) extends Renderable with final override def render(writer: Writer): writer.type = writer << name } -object Method extends MethodInstances { +object Method { sealed trait Semantics { def isIdempotent: Boolean def isSafe: Boolean @@ -144,12 +144,7 @@ object Method extends MethodInstances { ) private val allByKey: Map[String, Right[Nothing, Method]] = all.map(m => (m.name, Right(m))).toMap -} - -trait MethodInstances { - implicit val http4sEqForMethod: Eq[Method] = - Eq.fromUniversalEquals - implicit val http4sShowForMethod: Show[Method] = - Show.fromToString + implicit val http4sMethodEq: Eq[Method] = Eq.fromUniversalEquals + implicit val http4sShowEq: Show[Method] = Show.fromToString } diff --git a/core/src/main/scala/org/http4s/QValue.scala b/core/src/main/scala/org/http4s/QValue.scala index 27915ff3a05..7399c4e1c80 100644 --- a/core/src/main/scala/org/http4s/QValue.scala +++ b/core/src/main/scala/org/http4s/QValue.scala @@ -2,10 +2,10 @@ package org.http4s import cats._ import org.http4s.internal.parboiled2.{Parser => PbParser} -import org.http4s.util.Writer import org.http4s.parser.{AdditionalRules, Http4sParser} +import org.http4s.util.Writer import scala.language.experimental.macros -import scala.reflect.macros.whitebox.Context +import scala.reflect.macros.whitebox /** * A Quality Value. Represented as thousandths for an exact representation rounded to three @@ -60,7 +60,7 @@ final class QValue private (val thousandths: Int) extends AnyVal with Ordered[QV } } -object QValue extends QValueInstances with QValueFunctions { +object QValue { lazy val One: QValue = new QValue(1000) // scalastyle:ignore lazy val Zero: QValue = new QValue(0) @@ -95,7 +95,7 @@ object QValue extends QValueInstances with QValueFunctions { /** Exists to support compile-time verified literals. Do not call directly. */ def ☠(thousandths: Int): QValue = new QValue(thousandths) - class Macros(val c: Context) { + class Macros(val c: whitebox.Context) { import c.universe._ def qValueLiteral(d: c.Expr[Double]): Tree = @@ -111,18 +111,6 @@ object QValue extends QValueInstances with QValueFunctions { c.abort(c.enclosingPosition, s"literal Double value required") } } -} - -trait QValueInstances { - implicit val qValueOrder = Order.fromOrdering[QValue] - implicit val qValueShow = Show.fromToString[QValue] - implicit val qValueHttpCodec = new HttpCodec[QValue] { - def parse(s: String): ParseResult[QValue] = QValue.parse(s) - def render(writer: Writer, q: QValue): writer.type = q.render(writer) - } -} - -trait QValueFunctions { /** * Supports a literal syntax for validated QValues. @@ -135,7 +123,15 @@ trait QValueFunctions { * q(d) // does not compile: not a literal * }}} */ - def q(d: Double): QValue = macro QValue.Macros.qValueLiteral + def q(d: Double): QValue = macro Macros.qValueLiteral + + + implicit val http4sQValueOrder: Order[QValue] = Order.fromOrdering[QValue] + implicit val http4sQValueShow: Show[QValue] = Show.fromToString[QValue] + implicit val http4sQValueHttpCodec: HttpCodec[QValue] = new HttpCodec[QValue] { + def parse(s: String): ParseResult[QValue] = QValue.parse(s) + def render(writer: Writer, q: QValue): writer.type = q.render(writer) + } } trait HasQValue { diff --git a/core/src/main/scala/org/http4s/Status.scala b/core/src/main/scala/org/http4s/Status.scala index 3a000891605..8fa9a2ea62d 100644 --- a/core/src/main/scala/org/http4s/Status.scala +++ b/core/src/main/scala/org/http4s/Status.scala @@ -1,6 +1,6 @@ package org.http4s -import cats._ +import cats.{Order, Show} import org.http4s.Status.ResponseClass import org.http4s.util.Renderable @@ -10,7 +10,6 @@ import org.http4s.util.Renderable * * @param code HTTP status code * @param reason reason for the response. eg, OK - * * @see [http://tools.ietf.org/html/rfc7231#section-6 RFC7231, Section 6] * @see [http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml IANA Status Code Registry] */ @@ -195,9 +194,6 @@ object Status { Status(511, "Network Authentication Required")) // scalastyle:on magic.number -} - -trait StatusInstances { - implicit val StatusShow = Show.fromToString[Status] - implicit val StatusOrder = Order.fromOrdering[Status] + implicit val http4sStatusOrder: Order[Status] = Order.fromOrdering[Status] + implicit val http4sStatusShow: Show[Status] = Show.fromToString[Status] } diff --git a/core/src/main/scala/org/http4s/Uri.scala b/core/src/main/scala/org/http4s/Uri.scala index 42a6a4a943a..c97ab397323 100644 --- a/core/src/main/scala/org/http4s/Uri.scala +++ b/core/src/main/scala/org/http4s/Uri.scala @@ -11,7 +11,7 @@ import org.http4s.syntax.string._ import org.http4s.util._ import scala.language.experimental.macros import scala.math.Ordered -import scala.reflect.macros.whitebox.Context +import scala.reflect.macros.whitebox /** Representation of the [[Request]] URI * @param scheme optional Uri Scheme. eg, http, https @@ -118,7 +118,7 @@ final case class Uri( } object Uri extends UriFunctions { - class Macros(val c: Context) { + class Macros(val c: whitebox.Context) { import c.universe._ def uriLiteral(s: c.Expr[String]): Tree = @@ -260,17 +260,6 @@ object Uri extends UriFunctions { object IPv4 { def apply(address: String): IPv4 = new IPv4(address.ci) } object IPv6 { def apply(address: String): IPv6 = new IPv6(address.ci) } - implicit val eqInstance: Eq[Uri] = Eq.fromUniversalEquals -} - -trait UriFunctions { - - /** - * Literal syntax for URIs. Invalid or non-literal arguments are rejected - * at compile time. - */ - def uri(s: String): Uri = macro Uri.Macros.uriLiteral - /** * Resolve a relative Uri reference, per RFC 3986 sec 5.2 */ @@ -381,4 +370,14 @@ trait UriFunctions { case -1 => b.setLength(0) case n => b.setLength(n) } + + implicit val http4sUriEq: Eq[Uri] = Eq.fromUniversalEquals +} + +trait UriFunctions { + /** + * Literal syntax for URIs. Invalid or non-literal arguments are rejected + * at compile time. + */ + def uri(s: String): Uri = macro Uri.Macros.uriLiteral } diff --git a/dsl/src/main/scala/org/http4s/dsl/Http4sDsl.scala b/dsl/src/main/scala/org/http4s/dsl/Http4sDsl.scala index c0d0ed54937..c2ae21426b0 100644 --- a/dsl/src/main/scala/org/http4s/dsl/Http4sDsl.scala +++ b/dsl/src/main/scala/org/http4s/dsl/Http4sDsl.scala @@ -1,9 +1,9 @@ package org.http4s.dsl -import org.http4s.{Http4s, Method} +import org.http4s.{Method, UriFunctions} import org.http4s.dsl.impl._ -trait Http4sDsl[F[_]] extends Http4s with Methods with Statuses with Responses[F] with Auth { +trait Http4sDsl[F[_]] extends UriFunctions with Methods with Statuses with Responses[F] with Auth { import Http4sDsl._ type Path = impl.Path From 7cf1836b142580a074df88ae7dd8df74d5b62bb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Madsen?= Date: Sat, 27 Oct 2018 21:28:08 +0200 Subject: [PATCH 03/10] Update tests and examples --- .../http4s/server/blaze/ServerTestRoutes.scala | 1 + .../http4s/blaze/BlazeWebSocketExample.scala | 1 + .../com/example/http4s/blaze/ClientExample.scala | 6 +++--- .../server/endpoints/MultipartHttpEndpoint.scala | 1 + .../test/scala/org/http4s/server/MockRoute.scala | 2 +- .../src/test/scala/org/http4s/Http4sSpec.scala | 5 ++++- .../scala/org/http4s/ContentCodingSpec.scala | 4 ++-- .../test/scala/org/http4s/ResponderSpec.scala | 2 +- .../org/http4s/parser/AcceptEncodingSpec.scala | 9 ++++----- .../org/http4s/parser/AcceptHeaderSpec.scala | 16 ++++++++-------- .../org/http4s/parser/AcceptLanguageSpec.scala | 5 ++--- .../scala/org/http4s/parser/MediaRangeSpec.scala | 12 ++++++------ 12 files changed, 34 insertions(+), 30 deletions(-) diff --git a/blaze-server/src/test/scala/org/http4s/server/blaze/ServerTestRoutes.scala b/blaze-server/src/test/scala/org/http4s/server/blaze/ServerTestRoutes.scala index c05d8a800b3..8f5cde673d2 100644 --- a/blaze-server/src/test/scala/org/http4s/server/blaze/ServerTestRoutes.scala +++ b/blaze-server/src/test/scala/org/http4s/server/blaze/ServerTestRoutes.scala @@ -5,6 +5,7 @@ package blaze import cats.effect._ import cats.implicits._ import fs2.Stream._ +import org.http4s.implicits._ import org.http4s.Charset._ import org.http4s.dsl.Http4sDsl import org.http4s.headers._ diff --git a/examples/blaze/src/main/scala/com/example/http4s/blaze/BlazeWebSocketExample.scala b/examples/blaze/src/main/scala/com/example/http4s/blaze/BlazeWebSocketExample.scala index d394ac6d7a6..4b2b87b5cb7 100644 --- a/examples/blaze/src/main/scala/com/example/http4s/blaze/BlazeWebSocketExample.scala +++ b/examples/blaze/src/main/scala/com/example/http4s/blaze/BlazeWebSocketExample.scala @@ -5,6 +5,7 @@ import cats.implicits._ import fs2._ import fs2.concurrent.Queue import org.http4s._ +import org.http4s.implicits._ import org.http4s.dsl.Http4sDsl import org.http4s.server.blaze.BlazeServerBuilder import org.http4s.server.websocket._ diff --git a/examples/blaze/src/main/scala/com/example/http4s/blaze/ClientExample.scala b/examples/blaze/src/main/scala/com/example/http4s/blaze/ClientExample.scala index 783ede09c6a..64256d8a25a 100644 --- a/examples/blaze/src/main/scala/com/example/http4s/blaze/ClientExample.scala +++ b/examples/blaze/src/main/scala/com/example/http4s/blaze/ClientExample.scala @@ -3,7 +3,7 @@ package com.example.http4s.blaze import cats.effect._ import cats.implicits._ import io.circe.generic.auto._ -import org.http4s.Http4s._ +import org.http4s.Uri import org.http4s.Status.{NotFound, Successful} import org.http4s.circe._ import org.http4s.client.Client @@ -13,7 +13,7 @@ import scala.concurrent.ExecutionContext.global object ClientExample extends IOApp { def getSite(client: Client[IO]): IO[Unit] = IO { - val page: IO[String] = client.expect[String](uri("https://www.google.com/")) + val page: IO[String] = client.expect[String](Uri.uri("https://www.google.com/")) for (_ <- 1 to 2) println(page.map(_.take(72)).unsafeRunSync()) // each execution of the effect will refetch the page! @@ -24,7 +24,7 @@ object ClientExample extends IOApp { final case class Foo(bar: String) // Match on response code! - val page2 = client.get(uri("http://http4s.org/resources/foo.json")) { + val page2 = client.get(Uri.uri("http://http4s.org/resources/foo.json")) { case Successful(resp) => // decodeJson is defined for Json4s, Argonuat, and Circe, just need the right decoder! resp.decodeJson[Foo].map("Received response: " + _) diff --git a/examples/blaze/src/main/scala/com/example/http4s/blaze/demo/server/endpoints/MultipartHttpEndpoint.scala b/examples/blaze/src/main/scala/com/example/http4s/blaze/demo/server/endpoints/MultipartHttpEndpoint.scala index f041cbab27a..9cff70605b7 100644 --- a/examples/blaze/src/main/scala/com/example/http4s/blaze/demo/server/endpoints/MultipartHttpEndpoint.scala +++ b/examples/blaze/src/main/scala/com/example/http4s/blaze/demo/server/endpoints/MultipartHttpEndpoint.scala @@ -3,6 +3,7 @@ package com.example.http4s.blaze.demo.server.endpoints import cats.effect.Sync import cats.implicits._ import com.example.http4s.blaze.demo.server.service.FileService +import org.http4s.EntityDecoder.multipart import org.http4s._ import org.http4s.dsl.Http4sDsl import org.http4s.multipart.Part diff --git a/server/src/test/scala/org/http4s/server/MockRoute.scala b/server/src/test/scala/org/http4s/server/MockRoute.scala index 4771edad9a9..fa80d8846cb 100644 --- a/server/src/test/scala/org/http4s/server/MockRoute.scala +++ b/server/src/test/scala/org/http4s/server/MockRoute.scala @@ -6,7 +6,7 @@ import cats.implicits._ import org.http4s.Status.{Accepted, Ok} import org.http4s.server.middleware.PushSupport._ -object MockRoute extends Http4s { +object MockRoute { def route(): HttpRoutes[IO] = HttpRoutes.of { case req if req.uri.path === "/ping" => diff --git a/testing/src/test/scala/org/http4s/Http4sSpec.scala b/testing/src/test/scala/org/http4s/Http4sSpec.scala index 163b631236b..b5a580aba71 100644 --- a/testing/src/test/scala/org/http4s/Http4sSpec.scala +++ b/testing/src/test/scala/org/http4s/Http4sSpec.scala @@ -39,7 +39,10 @@ trait Http4sSpec with ScalaCheck with AnyMatchers with OptionMatchers - with Http4s + with syntax.AllSyntax + with UriFunctions + with EntityDecoderInstances + with EntityEncoderInstances with ArbitraryInstances with FragmentsDsl with Discipline diff --git a/tests/src/test/scala/org/http4s/ContentCodingSpec.scala b/tests/src/test/scala/org/http4s/ContentCodingSpec.scala index 29d3bf4adba..f49258c48ec 100644 --- a/tests/src/test/scala/org/http4s/ContentCodingSpec.scala +++ b/tests/src/test/scala/org/http4s/ContentCodingSpec.scala @@ -48,7 +48,7 @@ class ContentCodingSpec extends Http4sSpec { ContentCoding.parse("mycoding") must_== ContentCoding.fromString("mycoding") } "parse with quality" in { - ContentCoding.parse("gzip;q=0.8") must_== Right(ContentCoding.gzip.withQValue(q(0.8))) + ContentCoding.parse("gzip;q=0.8") must_== Right(ContentCoding.gzip.withQValue(QValue.q(0.8))) } "fail on empty" in { ContentCoding.parse("") must beLeft @@ -65,7 +65,7 @@ class ContentCodingSpec extends Http4sSpec { ContentCoding.parse("*fahon") must_== ParseResult.success( ContentCoding.unsafeFromString("*fahon")) ContentCoding.parse("*fahon;q=0.1") must_== ParseResult.success( - ContentCoding.unsafeFromString("*fahon").withQValue(q(0.1))) + ContentCoding.unsafeFromString("*fahon").withQValue(QValue.q(0.1))) } } diff --git a/tests/src/test/scala/org/http4s/ResponderSpec.scala b/tests/src/test/scala/org/http4s/ResponderSpec.scala index 26b8c82728b..2875aee9675 100644 --- a/tests/src/test/scala/org/http4s/ResponderSpec.scala +++ b/tests/src/test/scala/org/http4s/ResponderSpec.scala @@ -2,7 +2,7 @@ package org.http4s import cats.effect.IO import org.http4s.Charset._ -import org.http4s.Http4s._ +import org.http4s.implicits._ import org.http4s.headers._ import org.specs2.mutable.Specification diff --git a/tests/src/test/scala/org/http4s/parser/AcceptEncodingSpec.scala b/tests/src/test/scala/org/http4s/parser/AcceptEncodingSpec.scala index fed9f147e09..91d3cce886c 100644 --- a/tests/src/test/scala/org/http4s/parser/AcceptEncodingSpec.scala +++ b/tests/src/test/scala/org/http4s/parser/AcceptEncodingSpec.scala @@ -2,7 +2,6 @@ package org.http4s package parser import org.http4s.headers.`Accept-Encoding` -import org.http4s.Http4s._ import org.specs2.mutable.Specification class AcceptEncodingSpec extends Specification with HeaderParserHelper[`Accept-Encoding`] { @@ -10,11 +9,11 @@ class AcceptEncodingSpec extends Specification with HeaderParserHelper[`Accept-E HttpHeaderParser.ACCEPT_ENCODING(value) val gzip = `Accept-Encoding`(ContentCoding.gzip) - val gzip5 = `Accept-Encoding`(ContentCoding.gzip.withQValue(q(0.5))) - val gzip55 = `Accept-Encoding`(ContentCoding.gzip.withQValue(q(0.55))) - val gzip555 = `Accept-Encoding`(ContentCoding.gzip.withQValue(q(0.555))) + val gzip5 = `Accept-Encoding`(ContentCoding.gzip.withQValue(QValue.q(0.5))) + val gzip55 = `Accept-Encoding`(ContentCoding.gzip.withQValue(QValue.q(0.55))) + val gzip555 = `Accept-Encoding`(ContentCoding.gzip.withQValue(QValue.q(0.555))) - val gzip1 = `Accept-Encoding`(ContentCoding.gzip.withQValue(q(1.0))) + val gzip1 = `Accept-Encoding`(ContentCoding.gzip.withQValue(QValue.q(1.0))) "Accept-Encoding parser" should { diff --git a/tests/src/test/scala/org/http4s/parser/AcceptHeaderSpec.scala b/tests/src/test/scala/org/http4s/parser/AcceptHeaderSpec.scala index 675c90c12e5..da2c26cfd06 100644 --- a/tests/src/test/scala/org/http4s/parser/AcceptHeaderSpec.scala +++ b/tests/src/test/scala/org/http4s/parser/AcceptHeaderSpec.scala @@ -1,14 +1,14 @@ package org.http4s package parser -import org.http4s.headers.{Accept, MediaRangeAndQValue} +import cats.syntax.show._ import org.http4s.MediaRange._ import org.http4s.MediaType._ +import org.http4s.headers.{Accept, MediaRangeAndQValue} import org.http4s.testing._ -import cats.syntax.show._ import org.specs2.mutable.Specification -class AcceptHeaderSpec extends Specification with HeaderParserHelper[Accept] with Http4s { +class AcceptHeaderSpec extends Specification with HeaderParserHelper[Accept] { def hparse(value: String): ParseResult[Accept] = HttpHeaderParser.ACCEPT(value) def ext = Map("foo" -> "bar", "baz" -> "whatever") @@ -50,7 +50,7 @@ class AcceptHeaderSpec extends Specification with HeaderParserHelper[Accept] wit val accept = Accept(`audio/*`, `video/*`) parse(accept.value) must be_===(accept) - val accept2 = Accept(`audio/*`.withQValue(q(0.2)), `video/*`) + val accept2 = Accept(`audio/*`.withQValue(QValue.q(0.2)), `video/*`) parse(accept2.value) must be_===(accept2) // Go through all of them @@ -64,7 +64,7 @@ class AcceptHeaderSpec extends Specification with HeaderParserHelper[Accept] wit // Go through all of them with q and extensions { - val samples = MediaRange.standard.values.map(_.withExtensions(ext).withQValue(q(0.2))) + val samples = MediaRange.standard.values.map(_.withExtensions(ext).withQValue(QValue.q(0.2))) foreach(samples.sliding(4).toArray) { sample => val h = Accept(sample.head, sample.tail.toSeq: _*) parse(h.value) must be_===(h) @@ -90,13 +90,13 @@ class AcceptHeaderSpec extends Specification with HeaderParserHelper[Accept] wit val value = "text/*;q=0.3, text/html;q=0.7, text/html;level=1" parse(value) must be_===( Accept( - `text/*`.withQValue(q(0.3)), - MediaType.text.html.withQValue(q(0.7)), + `text/*`.withQValue(QValue.q(0.3)), + MediaType.text.html.withQValue(QValue.q(0.7)), MediaType.text.html.withExtensions(Map("level" -> "1")) )) // Go through all of them - val samples = MediaType.all.values.map(_.withExtensions(ext).withQValue(q(0.2))) + val samples = MediaType.all.values.map(_.withExtensions(ext).withQValue(QValue.q(0.2))) foreach(samples.sliding(4).toArray) { sample => val h = Accept(sample.head, sample.tail.toSeq: _*) parse(h.value) must be_===(h) diff --git a/tests/src/test/scala/org/http4s/parser/AcceptLanguageSpec.scala b/tests/src/test/scala/org/http4s/parser/AcceptLanguageSpec.scala index 1bc18718b0f..eeebe7f4247 100644 --- a/tests/src/test/scala/org/http4s/parser/AcceptLanguageSpec.scala +++ b/tests/src/test/scala/org/http4s/parser/AcceptLanguageSpec.scala @@ -6,15 +6,14 @@ import org.specs2.mutable.Specification class AcceptLanguageSpec extends Specification - with HeaderParserHelper[`Accept-Language`] - with Http4s { + with HeaderParserHelper[`Accept-Language`] { def hparse(value: String): ParseResult[`Accept-Language`] = HttpHeaderParser.ACCEPT_LANGUAGE(value) val en = `Accept-Language`(LanguageTag("en")) val fr = `Accept-Language`(LanguageTag("fr")) - val enq5 = `Accept-Language`(LanguageTag("en").withQValue(q(0.5))) + val enq5 = `Accept-Language`(LanguageTag("en").withQValue(QValue.q(0.5))) val en_cool = `Accept-Language`(LanguageTag("en", "cool")) val all = `Accept-Language`(LanguageTag.`*`) diff --git a/tests/src/test/scala/org/http4s/parser/MediaRangeSpec.scala b/tests/src/test/scala/org/http4s/parser/MediaRangeSpec.scala index 40f7aa44f7e..934f99572f3 100644 --- a/tests/src/test/scala/org/http4s/parser/MediaRangeSpec.scala +++ b/tests/src/test/scala/org/http4s/parser/MediaRangeSpec.scala @@ -6,7 +6,7 @@ import org.http4s.MediaType import org.http4s.testing._ import org.specs2.mutable.Specification -class MediaRangeSpec extends Specification with Http4s { +class MediaRangeSpec extends Specification { def ext = Map("foo" -> "bar") "MediaRanges" should { @@ -27,8 +27,8 @@ class MediaRangeSpec extends Specification with Http4s { } "Be satisfiedBy MediaTypes correctly" in { - `text/*`.satisfiedBy(MediaType.text css) must be_==(true) - `text/*`.satisfiedBy(MediaType.text css) must be_==(true) + `text/*`.satisfiedBy(MediaType.text.css) must be_==(true) + `text/*`.satisfiedBy(MediaType.text.css) must be_==(true) `text/*`.satisfiedBy(`audio/aiff`) must be_==(false) } @@ -45,14 +45,14 @@ class MediaRangeSpec extends Specification with Http4s { MediaType.text.html.withExtensions(ext) must be_!=(MediaType.text.html) - MediaType.text.html must be_!=(MediaType.text css) + MediaType.text.html must be_!=(MediaType.text.css) } "Be satisfiedBy MediaTypes correctly" in { - MediaType.text.html.satisfiedBy(MediaType.text css) must be_==(false) + MediaType.text.html.satisfiedBy(MediaType.text.css) must be_==(false) MediaType.text.html.satisfiedBy(MediaType.text.html) must be_==(true) - MediaType.text.html.satisfies(MediaType.text css) must be_==(false) + MediaType.text.html.satisfies(MediaType.text.css) must be_==(false) } "Not be satisfied by MediaRanges" in { From 87d6eef1f25462164fec8934a5491e8308534d40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Madsen?= Date: Tue, 30 Oct 2018 10:43:58 +0100 Subject: [PATCH 04/10] Clean up some implicit naming --- .../main/scala/org/http4s/CharsetRange.scala | 4 +- .../main/scala/org/http4s/ContentCoding.scala | 23 ++++----- .../main/scala/org/http4s/HttpVersion.scala | 6 ++- .../src/main/scala/org/http4s/MediaType.scala | 47 +++++++++---------- core/src/main/scala/org/http4s/Method.scala | 4 +- core/src/main/scala/org/http4s/QValue.scala | 7 ++- core/src/main/scala/org/http4s/Status.scala | 4 +- .../scala/org/http4s/TransferCoding.scala | 20 ++++---- core/src/main/scala/org/http4s/Uri.scala | 13 +++-- .../org/http4s/headers/Content-Type.scala | 2 +- .../org/http4s/parser/AcceptHeaderSpec.scala | 3 +- .../http4s/parser/AcceptLanguageSpec.scala | 4 +- 12 files changed, 63 insertions(+), 74 deletions(-) diff --git a/core/src/main/scala/org/http4s/CharsetRange.scala b/core/src/main/scala/org/http4s/CharsetRange.scala index 7d1ef2dff65..260c638ddc4 100644 --- a/core/src/main/scala/org/http4s/CharsetRange.scala +++ b/core/src/main/scala/org/http4s/CharsetRange.scala @@ -44,6 +44,6 @@ object CharsetRange { implicit def fromCharset(cs: Charset): CharsetRange.Atom = cs.toRange - implicit val http4sCharsetRangeEq: Eq[CharsetRange] = Eq.fromUniversalEquals - implicit val http4sCharsetRangeShow: Show[CharsetRange] = Show.fromToString + implicit val http4sEqForCharsetRange: Eq[CharsetRange] = Eq.fromUniversalEquals + implicit val http4sShowForCharsetRange: Show[CharsetRange] = Show.fromToString } diff --git a/core/src/main/scala/org/http4s/ContentCoding.scala b/core/src/main/scala/org/http4s/ContentCoding.scala index 1f1515aee43..df8df088626 100644 --- a/core/src/main/scala/org/http4s/ContentCoding.scala +++ b/core/src/main/scala/org/http4s/ContentCoding.scala @@ -18,10 +18,10 @@ */ package org.http4s -import cats.{Order, Show} -import cats.syntax.eq._ -import cats.instances.tuple._ import cats.instances.string._ +import cats.instances.tuple._ +import cats.syntax.eq._ +import cats.{Order, Show} import org.http4s.QValue.QValueParser import org.http4s.internal.parboiled2.{Parser => PbParser, _} import org.http4s.parser.Http4sParser @@ -65,7 +65,7 @@ class ContentCoding private (val coding: String, override val qValue: QValue = Q ContentCoding.http4sOrderForContentCoding.compare(this, other) override def render(writer: Writer): writer.type = - ContentCoding.http4sInstancesForContentCoding.render(writer, this) + ContentCoding.http4sHttpCodecForContentCoding.render(writer, this) } object ContentCoding { @@ -116,19 +116,16 @@ object ContentCoding { } } - implicit val http4sInstancesForContentCoding: Show[ContentCoding] with HttpCodec[ContentCoding] = - new Show[ContentCoding] with HttpCodec[ContentCoding] { - override def show(s: ContentCoding): String = s.toString - + implicit val http4sOrderForContentCoding: Order[ContentCoding] = + Order.by(c => (c.coding.toLowerCase, c.qValue)) + implicit val http4sShowForContentCoding: Show[ContentCoding] = + Show.fromToString + implicit val http4sHttpCodecForContentCoding: HttpCodec[ContentCoding] = + new HttpCodec[ContentCoding] { override def parse(s: String): ParseResult[ContentCoding] = ContentCoding.parse(s) override def render(writer: Writer, coding: ContentCoding): writer.type = writer << coding.coding.toLowerCase << coding.qValue - } - - implicit val http4sOrderForContentCoding: Order[ContentCoding] = - Order.by(c => (c.coding.toLowerCase, c.qValue)) - } diff --git a/core/src/main/scala/org/http4s/HttpVersion.scala b/core/src/main/scala/org/http4s/HttpVersion.scala index ac1afeb3646..74f93c504c4 100644 --- a/core/src/main/scala/org/http4s/HttpVersion.scala +++ b/core/src/main/scala/org/http4s/HttpVersion.scala @@ -51,6 +51,8 @@ object HttpVersion { else if (minor > 9) ParseResult.fail("Invalid HTTP version", s"major must be <= 9: $minor") else ParseResult.success(new HttpVersion(major, minor)) - implicit val http4sHttpVersionOrder: Order[HttpVersion] = Order.fromOrdering[HttpVersion] - implicit val http4sHttpVersionShow: Show[HttpVersion] = Show.fromToString[HttpVersion] + implicit val http4sHttpOrderForVersion: Order[HttpVersion] = + Order.fromOrdering[HttpVersion] + implicit val http4sHttpShowForVersion: Show[HttpVersion] = + Show.fromToString[HttpVersion] } diff --git a/core/src/main/scala/org/http4s/MediaType.scala b/core/src/main/scala/org/http4s/MediaType.scala index 86ef8ca3aec..52a3d30c9c2 100644 --- a/core/src/main/scala/org/http4s/MediaType.scala +++ b/core/src/main/scala/org/http4s/MediaType.scala @@ -18,8 +18,8 @@ */ package org.http4s -import cats.{Eq, Order, Show} import cats.implicits._ +import cats.{Eq, Order, Show} import org.http4s.headers.MediaRangeAndQValue import org.http4s.internal.parboiled2.{Parser => PbParser, _} import org.http4s.parser.{Http4sParser, Rfc2616BasicRules} @@ -142,31 +142,29 @@ object MediaRange { new MediaType(mainType.toLowerCase, subType.toLowerCase)) } - implicit val http4sInstancesForMediaRange - : Show[MediaRange] with HttpCodec[MediaRange] with Order[MediaRange] = - new Show[MediaRange] with HttpCodec[MediaRange] with Order[MediaRange] { - override def show(s: MediaRange): String = - s"${s.mainType}/*${MediaRange.extensionsToString(s)}" - + implicit val http4sShowForMediaRange: Show[MediaRange] = + Show.show(s => s"${s.mainType}/*${MediaRange.extensionsToString(s)}") + implicit val http4sOrderForMediaRange: Order[MediaRange] = + Order.from { (x, y) => + def orderedSubtype(a: MediaRange) = a match { + case mt: MediaType => mt.subType + case _ => "" + } + def f(a: MediaRange) = (a.mainType, orderedSubtype(a), a.extensions.toVector.sortBy(_._1)) + Order[(String, String, Vector[(String, String)])].compare(f(x), f(y)) + } + implicit val http4sHttpCodecForMediaRange: HttpCodec[MediaRange] = + new HttpCodec[MediaRange] { override def parse(s: String): ParseResult[MediaRange] = MediaRange.parse(s) override def render(writer: Writer, mr: MediaRange): writer.type = mr match { - case mt: MediaType => MediaType.http4sInstancesForMediaType.render(writer, mt) + case mt: MediaType => MediaType.http4sHttpCodecForMediaType.render(writer, mt) case _ => writer << mr.mainType << "/*" renderExtensions(writer, mr) writer } - - override def compare(x: MediaRange, y: MediaRange): Int = { - def orderedSubtype(a: MediaRange) = a match { - case mt: MediaType => mt.subType - case _ => "" - } - def f(a: MediaRange) = (a.mainType, orderedSubtype(a), a.extensions.toVector.sortBy(_._1)) - Order[(String, String, Vector[(String, String)])].compare(f(x), f(y)) - } } } @@ -264,12 +262,12 @@ object MediaType extends MimeDB { new MediaType(mainType.toLowerCase, subType.toLowerCase)) } - implicit val http4sInstancesForMediaType - : Show[MediaType] with HttpCodec[MediaType] with Eq[MediaType] = - new Show[MediaType] with HttpCodec[MediaType] with Eq[MediaType] { - override def show(s: MediaType): String = - s"${s.mainType}/${s.subType}${MediaRange.extensionsToString(s)}" - + implicit val http4sEqForMediaType: Eq[MediaType] = + Eq.fromUniversalEquals + implicit val http4sShowForMediaType: Show[MediaType] = + Show.show(s => s"${s.mainType}/${s.subType}${MediaRange.extensionsToString(s)}") + implicit val http4sHttpCodecForMediaType: HttpCodec[MediaType] = + new HttpCodec[MediaType] { override def parse(s: String): ParseResult[MediaType] = MediaType.parse(s) @@ -278,9 +276,6 @@ object MediaType extends MimeDB { MediaRange.renderExtensions(writer, mt) writer } - - override def eqv(x: MediaType, y: MediaType): Boolean = - x.equals(y) } } diff --git a/core/src/main/scala/org/http4s/Method.scala b/core/src/main/scala/org/http4s/Method.scala index 2c269030a87..77aab1964f5 100644 --- a/core/src/main/scala/org/http4s/Method.scala +++ b/core/src/main/scala/org/http4s/Method.scala @@ -145,6 +145,6 @@ object Method { private val allByKey: Map[String, Right[Nothing, Method]] = all.map(m => (m.name, Right(m))).toMap - implicit val http4sMethodEq: Eq[Method] = Eq.fromUniversalEquals - implicit val http4sShowEq: Show[Method] = Show.fromToString + implicit val http4sEqForMethod: Eq[Method] = Eq.fromUniversalEquals + implicit val http4sShowForMethod: Show[Method] = Show.fromToString } diff --git a/core/src/main/scala/org/http4s/QValue.scala b/core/src/main/scala/org/http4s/QValue.scala index 7399c4e1c80..5537c9b4b46 100644 --- a/core/src/main/scala/org/http4s/QValue.scala +++ b/core/src/main/scala/org/http4s/QValue.scala @@ -125,10 +125,9 @@ object QValue { */ def q(d: Double): QValue = macro Macros.qValueLiteral - - implicit val http4sQValueOrder: Order[QValue] = Order.fromOrdering[QValue] - implicit val http4sQValueShow: Show[QValue] = Show.fromToString[QValue] - implicit val http4sQValueHttpCodec: HttpCodec[QValue] = new HttpCodec[QValue] { + implicit val http4sOrderForQValue: Order[QValue] = Order.fromOrdering[QValue] + implicit val http4sShowForQValue: Show[QValue] = Show.fromToString[QValue] + implicit val http4sHttpCodecForQValue: HttpCodec[QValue] = new HttpCodec[QValue] { def parse(s: String): ParseResult[QValue] = QValue.parse(s) def render(writer: Writer, q: QValue): writer.type = q.render(writer) } diff --git a/core/src/main/scala/org/http4s/Status.scala b/core/src/main/scala/org/http4s/Status.scala index 8fa9a2ea62d..88f7a673aa7 100644 --- a/core/src/main/scala/org/http4s/Status.scala +++ b/core/src/main/scala/org/http4s/Status.scala @@ -194,6 +194,6 @@ object Status { Status(511, "Network Authentication Required")) // scalastyle:on magic.number - implicit val http4sStatusOrder: Order[Status] = Order.fromOrdering[Status] - implicit val http4sStatusShow: Show[Status] = Show.fromToString[Status] + implicit val http4sOrderForStatus: Order[Status] = Order.fromOrdering[Status] + implicit val http4sShowForStatus: Show[Status] = Show.fromToString[Status] } diff --git a/core/src/main/scala/org/http4s/TransferCoding.scala b/core/src/main/scala/org/http4s/TransferCoding.scala index fde755a9162..14f84ab9143 100644 --- a/core/src/main/scala/org/http4s/TransferCoding.scala +++ b/core/src/main/scala/org/http4s/TransferCoding.scala @@ -18,11 +18,11 @@ */ package org.http4s -import cats.{Order, Show} import cats.data.NonEmptyList -import org.http4s.util._ -import org.http4s.parser.{Http4sParser, Rfc2616BasicRules} +import cats.{Order, Show} import org.http4s.internal.parboiled2.{Parser => PbParser} +import org.http4s.parser.{Http4sParser, Rfc2616BasicRules} +import org.http4s.util._ class TransferCoding private (val coding: String) extends Ordered[TransferCoding] with Renderable { override def equals(o: Any) = o match { @@ -87,19 +87,17 @@ object TransferCoding { } } - implicit val http4sInstancesForTransferCoding - : Show[TransferCoding] with HttpCodec[TransferCoding] with Order[TransferCoding] = - new Show[TransferCoding] with HttpCodec[TransferCoding] with Order[TransferCoding] { - override def show(s: TransferCoding): String = s.coding - + implicit val http4sOrderForTransferCoding: Order[TransferCoding] = + Order.fromComparable + implicit val http4sShowForTransferCoding: Show[TransferCoding] = + Show.show(_.coding) + implicit val http4sInstancesForTransferCoding: HttpCodec[TransferCoding] = + new HttpCodec[TransferCoding] { override def parse(s: String): ParseResult[TransferCoding] = TransferCoding.parse(s) override def render(writer: Writer, coding: TransferCoding): writer.type = writer << coding.coding - - override def compare(x: TransferCoding, y: TransferCoding): Int = - x.compareTo(y) } } diff --git a/core/src/main/scala/org/http4s/Uri.scala b/core/src/main/scala/org/http4s/Uri.scala index c97ab397323..c31fc4a5ca6 100644 --- a/core/src/main/scala/org/http4s/Uri.scala +++ b/core/src/main/scala/org/http4s/Uri.scala @@ -202,18 +202,17 @@ object Uri extends UriFunctions { } } - implicit val http4sInstancesForScheme: Show[Scheme] with HttpCodec[Scheme] with Order[Scheme] = - new Show[Scheme] with HttpCodec[Scheme] with Order[Scheme] { - def show(s: Scheme): String = s.toString - + implicit val http4sOrderForScheme: Order[Scheme] = + Order.fromComparable + implicit val http4sShowForScheme: Show[Scheme] = + Show.fromToString + implicit val http4sInstancesForScheme: HttpCodec[Scheme] = + new HttpCodec[Scheme] { def parse(s: String): ParseResult[Scheme] = Scheme.parse(s) def render(writer: Writer, scheme: Scheme): writer.type = writer << scheme.value - - def compare(x: Scheme, y: Scheme) = - x.compare(y) } } diff --git a/core/src/main/scala/org/http4s/headers/Content-Type.scala b/core/src/main/scala/org/http4s/headers/Content-Type.scala index 57873d8d6eb..1b382c6e462 100644 --- a/core/src/main/scala/org/http4s/headers/Content-Type.scala +++ b/core/src/main/scala/org/http4s/headers/Content-Type.scala @@ -18,7 +18,7 @@ final case class `Content-Type` private (mediaType: MediaType, charset: Option[C override def key: `Content-Type`.type = `Content-Type` override def renderValue(writer: Writer): writer.type = charset match { case Some(cs) => writer << mediaType << "; charset=" << cs - case _ => MediaRange.http4sInstancesForMediaRange.render(writer, mediaType) + case _ => MediaRange.http4sHttpCodecForMediaRange.render(writer, mediaType) } def withMediaType(mediaType: MediaType): `Content-Type` = diff --git a/tests/src/test/scala/org/http4s/parser/AcceptHeaderSpec.scala b/tests/src/test/scala/org/http4s/parser/AcceptHeaderSpec.scala index da2c26cfd06..6e8c054d475 100644 --- a/tests/src/test/scala/org/http4s/parser/AcceptHeaderSpec.scala +++ b/tests/src/test/scala/org/http4s/parser/AcceptHeaderSpec.scala @@ -64,7 +64,8 @@ class AcceptHeaderSpec extends Specification with HeaderParserHelper[Accept] { // Go through all of them with q and extensions { - val samples = MediaRange.standard.values.map(_.withExtensions(ext).withQValue(QValue.q(0.2))) + val samples = + MediaRange.standard.values.map(_.withExtensions(ext).withQValue(QValue.q(0.2))) foreach(samples.sliding(4).toArray) { sample => val h = Accept(sample.head, sample.tail.toSeq: _*) parse(h.value) must be_===(h) diff --git a/tests/src/test/scala/org/http4s/parser/AcceptLanguageSpec.scala b/tests/src/test/scala/org/http4s/parser/AcceptLanguageSpec.scala index eeebe7f4247..d8ea3283769 100644 --- a/tests/src/test/scala/org/http4s/parser/AcceptLanguageSpec.scala +++ b/tests/src/test/scala/org/http4s/parser/AcceptLanguageSpec.scala @@ -4,9 +4,7 @@ package parser import org.http4s.headers.`Accept-Language` import org.specs2.mutable.Specification -class AcceptLanguageSpec - extends Specification - with HeaderParserHelper[`Accept-Language`] { +class AcceptLanguageSpec extends Specification with HeaderParserHelper[`Accept-Language`] { def hparse(value: String): ParseResult[`Accept-Language`] = HttpHeaderParser.ACCEPT_LANGUAGE(value) From b2e409beb60aa24fb8eb7ee914489210564fe5c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Madsen?= Date: Tue, 30 Oct 2018 10:44:53 +0100 Subject: [PATCH 05/10] Remove UriFunctions --- .../scala/org/http4s/client/ClientSyntaxSpec.scala | 1 + .../http4s/client/middleware/FollowRedirectSpec.scala | 1 + .../org/http4s/client/middleware/LoggerSpec.scala | 1 + .../org/http4s/client/middleware/RetrySpec.scala | 1 + core/src/main/scala/org/http4s/Http4s.scala | 6 ++---- core/src/main/scala/org/http4s/Uri.scala | 11 +++++------ .../dropwizard/DropwizardClientMetricsSpec.scala | 1 + .../dropwizard/DropwizardServerMetricsSpec.scala | 3 ++- dsl/src/main/scala/org/http4s/dsl/Http4sDsl.scala | 4 ++-- .../scala/org/http4s/dsl/PathInHttpRoutesSpec.scala | 1 + dsl/src/test/scala/org/http4s/dsl/PathSpec.scala | 1 + .../com/example/http4s/blaze/ClientPostExample.scala | 1 + .../scala/com/example/http4s/ExampleService.scala | 2 +- .../prometheus/PrometheusServerMetricsSpec.scala | 1 + .../test/scala/org/http4s/server/HttpRoutesSpec.scala | 1 + .../src/test/scala/org/http4s/server/RouterSpec.scala | 1 + .../org/http4s/server/middleware/AutoSlashSpec.scala | 1 + .../http4s/server/middleware/DefaultHeadSpec.scala | 1 + .../http4s/server/middleware/EntityLimiterSpec.scala | 1 + .../org/http4s/server/middleware/HeaderEchoSpec.scala | 1 + .../org/http4s/server/middleware/LoggerSpec.scala | 1 + .../http4s/server/middleware/ResponseTimingSpec.scala | 2 +- .../http4s/server/middleware/StaticHeadersSpec.scala | 1 + .../org/http4s/server/middleware/ThrottleSpec.scala | 11 ++++++----- .../org/http4s/server/middleware/TimeoutSpec.scala | 1 + .../http4s/server/middleware/VirtualHostSpec.scala | 3 ++- .../http4s/server/staticcontent/FileServiceSpec.scala | 1 + .../server/staticcontent/ResourceServiceSpec.scala | 1 + .../server/staticcontent/WebjarServiceSpec.scala | 1 + testing/src/test/scala/org/http4s/Http4sSpec.scala | 1 - 30 files changed, 42 insertions(+), 22 deletions(-) diff --git a/client/src/test/scala/org/http4s/client/ClientSyntaxSpec.scala b/client/src/test/scala/org/http4s/client/ClientSyntaxSpec.scala index cb58f4df711..f21e1cabe5d 100644 --- a/client/src/test/scala/org/http4s/client/ClientSyntaxSpec.scala +++ b/client/src/test/scala/org/http4s/client/ClientSyntaxSpec.scala @@ -10,6 +10,7 @@ import org.http4s.MediaType import org.http4s.Status.{BadRequest, Created, InternalServerError, Ok} import org.http4s.client.dsl.Http4sClientDsl import org.http4s.headers.Accept +import org.http4s.Uri.uri import org.specs2.matcher.MustThrownMatchers class ClientSyntaxSpec extends Http4sSpec with Http4sClientDsl[IO] with MustThrownMatchers { diff --git a/client/src/test/scala/org/http4s/client/middleware/FollowRedirectSpec.scala b/client/src/test/scala/org/http4s/client/middleware/FollowRedirectSpec.scala index 95aba6d20b1..b48ee9943c6 100644 --- a/client/src/test/scala/org/http4s/client/middleware/FollowRedirectSpec.scala +++ b/client/src/test/scala/org/http4s/client/middleware/FollowRedirectSpec.scala @@ -9,6 +9,7 @@ import java.util.concurrent.atomic._ import org.http4s.client.dsl.Http4sClientDsl import org.http4s.dsl.io._ import org.http4s.headers._ +import org.http4s.Uri.uri import org.specs2.mutable.Tables class FollowRedirectSpec extends Http4sSpec with Http4sClientDsl[IO] with Tables { diff --git a/client/src/test/scala/org/http4s/client/middleware/LoggerSpec.scala b/client/src/test/scala/org/http4s/client/middleware/LoggerSpec.scala index ccf11065f34..aef785a2cee 100644 --- a/client/src/test/scala/org/http4s/client/middleware/LoggerSpec.scala +++ b/client/src/test/scala/org/http4s/client/middleware/LoggerSpec.scala @@ -4,6 +4,7 @@ package middleware import cats.effect._ import fs2.io.readInputStream +import org.http4s.Uri.uri import org.http4s.dsl.io._ import scala.io.Source diff --git a/client/src/test/scala/org/http4s/client/middleware/RetrySpec.scala b/client/src/test/scala/org/http4s/client/middleware/RetrySpec.scala index 0f51a183cfe..cd9f54b26a6 100644 --- a/client/src/test/scala/org/http4s/client/middleware/RetrySpec.scala +++ b/client/src/test/scala/org/http4s/client/middleware/RetrySpec.scala @@ -7,6 +7,7 @@ import cats.effect.concurrent.Ref import cats.implicits.{catsSyntaxEither => _, _} import fs2.Stream import org.http4s.dsl.io._ +import org.http4s.Uri.uri import org.specs2.specification.Tables import scala.concurrent.duration._ diff --git a/core/src/main/scala/org/http4s/Http4s.scala b/core/src/main/scala/org/http4s/Http4s.scala index 751b85b1dd2..9f17b3cfbaa 100644 --- a/core/src/main/scala/org/http4s/Http4s.scala +++ b/core/src/main/scala/org/http4s/Http4s.scala @@ -7,15 +7,13 @@ trait Http4s extends Http4sInstances with Http4sFunctions with syntax.AllSyntax object Http4s extends Http4s @deprecated("Import from or use EntityDecoder/EntityEncoder directly instead", "0.20.0-M2") -trait Http4sInstances - extends EntityDecoderInstances - with EntityEncoderInstances +trait Http4sInstances extends EntityDecoderInstances with EntityEncoderInstances @deprecated("Import from or use EntityDecoder/EntityEncoder directly instead", "0.20.0-M2") object Http4sInstances extends Http4sInstances @deprecated("Use org.http4s.qvalue._ or org.http4s.Uri._ instead", "0.20.0-M2") -trait Http4sFunctions extends UriFunctions +trait Http4sFunctions @deprecated("Use org.http4s.qvalue._ or org.http4s.Uri._ instead", "0.20.0-M2") object Http4sFunctions extends Http4sFunctions diff --git a/core/src/main/scala/org/http4s/Uri.scala b/core/src/main/scala/org/http4s/Uri.scala index c31fc4a5ca6..0198fb34cf8 100644 --- a/core/src/main/scala/org/http4s/Uri.scala +++ b/core/src/main/scala/org/http4s/Uri.scala @@ -4,8 +4,8 @@ import cats._ import cats.implicits.{catsSyntaxEither => _, _} import java.nio.charset.StandardCharsets import org.http4s.Uri._ -import org.http4s.internal.parboiled2.{Parser => PbParser} import org.http4s.internal.parboiled2.CharPredicate.{Alpha, Digit} +import org.http4s.internal.parboiled2.{Parser => PbParser} import org.http4s.parser._ import org.http4s.syntax.string._ import org.http4s.util._ @@ -14,6 +14,7 @@ import scala.math.Ordered import scala.reflect.macros.whitebox /** Representation of the [[Request]] URI + * * @param scheme optional Uri Scheme. eg, http, https * @param authority optional Uri Authority. eg, localhost:8080, www.foo.bar * @param path url-encoded string representation of the path component of the Uri. @@ -117,7 +118,7 @@ final case class Uri( override protected def replaceQuery(query: Query): Self = copy(query = query) } -object Uri extends UriFunctions { +object Uri { class Macros(val c: whitebox.Context) { import c.universe._ @@ -370,13 +371,11 @@ object Uri extends UriFunctions { case n => b.setLength(n) } - implicit val http4sUriEq: Eq[Uri] = Eq.fromUniversalEquals -} - -trait UriFunctions { /** * Literal syntax for URIs. Invalid or non-literal arguments are rejected * at compile time. */ def uri(s: String): Uri = macro Uri.Macros.uriLiteral + + implicit val http4sUriEq: Eq[Uri] = Eq.fromUniversalEquals } diff --git a/dropwizard-metrics/src/test/scala/org/http4s/metrics/dropwizard/DropwizardClientMetricsSpec.scala b/dropwizard-metrics/src/test/scala/org/http4s/metrics/dropwizard/DropwizardClientMetricsSpec.scala index 8401317e6df..0006633d0fd 100644 --- a/dropwizard-metrics/src/test/scala/org/http4s/metrics/dropwizard/DropwizardClientMetricsSpec.scala +++ b/dropwizard-metrics/src/test/scala/org/http4s/metrics/dropwizard/DropwizardClientMetricsSpec.scala @@ -9,6 +9,7 @@ import org.http4s.client.{Client, UnexpectedStatus} import org.http4s.client.middleware.Metrics import org.http4s.dsl.io._ import org.http4s.metrics.dropwizard.util._ +import org.http4s.Uri.uri class DropwizardMetricsSpec extends Http4sSpec { diff --git a/dropwizard-metrics/src/test/scala/org/http4s/metrics/dropwizard/DropwizardServerMetricsSpec.scala b/dropwizard-metrics/src/test/scala/org/http4s/metrics/dropwizard/DropwizardServerMetricsSpec.scala index f6895c7aea5..4c12225b3af 100644 --- a/dropwizard-metrics/src/test/scala/org/http4s/metrics/dropwizard/DropwizardServerMetricsSpec.scala +++ b/dropwizard-metrics/src/test/scala/org/http4s/metrics/dropwizard/DropwizardServerMetricsSpec.scala @@ -2,10 +2,11 @@ package org.http4s.metrics.dropwizard import cats.effect.IO import com.codahale.metrics.{MetricRegistry, SharedMetricRegistries} -import org.http4s.{Http4sSpec, HttpRoutes, Request, Status} +import org.http4s.Uri.uri import org.http4s.dsl.io._ import org.http4s.metrics.dropwizard.util._ import org.http4s.server.middleware.Metrics +import org.http4s.{Http4sSpec, HttpRoutes, Request, Status} class DropwizardServerMetricsSpec extends Http4sSpec { diff --git a/dsl/src/main/scala/org/http4s/dsl/Http4sDsl.scala b/dsl/src/main/scala/org/http4s/dsl/Http4sDsl.scala index c2ae21426b0..4f8577c16fc 100644 --- a/dsl/src/main/scala/org/http4s/dsl/Http4sDsl.scala +++ b/dsl/src/main/scala/org/http4s/dsl/Http4sDsl.scala @@ -1,9 +1,9 @@ package org.http4s.dsl -import org.http4s.{Method, UriFunctions} +import org.http4s.Method import org.http4s.dsl.impl._ -trait Http4sDsl[F[_]] extends UriFunctions with Methods with Statuses with Responses[F] with Auth { +trait Http4sDsl[F[_]] extends Methods with Statuses with Responses[F] with Auth { import Http4sDsl._ type Path = impl.Path diff --git a/dsl/src/test/scala/org/http4s/dsl/PathInHttpRoutesSpec.scala b/dsl/src/test/scala/org/http4s/dsl/PathInHttpRoutesSpec.scala index 04adf3ce80d..666d8f51f99 100644 --- a/dsl/src/test/scala/org/http4s/dsl/PathInHttpRoutesSpec.scala +++ b/dsl/src/test/scala/org/http4s/dsl/PathInHttpRoutesSpec.scala @@ -5,6 +5,7 @@ import cats.data.Validated._ import cats.effect.IO import cats.implicits._ import org.http4s.dsl.io._ +import org.http4s.Uri.uri object PathInHttpRoutesSpec extends Http4sSpec { diff --git a/dsl/src/test/scala/org/http4s/dsl/PathSpec.scala b/dsl/src/test/scala/org/http4s/dsl/PathSpec.scala index 4d817a3603e..e2fab512aee 100644 --- a/dsl/src/test/scala/org/http4s/dsl/PathSpec.scala +++ b/dsl/src/test/scala/org/http4s/dsl/PathSpec.scala @@ -9,6 +9,7 @@ package dsl import cats.effect.IO import org.http4s.dsl.io._ +import org.http4s.Uri.uri class PathSpec extends Http4sSpec { "Path" should { diff --git a/examples/blaze/src/main/scala/com/example/http4s/blaze/ClientPostExample.scala b/examples/blaze/src/main/scala/com/example/http4s/blaze/ClientPostExample.scala index 7445c0ef50e..79c8b792294 100644 --- a/examples/blaze/src/main/scala/com/example/http4s/blaze/ClientPostExample.scala +++ b/examples/blaze/src/main/scala/com/example/http4s/blaze/ClientPostExample.scala @@ -6,6 +6,7 @@ import org.http4s._ import org.http4s.client.blaze.BlazeClientBuilder import org.http4s.client.dsl.Http4sClientDsl import org.http4s.dsl.io._ +import org.http4s.Uri.uri import scala.concurrent.ExecutionContext.Implicits.global object ClientPostExample extends IOApp with Http4sClientDsl[IO] { diff --git a/examples/src/main/scala/com/example/http4s/ExampleService.scala b/examples/src/main/scala/com/example/http4s/ExampleService.scala index b9d66b6277d..b0d345b1c00 100644 --- a/examples/src/main/scala/com/example/http4s/ExampleService.scala +++ b/examples/src/main/scala/com/example/http4s/ExampleService.scala @@ -53,7 +53,7 @@ class ExampleService[F[_]](implicit F: Effect[F], cs: ContextShift[F]) extends H case GET -> Root / "redirect" => // Not every response must be Ok using a EntityEncoder: some have meaning only for specific types - TemporaryRedirect(Location(uri("/http4s/"))) + TemporaryRedirect(Location(Uri.uri("/http4s/"))) case GET -> Root / "content-change" => // EntityEncoder typically deals with appropriate headers, but they can be overridden diff --git a/prometheus-metrics/src/test/scala/org/http4s/metrics/prometheus/PrometheusServerMetricsSpec.scala b/prometheus-metrics/src/test/scala/org/http4s/metrics/prometheus/PrometheusServerMetricsSpec.scala index 2b97ffd1c60..133e3c1770c 100644 --- a/prometheus-metrics/src/test/scala/org/http4s/metrics/prometheus/PrometheusServerMetricsSpec.scala +++ b/prometheus-metrics/src/test/scala/org/http4s/metrics/prometheus/PrometheusServerMetricsSpec.scala @@ -7,6 +7,7 @@ import org.http4s.dsl.io._ import org.http4s.metrics.prometheus.util._ import org.http4s.server.middleware.Metrics import org.http4s.Method.GET +import org.http4s.Uri.uri class PrometheusServerMetricsSpec extends Http4sSpec { diff --git a/server/src/test/scala/org/http4s/server/HttpRoutesSpec.scala b/server/src/test/scala/org/http4s/server/HttpRoutesSpec.scala index 3199ddb7018..9d574246836 100644 --- a/server/src/test/scala/org/http4s/server/HttpRoutesSpec.scala +++ b/server/src/test/scala/org/http4s/server/HttpRoutesSpec.scala @@ -3,6 +3,7 @@ package server import cats.effect._ import cats.implicits._ +import org.http4s.Uri.uri class HttpRoutesSpec extends Http4sSpec { diff --git a/server/src/test/scala/org/http4s/server/RouterSpec.scala b/server/src/test/scala/org/http4s/server/RouterSpec.scala index 555c10d6440..2356319d6b7 100644 --- a/server/src/test/scala/org/http4s/server/RouterSpec.scala +++ b/server/src/test/scala/org/http4s/server/RouterSpec.scala @@ -2,6 +2,7 @@ package org.http4s package server import cats.effect._ +import org.http4s.Uri.uri import org.http4s.dsl.io._ class RouterSpec extends Http4sSpec { diff --git a/server/src/test/scala/org/http4s/server/middleware/AutoSlashSpec.scala b/server/src/test/scala/org/http4s/server/middleware/AutoSlashSpec.scala index 2ca1f4c023a..d92cb122548 100644 --- a/server/src/test/scala/org/http4s/server/middleware/AutoSlashSpec.scala +++ b/server/src/test/scala/org/http4s/server/middleware/AutoSlashSpec.scala @@ -3,6 +3,7 @@ package org.http4s.server.middleware import cats.effect._ import org.http4s.{Http4sSpec, HttpRoutes, Request, Status} import org.http4s.server.{MockRoute, Router} +import org.http4s.Uri.uri class AutoSlashSpec extends Http4sSpec { diff --git a/server/src/test/scala/org/http4s/server/middleware/DefaultHeadSpec.scala b/server/src/test/scala/org/http4s/server/middleware/DefaultHeadSpec.scala index 7cbb2925722..85bcff49c91 100644 --- a/server/src/test/scala/org/http4s/server/middleware/DefaultHeadSpec.scala +++ b/server/src/test/scala/org/http4s/server/middleware/DefaultHeadSpec.scala @@ -5,6 +5,7 @@ package middleware import cats.effect._ import fs2.Stream._ import org.http4s.dsl.io._ +import org.http4s.Uri.uri class DefaultHeadSpec extends Http4sSpec { val app = DefaultHead(HttpRoutes.of[IO] { diff --git a/server/src/test/scala/org/http4s/server/middleware/EntityLimiterSpec.scala b/server/src/test/scala/org/http4s/server/middleware/EntityLimiterSpec.scala index c7fafaa02d4..0a19d0b3c12 100644 --- a/server/src/test/scala/org/http4s/server/middleware/EntityLimiterSpec.scala +++ b/server/src/test/scala/org/http4s/server/middleware/EntityLimiterSpec.scala @@ -10,6 +10,7 @@ import java.nio.charset.StandardCharsets import org.http4s.server.middleware.EntityLimiter.EntityTooLarge import org.http4s.Method._ import org.http4s.Status._ +import org.http4s.Uri.uri class EntityLimiterSpec extends Http4sSpec { diff --git a/server/src/test/scala/org/http4s/server/middleware/HeaderEchoSpec.scala b/server/src/test/scala/org/http4s/server/middleware/HeaderEchoSpec.scala index 63bbe2c2821..3fc7997b52e 100644 --- a/server/src/test/scala/org/http4s/server/middleware/HeaderEchoSpec.scala +++ b/server/src/test/scala/org/http4s/server/middleware/HeaderEchoSpec.scala @@ -3,6 +3,7 @@ package org.http4s.server.middleware import cats.effect.IO import org.http4s._ import org.http4s.dsl.io._ +import org.http4s.Uri.uri import org.http4s.util.CaseInsensitiveString class HeaderEchoSpec extends Http4sSpec { diff --git a/server/src/test/scala/org/http4s/server/middleware/LoggerSpec.scala b/server/src/test/scala/org/http4s/server/middleware/LoggerSpec.scala index 1a99764ed17..7b7100246b4 100644 --- a/server/src/test/scala/org/http4s/server/middleware/LoggerSpec.scala +++ b/server/src/test/scala/org/http4s/server/middleware/LoggerSpec.scala @@ -5,6 +5,7 @@ package middleware import cats.effect._ import fs2.io.readInputStream import org.http4s.dsl.io._ +import org.http4s.Uri.uri import scala.io.Source /** diff --git a/server/src/test/scala/org/http4s/server/middleware/ResponseTimingSpec.scala b/server/src/test/scala/org/http4s/server/middleware/ResponseTimingSpec.scala index 26d8a4e510e..0801ec29f62 100644 --- a/server/src/test/scala/org/http4s/server/middleware/ResponseTimingSpec.scala +++ b/server/src/test/scala/org/http4s/server/middleware/ResponseTimingSpec.scala @@ -22,7 +22,7 @@ class ResponseTimingSpec extends Http4sSpec { "ResponseTiming middleware" should { "add a custom header with timing info" in { - val req = Request[IO](uri = uri("/request")) + val req = Request[IO](uri = Uri.uri("/request")) val app = ResponseTiming(thisService) val res = app(req) diff --git a/server/src/test/scala/org/http4s/server/middleware/StaticHeadersSpec.scala b/server/src/test/scala/org/http4s/server/middleware/StaticHeadersSpec.scala index 15cb4584367..9b9ab3aaf9a 100644 --- a/server/src/test/scala/org/http4s/server/middleware/StaticHeadersSpec.scala +++ b/server/src/test/scala/org/http4s/server/middleware/StaticHeadersSpec.scala @@ -3,6 +3,7 @@ package org.http4s.server.middleware import cats.effect._ import org.http4s._ import org.http4s.dsl.io._ +import org.http4s.Uri.uri class StaticHeadersSpec extends Http4sSpec { diff --git a/server/src/test/scala/org/http4s/server/middleware/ThrottleSpec.scala b/server/src/test/scala/org/http4s/server/middleware/ThrottleSpec.scala index e86f957d577..b188e687d9d 100644 --- a/server/src/test/scala/org/http4s/server/middleware/ThrottleSpec.scala +++ b/server/src/test/scala/org/http4s/server/middleware/ThrottleSpec.scala @@ -1,15 +1,16 @@ package org.http4s.server.middleware -import cats.effect.{IO, Timer} +import cats.effect.IO.ioEffect import cats.effect.laws.util.TestContext -import org.http4s.{Http4sSpec, HttpApp, Request, Status} +import cats.effect.{IO, Timer} import cats.implicits._ +import org.http4s.Uri.uri import org.http4s.dsl.io._ -import cats.effect.IO.ioEffect +import org.http4s.server.middleware.Throttle._ +import org.http4s.{Http4sSpec, HttpApp, Request, Status} +import org.specs2.concurrent.ExecutionEnv import org.specs2.matcher.FutureMatchers import scala.concurrent.duration._ -import org.specs2.concurrent.ExecutionEnv -import Throttle._ class ThrottleSpec(implicit ee: ExecutionEnv) extends Http4sSpec with FutureMatchers { "LocalTokenBucket" should { diff --git a/server/src/test/scala/org/http4s/server/middleware/TimeoutSpec.scala b/server/src/test/scala/org/http4s/server/middleware/TimeoutSpec.scala index af49dcd3c5c..42862d83c71 100644 --- a/server/src/test/scala/org/http4s/server/middleware/TimeoutSpec.scala +++ b/server/src/test/scala/org/http4s/server/middleware/TimeoutSpec.scala @@ -7,6 +7,7 @@ import cats.effect._ import java.util.concurrent.TimeoutException import java.util.concurrent.atomic.AtomicBoolean import org.http4s.dsl.io._ +import org.http4s.Uri.uri import scala.concurrent.duration._ class TimeoutSpec extends Http4sSpec { diff --git a/server/src/test/scala/org/http4s/server/middleware/VirtualHostSpec.scala b/server/src/test/scala/org/http4s/server/middleware/VirtualHostSpec.scala index 1991ce57781..b3c61c1230e 100644 --- a/server/src/test/scala/org/http4s/server/middleware/VirtualHostSpec.scala +++ b/server/src/test/scala/org/http4s/server/middleware/VirtualHostSpec.scala @@ -5,8 +5,9 @@ package middleware import cats.effect._ import cats.syntax.applicative._ import org.http4s.Method._ -import org.http4s.headers.Host import org.http4s.Status.{BadRequest, NotFound, Ok} +import org.http4s.Uri.uri +import org.http4s.headers.Host class VirtualHostSpec extends Http4sSpec { diff --git a/server/src/test/scala/org/http4s/server/staticcontent/FileServiceSpec.scala b/server/src/test/scala/org/http4s/server/staticcontent/FileServiceSpec.scala index 3e6b4d8031b..5eaee423109 100644 --- a/server/src/test/scala/org/http4s/server/staticcontent/FileServiceSpec.scala +++ b/server/src/test/scala/org/http4s/server/staticcontent/FileServiceSpec.scala @@ -5,6 +5,7 @@ package staticcontent import cats.effect._ import fs2._ import java.io.File +import org.http4s.Uri.uri import org.http4s.server.middleware.TranslateUri class FileServiceSpec extends Http4sSpec with StaticContentShared { diff --git a/server/src/test/scala/org/http4s/server/staticcontent/ResourceServiceSpec.scala b/server/src/test/scala/org/http4s/server/staticcontent/ResourceServiceSpec.scala index 3b12ef611f9..b10040d84b1 100644 --- a/server/src/test/scala/org/http4s/server/staticcontent/ResourceServiceSpec.scala +++ b/server/src/test/scala/org/http4s/server/staticcontent/ResourceServiceSpec.scala @@ -5,6 +5,7 @@ package staticcontent import cats.effect._ import org.http4s.headers.{`Accept-Encoding`, `If-Modified-Since`} import org.http4s.server.middleware.TranslateUri +import org.http4s.Uri.uri class ResourceServiceSpec extends Http4sSpec with StaticContentShared { diff --git a/server/src/test/scala/org/http4s/server/staticcontent/WebjarServiceSpec.scala b/server/src/test/scala/org/http4s/server/staticcontent/WebjarServiceSpec.scala index 382e8a9c2c3..d468d6fb734 100644 --- a/server/src/test/scala/org/http4s/server/staticcontent/WebjarServiceSpec.scala +++ b/server/src/test/scala/org/http4s/server/staticcontent/WebjarServiceSpec.scala @@ -4,6 +4,7 @@ package staticcontent import cats.effect._ import org.http4s.Method.{GET, POST} +import org.http4s.Uri.uri import org.http4s.server.staticcontent.WebjarService.Config object WebjarServiceSpec extends Http4sSpec with StaticContentShared { diff --git a/testing/src/test/scala/org/http4s/Http4sSpec.scala b/testing/src/test/scala/org/http4s/Http4sSpec.scala index b5a580aba71..da11c0df4f8 100644 --- a/testing/src/test/scala/org/http4s/Http4sSpec.scala +++ b/testing/src/test/scala/org/http4s/Http4sSpec.scala @@ -40,7 +40,6 @@ trait Http4sSpec with AnyMatchers with OptionMatchers with syntax.AllSyntax - with UriFunctions with EntityDecoderInstances with EntityEncoderInstances with ArbitraryInstances From 7f63b513d9459a6fee2e7a6d4bf4dae92e735383 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Madsen?= Date: Thu, 1 Nov 2018 12:12:33 +0100 Subject: [PATCH 06/10] Fix Order instance for HttpVersion --- core/src/main/scala/org/http4s/HttpVersion.scala | 4 ++-- twirl/src/test/scala/org/http4s/twirl/TwirlSpec.scala | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/core/src/main/scala/org/http4s/HttpVersion.scala b/core/src/main/scala/org/http4s/HttpVersion.scala index 74f93c504c4..71d23f36b1c 100644 --- a/core/src/main/scala/org/http4s/HttpVersion.scala +++ b/core/src/main/scala/org/http4s/HttpVersion.scala @@ -52,7 +52,7 @@ object HttpVersion { else ParseResult.success(new HttpVersion(major, minor)) implicit val http4sHttpOrderForVersion: Order[HttpVersion] = - Order.fromOrdering[HttpVersion] + Order.fromComparable implicit val http4sHttpShowForVersion: Show[HttpVersion] = - Show.fromToString[HttpVersion] + Show.fromToString } diff --git a/twirl/src/test/scala/org/http4s/twirl/TwirlSpec.scala b/twirl/src/test/scala/org/http4s/twirl/TwirlSpec.scala index cd19887ec2c..941047adfc9 100644 --- a/twirl/src/test/scala/org/http4s/twirl/TwirlSpec.scala +++ b/twirl/src/test/scala/org/http4s/twirl/TwirlSpec.scala @@ -22,7 +22,7 @@ class TwirlSpec extends Http4sSpec { "HTML encoder" should { "return Content-Type text/html with proper charset" in prop { implicit cs: Charset => val headers = EntityEncoder[IO, Html].headers - headers.get(`Content-Type`) must_== Some(`Content-Type`(MediaType.text.html, Some(cs))) + headers.get(`Content-Type`) must beSome(`Content-Type`(MediaType.text.html, Some(cs))) } "render the body" in prop { implicit cs: Charset => @@ -35,8 +35,7 @@ class TwirlSpec extends Http4sSpec { "return Content-Type application/javascript with proper charset" in prop { implicit cs: Charset => val headers = EntityEncoder[IO, JavaScript].headers - headers.get(`Content-Type`) must_== Some( - `Content-Type`(MediaType.application.javascript, Some(cs))) + headers.get(`Content-Type`) must beSome(`Content-Type`(MediaType.application.javascript, Some(cs))) } "render the body" in prop { implicit cs: Charset => @@ -48,7 +47,7 @@ class TwirlSpec extends Http4sSpec { "Text encoder" should { "return Content-Type text/plain with proper charset" in prop { implicit cs: Charset => val headers = EntityEncoder[IO, Txt].headers - headers.get(`Content-Type`) must_== Some(`Content-Type`(MediaType.text.plain, Some(cs))) + headers.get(`Content-Type`) must beSome(`Content-Type`(MediaType.text.plain, Some(cs))) } "render the body" in prop { implicit cs: Charset => @@ -60,7 +59,7 @@ class TwirlSpec extends Http4sSpec { "XML encoder" should { "return Content-Type application/xml with proper charset" in prop { implicit cs: Charset => val headers = EntityEncoder[IO, Xml].headers - headers.get(`Content-Type`) must_== Some(`Content-Type`(MediaType.application.xml, Some(cs))) + headers.get(`Content-Type`) must beSome(`Content-Type`(MediaType.application.xml, Some(cs))) } "render the body" in prop { implicit cs: Charset => From b7a77e708a4e8a6489a9e4c5ee196dc2d2999d9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Madsen?= Date: Thu, 1 Nov 2018 12:22:41 +0100 Subject: [PATCH 07/10] Don't mix in Entity{De,En}coderInstances in Http4sSpec --- .../scala/org/http4s/scalatags/ScalatagsSpec.scala | 2 +- testing/src/test/scala/org/http4s/Http4sSpec.scala | 2 -- .../src/test/scala/org/http4s/EntityDecoderSpec.scala | 10 +++++----- twirl/src/test/scala/org/http4s/twirl/TwirlSpec.scala | 8 ++++---- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/scalatags/src/test/scala/org/http4s/scalatags/ScalatagsSpec.scala b/scalatags/src/test/scala/org/http4s/scalatags/ScalatagsSpec.scala index 4a82d4b3e0a..6dce02cc02f 100644 --- a/scalatags/src/test/scala/org/http4s/scalatags/ScalatagsSpec.scala +++ b/scalatags/src/test/scala/org/http4s/scalatags/ScalatagsSpec.scala @@ -35,7 +35,7 @@ class ScalatagsSpec extends Http4sSpec { "render the body" in { val resp = Response[IO](Ok).withEntity(testBody()) - text[IO].decode(resp, strict = false).value.unsafeRunSync must beRight( + EntityDecoder.text[IO].decode(resp, strict = false).value.unsafeRunSync must beRight( "

this is my testBody

") } } diff --git a/testing/src/test/scala/org/http4s/Http4sSpec.scala b/testing/src/test/scala/org/http4s/Http4sSpec.scala index da11c0df4f8..07cb9c45ef9 100644 --- a/testing/src/test/scala/org/http4s/Http4sSpec.scala +++ b/testing/src/test/scala/org/http4s/Http4sSpec.scala @@ -40,8 +40,6 @@ trait Http4sSpec with AnyMatchers with OptionMatchers with syntax.AllSyntax - with EntityDecoderInstances - with EntityEncoderInstances with ArbitraryInstances with FragmentsDsl with Discipline diff --git a/tests/src/test/scala/org/http4s/EntityDecoderSpec.scala b/tests/src/test/scala/org/http4s/EntityDecoderSpec.scala index ca795525d97..a70c07d5f57 100644 --- a/tests/src/test/scala/org/http4s/EntityDecoderSpec.scala +++ b/tests/src/test/scala/org/http4s/EntityDecoderSpec.scala @@ -370,7 +370,7 @@ class EntityDecoderSpec extends Http4sSpec with PendingUntilFixed { val tmpFile = File.createTempFile("foo", "bar") try { val response = mockServe(Request()) { req => - req.decodeWith(textFile(tmpFile, testBlockingExecutionContext), strict = false) { _ => + req.decodeWith(EntityDecoder.textFile(tmpFile, testBlockingExecutionContext), strict = false) { _ => Response[IO](Ok).withEntity("Hello").pure[IO] } }.unsafeRunSync @@ -389,7 +389,7 @@ class EntityDecoderSpec extends Http4sSpec with PendingUntilFixed { try { val response = mockServe(Request()) { case req => - req.decodeWith(binFile(tmpFile, testBlockingExecutionContext), strict = false) { _ => + req.decodeWith(EntityDecoder.binFile(tmpFile, testBlockingExecutionContext), strict = false) { _ => Response[IO](Ok).withEntity("Hello").pure[IO] } }.unsafeRunSync @@ -407,7 +407,7 @@ class EntityDecoderSpec extends Http4sSpec with PendingUntilFixed { "binary EntityDecoder" should { "yield an empty array on a bodyless message" in { val msg = Request[IO]() - binary[IO].decode(msg, strict = false) must returnRight(Chunk.empty[Byte]) + EntityDecoder.binary[IO].decode(msg, strict = false) must returnRight(Chunk.empty[Byte]) } "concat Chunks" in { @@ -415,11 +415,11 @@ class EntityDecoderSpec extends Http4sSpec with PendingUntilFixed { val body = chunk(Chunk.bytes(d1)) ++ chunk(Chunk.bytes(d2)) val msg = Request[IO](body = body) val expected = Chunk.bytes(Array[Byte](1, 2, 3, 4, 5, 6)) - binary[IO].decode(msg, strict = false) must returnRight(expected) + EntityDecoder.binary[IO].decode(msg, strict = false) must returnRight(expected) } "Match any media type" in { - binary[IO].matchesMediaType(MediaType.text.plain) must_== true + EntityDecoder.binary[IO].matchesMediaType(MediaType.text.plain) must_== true } } diff --git a/twirl/src/test/scala/org/http4s/twirl/TwirlSpec.scala b/twirl/src/test/scala/org/http4s/twirl/TwirlSpec.scala index 941047adfc9..d08e1a0f29e 100644 --- a/twirl/src/test/scala/org/http4s/twirl/TwirlSpec.scala +++ b/twirl/src/test/scala/org/http4s/twirl/TwirlSpec.scala @@ -27,7 +27,7 @@ class TwirlSpec extends Http4sSpec { "render the body" in prop { implicit cs: Charset => val resp = Response[IO](Ok).withEntity(html.test()) - text[IO].decode(resp, strict = false).value.unsafeRunSync must beRight("

test html

") + EntityDecoder.text[IO].decode(resp, strict = false).value.unsafeRunSync must beRight("

test html

") } } @@ -40,7 +40,7 @@ class TwirlSpec extends Http4sSpec { "render the body" in prop { implicit cs: Charset => val resp = Response[IO](Ok).withEntity(js.test()) - text[IO].decode(resp, strict = false).value.unsafeRunSync must beRight(""""test js"""") + EntityDecoder.text[IO].decode(resp, strict = false).value.unsafeRunSync must beRight(""""test js"""") } } @@ -52,7 +52,7 @@ class TwirlSpec extends Http4sSpec { "render the body" in prop { implicit cs: Charset => val resp = Response[IO](Ok).withEntity(txt.test()) - text[IO].decode(resp, strict = false).value.unsafeRunSync must beRight("""test text""") + EntityDecoder.text[IO].decode(resp, strict = false).value.unsafeRunSync must beRight("""test text""") } } @@ -64,7 +64,7 @@ class TwirlSpec extends Http4sSpec { "render the body" in prop { implicit cs: Charset => val resp = Response[IO](Ok).withEntity(_root_.xml.test()) - text[IO].decode(resp, strict = false).value.unsafeRunSync must beRight( + EntityDecoder.text[IO].decode(resp, strict = false).value.unsafeRunSync must beRight( "test xml") } } From caf2d4936b91b8ad66e01853b73369bb403395f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Madsen?= Date: Thu, 1 Nov 2018 12:30:31 +0100 Subject: [PATCH 08/10] Formatting --- .../test/scala/org/http4s/EntityDecoderSpec.scala | 8 ++++++-- .../src/test/scala/org/http4s/twirl/TwirlSpec.scala | 12 ++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/tests/src/test/scala/org/http4s/EntityDecoderSpec.scala b/tests/src/test/scala/org/http4s/EntityDecoderSpec.scala index a70c07d5f57..729f1bea30a 100644 --- a/tests/src/test/scala/org/http4s/EntityDecoderSpec.scala +++ b/tests/src/test/scala/org/http4s/EntityDecoderSpec.scala @@ -370,7 +370,9 @@ class EntityDecoderSpec extends Http4sSpec with PendingUntilFixed { val tmpFile = File.createTempFile("foo", "bar") try { val response = mockServe(Request()) { req => - req.decodeWith(EntityDecoder.textFile(tmpFile, testBlockingExecutionContext), strict = false) { _ => + req.decodeWith( + EntityDecoder.textFile(tmpFile, testBlockingExecutionContext), + strict = false) { _ => Response[IO](Ok).withEntity("Hello").pure[IO] } }.unsafeRunSync @@ -389,7 +391,9 @@ class EntityDecoderSpec extends Http4sSpec with PendingUntilFixed { try { val response = mockServe(Request()) { case req => - req.decodeWith(EntityDecoder.binFile(tmpFile, testBlockingExecutionContext), strict = false) { _ => + req.decodeWith( + EntityDecoder.binFile(tmpFile, testBlockingExecutionContext), + strict = false) { _ => Response[IO](Ok).withEntity("Hello").pure[IO] } }.unsafeRunSync diff --git a/twirl/src/test/scala/org/http4s/twirl/TwirlSpec.scala b/twirl/src/test/scala/org/http4s/twirl/TwirlSpec.scala index d08e1a0f29e..40ad5ee12c8 100644 --- a/twirl/src/test/scala/org/http4s/twirl/TwirlSpec.scala +++ b/twirl/src/test/scala/org/http4s/twirl/TwirlSpec.scala @@ -27,7 +27,8 @@ class TwirlSpec extends Http4sSpec { "render the body" in prop { implicit cs: Charset => val resp = Response[IO](Ok).withEntity(html.test()) - EntityDecoder.text[IO].decode(resp, strict = false).value.unsafeRunSync must beRight("

test html

") + EntityDecoder.text[IO].decode(resp, strict = false).value.unsafeRunSync must beRight( + "

test html

") } } @@ -35,12 +36,14 @@ class TwirlSpec extends Http4sSpec { "return Content-Type application/javascript with proper charset" in prop { implicit cs: Charset => val headers = EntityEncoder[IO, JavaScript].headers - headers.get(`Content-Type`) must beSome(`Content-Type`(MediaType.application.javascript, Some(cs))) + headers.get(`Content-Type`) must beSome( + `Content-Type`(MediaType.application.javascript, Some(cs))) } "render the body" in prop { implicit cs: Charset => val resp = Response[IO](Ok).withEntity(js.test()) - EntityDecoder.text[IO].decode(resp, strict = false).value.unsafeRunSync must beRight(""""test js"""") + EntityDecoder.text[IO].decode(resp, strict = false).value.unsafeRunSync must beRight( + """"test js"""") } } @@ -52,7 +55,8 @@ class TwirlSpec extends Http4sSpec { "render the body" in prop { implicit cs: Charset => val resp = Response[IO](Ok).withEntity(txt.test()) - EntityDecoder.text[IO].decode(resp, strict = false).value.unsafeRunSync must beRight("""test text""") + EntityDecoder.text[IO].decode(resp, strict = false).value.unsafeRunSync must beRight( + """test text""") } } From 5bd6027919c2e6a383cd66df6bb2b01c9e14f04b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Madsen?= Date: Thu, 1 Nov 2018 18:56:36 +0100 Subject: [PATCH 09/10] Update tuts --- docs/src/main/tut/cors.md | 8 ++++---- docs/src/main/tut/dsl.md | 2 +- docs/src/main/tut/gzip.md | 3 ++- docs/src/main/tut/hsts.md | 3 ++- docs/src/main/tut/json.md | 11 ++++++----- docs/src/main/tut/middleware.md | 8 ++++---- docs/src/main/tut/service.md | 1 + docs/src/main/tut/testing.md | 1 + 8 files changed, 21 insertions(+), 16 deletions(-) diff --git a/docs/src/main/tut/cors.md b/docs/src/main/tut/cors.md index 47bda8c9f25..14944eb4099 100644 --- a/docs/src/main/tut/cors.md +++ b/docs/src/main/tut/cors.md @@ -33,7 +33,7 @@ val service = HttpRoutes.of[IO] { Ok() } -val request = Request[IO](Method.GET, uri("/")) +val request = Request[IO](Method.GET, Uri.uri("/")) service.orNotFound(request).unsafeRunSync ``` @@ -70,9 +70,9 @@ First, we'll create some requests to use in our example. We want these requests have a variety of origins and methods. ```tut:book -val googleGet = Request[IO](Method.GET, uri("/"), headers = Headers(Header("Origin", "google.com"))) -val yahooPut = Request[IO](Method.PUT, uri("/"), headers = Headers(Header("Origin", "yahoo.com"))) -val duckPost = Request[IO](Method.POST, uri("/"), headers = Headers(Header("Origin", "duckduckgo.com"))) +val googleGet = Request[IO](Method.GET, Uri.uri("/"), headers = Headers(Header("Origin", "google.com"))) +val yahooPut = Request[IO](Method.PUT, Uri.uri("/"), headers = Headers(Header("Origin", "yahoo.com"))) +val duckPost = Request[IO](Method.POST, Uri.uri("/"), headers = Headers(Header("Origin", "duckduckgo.com"))) ``` Now, we'll create a configuration that limits the allowed methods to `GET` diff --git a/docs/src/main/tut/dsl.md b/docs/src/main/tut/dsl.md index 3396204b136..89dd3f13a21 100644 --- a/docs/src/main/tut/dsl.md +++ b/docs/src/main/tut/dsl.md @@ -66,7 +66,7 @@ need a server to test our route. We can construct our own request and experiment directly in the REPL. ```tut -val getRoot = Request[IO](Method.GET, uri("/")) +val getRoot = Request[IO](Method.GET, Uri.uri("/")) val io = service.orNotFound.run(getRoot) ``` diff --git a/docs/src/main/tut/gzip.md b/docs/src/main/tut/gzip.md index 72488213772..577ee36c10d 100644 --- a/docs/src/main/tut/gzip.md +++ b/docs/src/main/tut/gzip.md @@ -22,6 +22,7 @@ And we need some imports. import cats.effect._ import org.http4s._ import org.http4s.dsl.io._ +import org.http4s.implicits._ ``` Let's start by making a simple service that returns a (relatively) large string @@ -33,7 +34,7 @@ val service = HttpRoutes.of[IO] { Ok("I repeat myself when I'm under stress. " * 3) } -val request = Request[IO](Method.GET, uri("/")) +val request = Request[IO](Method.GET, Uri.uri("/")) // Do not call 'unsafeRun' in your code - see note at bottom. val response = service.orNotFound(request).unsafeRunSync diff --git a/docs/src/main/tut/hsts.md b/docs/src/main/tut/hsts.md index 9fe40d79342..6e941628440 100644 --- a/docs/src/main/tut/hsts.md +++ b/docs/src/main/tut/hsts.md @@ -22,6 +22,7 @@ And we need some imports. ```tut:silent import org.http4s._ import org.http4s.dsl.io._ +import org.http4s.implicits._ import cats.effect.IO ``` @@ -33,7 +34,7 @@ val service = HttpRoutes.of[IO] { Ok("ok") } -val request = Request[IO](Method.GET, uri("/")) +val request = Request[IO](Method.GET, Uri.uri("/")) // Do not call 'unsafeRunSync' in your code val response = service.orNotFound(request).unsafeRunSync diff --git a/docs/src/main/tut/json.md b/docs/src/main/tut/json.md index d050aaaa372..4c6872ec9dd 100644 --- a/docs/src/main/tut/json.md +++ b/docs/src/main/tut/json.md @@ -104,7 +104,7 @@ useful on client requests: import org.http4s.client._ import org.http4s.client.dsl.io._ -POST(uri("/hello"), json"""{"name": "Alice"}""").unsafeRunSync +POST(Uri.uri("/hello"), json"""{"name": "Alice"}""").unsafeRunSync ``` ## Encoding case classes as JSON @@ -159,7 +159,7 @@ and responses for our case classes: ```tut:book Ok(Hello("Alice").asJson).unsafeRunSync -POST(uri("/hello"), User("Bob").asJson).unsafeRunSync +POST(Uri.uri("/hello"), User("Bob").asJson).unsafeRunSync ``` If within some route we serve json only, we can use: @@ -185,7 +185,7 @@ response body to JSON using the [`as` syntax]: ```tut:book Ok("""{"name":"Alice"}""").flatMap(_.as[Json]).unsafeRunSync -POST(uri("/hello"),"""{"name":"Bob"}""").flatMap(_.as[Json]).unsafeRunSync +POST(Uri.uri("/hello"),"""{"name":"Bob"}""").flatMap(_.as[Json]).unsafeRunSync ``` Like sending raw JSON, this is useful to a point, but we typically @@ -202,7 +202,7 @@ an implicit `Decoder[A]` and makes a `EntityDecoder[A]`: ```tut:book implicit val userDecoder = jsonOf[IO, User] Ok("""{"name":"Alice"}""").flatMap(_.as[User]).unsafeRunSync -POST(uri("/hello"), """{"name":"Bob"}""").flatMap(_.as[User]).unsafeRunSync +POST(Uri.uri("/hello"), """{"name":"Bob"}""").flatMap(_.as[User]).unsafeRunSync ``` If we are always decoding from JSON to a typed model, we can use @@ -242,6 +242,7 @@ import io.circe.syntax._ import org.http4s._ import org.http4s.circe._ import org.http4s.dsl.io._ +import org.http4s.implicits._ import scala.concurrent.ExecutionContext.Implicits.global @@ -284,7 +285,7 @@ import fs2.Stream // Decode the Hello response def helloClient(name: String): Stream[IO, Hello] = { // Encode a User request - val req = POST(uri("http://localhost:8080/hello"), User(name).asJson) + val req = POST(Uri.uri("http://localhost:8080/hello"), User(name).asJson) // Create a client BlazeClientBuilder[IO](global).stream.flatMap { httpClient => // Decode a Hello response diff --git a/docs/src/main/tut/middleware.md b/docs/src/main/tut/middleware.md index 7f474838d92..723ece27779 100644 --- a/docs/src/main/tut/middleware.md +++ b/docs/src/main/tut/middleware.md @@ -28,8 +28,8 @@ import cats.data.Kleisli import cats.effect._ import cats.implicits._ import org.http4s._ -import org.http4s.implicits._ import org.http4s.dsl.io._ +import org.http4s.implicits._ ``` Then, we can create a middleware that adds a header to successful responses from @@ -64,8 +64,8 @@ val service = HttpRoutes.of[IO] { Ok() } -val goodRequest = Request[IO](Method.GET, uri("/")) -val badRequest = Request[IO](Method.GET, uri("/bad")) +val goodRequest = Request[IO](Method.GET, Uri.uri("/")) +val badRequest = Request[IO](Method.GET, Uri.uri("/bad")) service.orNotFound(goodRequest).unsafeRunSync service.orNotFound(badRequest).unsafeRunSync @@ -127,7 +127,7 @@ val apiService = HttpRoutes.of[IO] { val aggregateService = apiService <+> MyMiddle(service, Header("SomeKey", "SomeValue")) -val apiRequest = Request[IO](Method.GET, uri("/api")) +val apiRequest = Request[IO](Method.GET, Uri.uri("/api")) aggregateService.orNotFound(goodRequest).unsafeRunSync aggregateService.orNotFound(apiRequest).unsafeRunSync diff --git a/docs/src/main/tut/service.md b/docs/src/main/tut/service.md index 5554e4c1280..67668a35de8 100644 --- a/docs/src/main/tut/service.md +++ b/docs/src/main/tut/service.md @@ -176,6 +176,7 @@ import cats.implicits._ import org.http4s.HttpRoutes import org.http4s.syntax._ import org.http4s.dsl.io._ +import org.http4s.implicits._ import org.http4s.server.blaze._ object Main extends IOApp { diff --git a/docs/src/main/tut/testing.md b/docs/src/main/tut/testing.md index 8191cb10750..2f0de67cce9 100644 --- a/docs/src/main/tut/testing.md +++ b/docs/src/main/tut/testing.md @@ -22,6 +22,7 @@ import cats.effect._ import org.http4s._ import org.http4s.circe._ import org.http4s.dsl.io._ +import org.http4s.implicits._ final case class User(name: String, age: Int) implicit val UserEncoder: Encoder[User] = deriveEncoder[User] From 2eb457561e24480a39af57db534a0c412fb0476f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Madsen?= Date: Thu, 1 Nov 2018 21:45:03 +0100 Subject: [PATCH 10/10] Remove Entity{De,En}coderInstances traits --- .../main/scala/org/http4s/EntityDecoder.scala | 9 +++------ .../main/scala/org/http4s/EntityEncoder.scala | 16 ++++------------ core/src/main/scala/org/http4s/Http4s.scala | 2 +- 3 files changed, 8 insertions(+), 19 deletions(-) diff --git a/core/src/main/scala/org/http4s/EntityDecoder.scala b/core/src/main/scala/org/http4s/EntityDecoder.scala index 7c3ff687e71..edf0dc90297 100644 --- a/core/src/main/scala/org/http4s/EntityDecoder.scala +++ b/core/src/main/scala/org/http4s/EntityDecoder.scala @@ -16,6 +16,7 @@ import scala.concurrent.ExecutionContext * entire resulting A. If an error occurs it will result in a failed effect. * The default decoders provided here are not streaming, but one could implement * a streaming decoder by having the value of A be some kind of streaming construct. + * * @tparam T result type produced by the decoder */ @implicitNotFound( @@ -93,6 +94,7 @@ trait EntityDecoder[F[_], T] { self => * * The new [[EntityDecoder]] will first attempt to determine if it can perform the decode, * and if not, defer to the second [[EntityDecoder]] + * * @param other backup [[EntityDecoder]] */ def orElse[T2 >: T](other: EntityDecoder[F, T2])(implicit F: Functor[F]): EntityDecoder[F, T2] = @@ -110,7 +112,7 @@ trait EntityDecoder[F[_], T] { self => * This companion object provides a way to create `new EntityDecoder`s along * with some commonly used instances which can be resolved implicitly. */ -object EntityDecoder extends EntityDecoderInstances { +object EntityDecoder { // This is not a real media type but will still be matched by `*/*` private val UndefinedMediaType = new MediaType("UNKNOWN", "UNKNOWN") @@ -185,11 +187,6 @@ object EntityDecoder extends EntityDecoderInstances { def decodeString[F[_]: Sync](msg: Message[F])( implicit defaultCharset: Charset = DefaultCharset): F[String] = msg.bodyAsText.compile.foldMonoid -} - -/** Implementations of the EntityDecoder instances */ -trait EntityDecoderInstances { - import org.http4s.EntityDecoder._ /////////////////// Instances ////////////////////////////////////////////// diff --git a/core/src/main/scala/org/http4s/EntityEncoder.scala b/core/src/main/scala/org/http4s/EntityEncoder.scala index 278afd725e3..8e42525077e 100644 --- a/core/src/main/scala/org/http4s/EntityEncoder.scala +++ b/core/src/main/scala/org/http4s/EntityEncoder.scala @@ -3,8 +3,8 @@ package org.http4s import cats._ import cats.effect.{ContextShift, Effect, Sync} import cats.implicits._ -import fs2._ import fs2.Stream._ +import fs2._ import fs2.io.file.readAll import fs2.io.readInputStream import java.io._ @@ -48,7 +48,9 @@ trait EntityEncoder[F[_], A] { self => } } -object EntityEncoder extends EntityEncoderInstances { +object EntityEncoder { + + private val DefaultChunkSize = 4096 /** summon an implicit [[EntityEncoder]] */ def apply[F[_], A](implicit ev: EntityEncoder[F, A]): EntityEncoder[F, A] = ev @@ -75,10 +77,6 @@ object EntityEncoder extends EntityEncoderInstances { val c = toChunk(a) Entity[F](chunk(c).covary[F], Some(c.size.toLong)) } -} - -trait EntityEncoderInstances0 { - import EntityEncoder._ /** Encodes a value from its Show instance. Too broad to be implicit, too useful to not exist. */ def showEncoder[F[_], A]( @@ -113,12 +111,6 @@ trait EntityEncoderInstances0 { W.headers.put(`Transfer-Encoding`(TransferCoding.chunked)) } } -} - -trait EntityEncoderInstances extends EntityEncoderInstances0 { - import EntityEncoder._ - - private val DefaultChunkSize = 4096 implicit def unitEncoder[F[_]]: EntityEncoder[F, Unit] = emptyEncoder[F, Unit] diff --git a/core/src/main/scala/org/http4s/Http4s.scala b/core/src/main/scala/org/http4s/Http4s.scala index 9f17b3cfbaa..efef11b7e4d 100644 --- a/core/src/main/scala/org/http4s/Http4s.scala +++ b/core/src/main/scala/org/http4s/Http4s.scala @@ -7,7 +7,7 @@ trait Http4s extends Http4sInstances with Http4sFunctions with syntax.AllSyntax object Http4s extends Http4s @deprecated("Import from or use EntityDecoder/EntityEncoder directly instead", "0.20.0-M2") -trait Http4sInstances extends EntityDecoderInstances with EntityEncoderInstances +trait Http4sInstances @deprecated("Import from or use EntityDecoder/EntityEncoder directly instead", "0.20.0-M2") object Http4sInstances extends Http4sInstances