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

Compile without fatal warnings on 2.13.0 #2891

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 42 additions & 10 deletions core/src/main/scala/org/http4s/Message.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import cats.implicits._
import cats.effect.IO
import fs2.{Pure, Stream}
import fs2.text.{utf8Decode, utf8Encode}
import java.io.File
import java.io.{File, Serializable}
import java.net.{InetAddress, InetSocketAddress}
import org.http4s.headers._
import org.http4s.util.decode
import org.log4s.getLogger
import _root_.io.chrisdavenport.vault._
import scala.util.hashing.MurmurHash3

/**
* Represents a HTTP Message. The interesting subclasses are Request and Response.
Expand Down Expand Up @@ -236,14 +237,14 @@ object Message {
* @param body fs2.Stream[F, Byte] defining the body of the request
* @param attributes Immutable Map used for carrying additional information in a type safe fashion
*/
sealed abstract case class Request[F[_]](
method: Method = Method.GET,
uri: Uri = Uri(path = "/"),
httpVersion: HttpVersion = HttpVersion.`HTTP/1.1`,
headers: Headers = Headers.empty,
body: EntityBody[F] = EmptyBody,
attributes: Vault = Vault.empty
) extends Message[F] {
final class Request[F[_]](
val method: Method = Method.GET,
val uri: Uri = Uri(path = "/"),
val httpVersion: HttpVersion = HttpVersion.`HTTP/1.1`,
val headers: Headers = Headers.empty,
val body: EntityBody[F] = EmptyBody,
val attributes: Vault = Vault.empty
) extends Message[F] with Product with Serializable {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a huge fan of these interfaces, but:

  • Product makes hash code easier and was there before.
  • Spark folks may be depending on Serializable. I don't judge.

import Request._

type Self = Request[F]
Expand Down Expand Up @@ -414,6 +415,34 @@ sealed abstract case class Request[F[_]](
override def toString: String =
s"""Request(method=$method, uri=$uri, headers=${headers.redactSensitive()})"""

override def hashCode(): Int = MurmurHash3.productHash(this)

override def equals(that: Any): Boolean = (this eq that.asInstanceOf[Object]) || (that match {
case that: Request[_] =>
(this.method == that.method) &&
(this.uri == that.uri) &&
(this.httpVersion == that.httpVersion) &&
(this.headers == that.headers) &&
(this.body == that.body) &&
(this.attributes == that.attributes)
case _ => false
})

def canEqual(that: Any) = that.isInstanceOf[Request[F]]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That F is erased and I'm surprised this didn't generate a warning but _ didn't work. Maybe _[_]? Ugh.


def productArity: Int = 6

def productElement(n: Int) = n match {
case 0 => method
case 1 => uri
case 2 => httpVersion
case 3 => headers
case 4 => body
case 5 => attributes
case _ => throw new IndexOutOfBoundsException()
}

override def productPrefix: String = "Request"
}

object Request {
Expand All @@ -433,7 +462,10 @@ object Request {
headers = headers,
body = body,
attributes = attributes
) {}
)

def unapply[F[_]](request: Request[F]): Option[(Method, Uri, HttpVersion, Headers, EntityBody[F], Vault)] =
Some((request.method, request.uri, request.httpVersion, request.headers, request.body, request.attributes))

final case class Connection(local: InetSocketAddress, remote: InetSocketAddress, secure: Boolean)

Expand Down
4 changes: 2 additions & 2 deletions dsl/src/test/scala/org/http4s/dsl/PathInHttpRoutesSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import org.http4s.Uri.uri
object PathInHttpRoutesSpec extends Http4sSpec {

object List {
def unapplySeq(params: Map[String, Seq[String]]) = params.get("list")
def unapply(params: Map[String, Seq[String]]) = unapplySeq(params)
def unapplySeq(params: Map[String, collection.Seq[String]]) = params.get("list")
def unapply(params: Map[String, collection.Seq[String]]) = unapplySeq(params)
}

object I extends QueryParamDecoderMatcher[Int]("start")
Expand Down
9 changes: 0 additions & 9 deletions project/Http4sPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,6 @@ object Http4sPlugin extends AutoPlugin {
override lazy val projectSettings: Seq[Setting[_]] = Seq(
scalaVersion := scala_213,
crossScalaVersions := Seq(scala_213, scala_212),
// Getting some spurious unreachable code warnings in 2.13.0
scalacOptions -= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 13)) =>
"-Xfatal-warnings"
case _ =>
"I DON'T EXIST I'M WORKING AROUND NOT BEING ABLE TO CALL scalaVersion.value FROM ~="
}
},

// https://github.com/tkawachi/sbt-doctest/issues/102
Test / compile / scalacOptions -= "-Ywarn-unused:params",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@ import org.specs2.concurrent.ExecutionEnv
import scala.concurrent.duration._
import scala.io.Source

class TomcatServerSpec(implicit ee: ExecutionEnv) extends {
class TomcatServerSpec(implicit ee: ExecutionEnv) extends Http4sSpec {
// Prevents us from loading jar and war URLs, but lets us
// run Tomcat twice in the same JVM. This makes me grumpy.
//
// Needs to run before the server is initialized in the superclass.
// This also makes me grumpy.
val _ = TomcatURLStreamHandlerFactory.disable()
} with Http4sSpec {
TomcatURLStreamHandlerFactory.disable()

def builder = TomcatBuilder[IO]

val serverR =
Expand Down