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

0.19 #253

Merged
merged 24 commits into from
Nov 4, 2018
Merged

0.19 #253

merged 24 commits into from
Nov 4, 2018

Conversation

chuwy
Copy link
Contributor

@chuwy chuwy commented Oct 6, 2018

This is based on #236 and leaves @Igosuki's work almost untouched, but:

  • bumps http4s to 0.19.0 (which is still not final, I guess?)
  • rebased on top of current master
  • makes all tests green
  • Bumps SBT to latest version
  • Makes json4s a test-only dependency for swagger

TODO

  • Fix HListToFuncSpec
  • Fix docstring in AuthedContext
  • Rename few more "service" to "routes"
  • Add a comment in AuthedContext that middleware is mandatory
  • Should we rename RhoService to RhoRoutes?
  • Bump to final 0.20.0 when available

new RhoService[IO] {
// `.pure[IO]` used to require the cats.implicits under test
GET / "route1" |>> { () => Ok("foo".pure[IO]) }
GET / "route1" |>> { () => Ok("foo") }
Copy link
Member

Choose a reason for hiding this comment

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

This needs to get changed back, otherwise it doesn't properly test for regressions of issue #218

@@ -0,0 +1 @@
sbt.version=1.1.5
Copy link
Member

Choose a reason for hiding this comment

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

Probably set this to 1.2.3 like the main project.


val routes =
new Routes(businessLayer)

BlazeBuilder[IO]
.mountService(routes.staticContent combineK routes.dynamicContent, "")
.bindLocal(port)
.serve
.serve.compile.toList.map(_.head)
Copy link
Member

Choose a reason for hiding this comment

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

Would it be better to use head.compile.last instead of toList here? No need to build a full list here? (I realize it will likely never emit more than a single Exit code, but if it does, shouldn't we just take the head exit code and stop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, thanks. We don't want toList for sure. But I belive compile.drain.as(ExitCode.Success) is a preferred option for streaming applications inside IOApp.

Copy link
Member

@zarthross zarthross Oct 6, 2018

Choose a reason for hiding this comment

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

Yeah, I saw that in the Http4s docs, wasn't 100% sure thats the right choice either honestly... but I'm ok with using what the http4s docs say.

.bindLocal(port)
.serve
.serve.compile.toList.map(_.head)
Copy link
Member

Choose a reason for hiding this comment

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

Same as the above comment on head.compile.last

consumes = rr.validMedia.toList.map(_.renderString),
produces = rr.responseEncodings.toList.map(_.renderString),
consumes = rr.validMedia.toList.map(_.toString),
produces = rr.responseEncodings.toList.map(_.toString),
Copy link
Member

@zarthross zarthross Oct 6, 2018

Choose a reason for hiding this comment

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

I feel like the old renderString function was not the same as toString on a MediaRange. (Possibly not on an responseEncoding)... toString's results have a MediaRange and some parens in the string that 'renderString' did not put there...

Copy link
Member

Choose a reason for hiding this comment

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

I'm looking at this diff in http4s to see the change: http4s/http4s@f2ca175

audio.midi,
image.gif,
text.html
).map(_.toString)
Copy link
Member

Choose a reason for hiding this comment

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

Again, not sure toString should be the substitute for renderString on a MediaRange

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems that we have Show instance for MediaType. I believe it will be the correct substitution.

Copy link
Member

Choose a reason for hiding this comment

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

I believe you are correct.

@chuwy
Copy link
Contributor Author

chuwy commented Oct 6, 2018

Thank you very much for the feedback, @zarthross. I'm still a little bit puzzled by HListToFuncSpec as it cannot resolve EntityEncoder[IO, IO[String]], but probably I'm missing something super obvious as it is quite late in where I am - I'll try to fix it tomorrow.

@chuwy
Copy link
Contributor Author

chuwy commented Oct 6, 2018

Aha! So, the problem is that indeed EntityDecoder[F, F[A]] is missing since this commit. Wondering what was the reasoning.

@@ -14,7 +14,7 @@ class CodecRouterSpec extends Specification {

"A CodecRouter in a RhoService" should {

val service = new RhoService[IO] {
val routes = new RhoService[IO] {
Copy link
Member

Choose a reason for hiding this comment

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

This is still a RhoService, so i don't know that the rename is appropriate here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But we're immediately converting it to HttpRoutes[IO] below, so I think all these are justified.

Copy link
Member

@zarthross zarthross Oct 6, 2018

Choose a reason for hiding this comment

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

¯\_(ツ)_/¯
Not really that big of deal. Not a deal breaker for me either way.

Copy link
Member

Choose a reason for hiding this comment

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

(Removed other similar comments for brevity.)

Copy link
Member

@zarthross zarthross left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@rossabaker
Copy link
Member

Yeah, sorry about 0.19.0 not being final. I messed up the tagging.

Would you like to do a milestone release on this so people can try it?

@zarthross
Copy link
Member

I think there is a few more changes @chuwy would like to make before we merge/release, but once he finishes those check boxes, I would like to get this released. I have some projects I would like to get a head start updating before the 0.19.1 release.

@chuwy
Copy link
Contributor Author

chuwy commented Oct 7, 2018

@rossabaker, @zarthross I made some more "service -> routes" renamings to be consistent with core and updated AuthedContext (I believe unsafe getAuth was a bug - I stumbled upon it when first used rho). It would be nice to get M1 when you have time.

Last question I have is whether we should rename RhoService to RhoRoutes. I vote for yes, e.g. it is just a wrapper around list of individual RhoRoutes.

@@ -7,15 +7,15 @@ import shapeless.HList
import scala.collection.immutable.VectorBuilder

/** CompileService which accumulates routes and can build a `HttpService` */
final class ServiceBuilder[F[_]: Monad] private(internalRoutes: VectorBuilder[RhoRoute.Tpe[F]]) extends CompileService[F, RhoRoute.Tpe[F]] {
final class ServiceBuilder[F[_]: Monad] private(internalRoutes: VectorBuilder[RhoRoute.Tpe[F]]) extends CompileRoutes[F, RhoRoute.Tpe[F]] {

/** Turn the accumulated routes into an `HttpService`
*
* @param filter [[RhoMiddleware]] to apply to the collection of routes.
* @return An `HttpService` which can be mounted by http4s servers.
*/
def toService(filter: RhoMiddleware[F] = identity): HttpRoutes[F] =
Copy link
Member

Choose a reason for hiding this comment

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

ServiceBuilder and its toService function also need a rename.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree, but I think we should handle this along with RhoService

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I agree with the RhoService rename. It makes sense in context with what http4s is trying to do.

Copy link
Member

Choose a reason for hiding this comment

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

The only worry is that it'll get confusing with RhoRhoute vs RhoRhoutes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My worry is similar: we're getting too many "route" in different places that clash with each other and core's. We're ending up with RouteFoo.toRoutes(routes).asRoutes roughly speaking. But still I believe this is a right choice.

@@ -26,13 +26,22 @@ object MyAuth extends AuthedContext[IO, User]
object MyService extends RhoService[IO] {
import MyAuth._

GET +? param("foo", "bar") >>> auth |>> { (req: Request[IO], foo: String, user: User) =>
GET +? param("foo", "bar") >>> auth |>> { (_: Request[IO], foo: String, user: User) =>
Copy link
Member

Choose a reason for hiding this comment

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

You can remove the _: Request[IO] all together here. If Request isn't the first parameter of the HList its just not provided.

GET / "private" / 'place |>> { (req: Request[IO], path: String) =>
getAuth(req) match {
case Some(user) => Ok(s"${user.name} at $path")
case None => Forbidden(s"not authenticated at $path")
Copy link
Member

Choose a reason for hiding this comment

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

Unfortunately, if getAuth returns None it doesn't mean the user was not authenticated, it means the AuthMiddleware wasn't applied.

Copy link
Contributor Author

@chuwy chuwy Oct 7, 2018

Choose a reason for hiding this comment

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

Our authenticated middleware always returns Some, but in case where it returns None (which is still valid) - it will be indistinguishable from not applied middleware. So we have plenty of slightly broken APIs, but this one from my POV is less broken. We just need to mention in comments that AuthMiddleware always should be applied. Until we come up with best strategy.

@zarthross
Copy link
Member

@chuwy How many of those checkboxes do you want to complete before this gets merged in?

@chuwy
Copy link
Contributor Author

chuwy commented Oct 15, 2018

@zarthross I think two at least. Should be done in next couple of days.

@zarthross
Copy link
Member

I think it would probably be wise to go through with the RhoService to RhoRoutes rename to follow suite with the Http4s rename.

@chuwy
Copy link
Contributor Author

chuwy commented Oct 15, 2018

Sure. Totally agree. I meant "all except Bump to final 0.19.1", so this renaming will be included for sure.

@chuwy
Copy link
Contributor Author

chuwy commented Oct 15, 2018

Also, I assume you're fine with Option in AuthedContext. I believe that it is a not an ideal solution, but still better than runtime exception.

@@ -2,7 +2,7 @@ import sbt._
import Keys._

object Dependencies {
lazy val http4sVersion = "0.18.19"
lazy val http4sVersion = "0.19.0"

Choose a reason for hiding this comment

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

The currently version is 0.19.0-M4, 0.19.0 was mistagged and should be avoided if possible.

@chuwy
Copy link
Contributor Author

chuwy commented Oct 29, 2018

Hey @zarthross, sorry for delay. This has been updated to http4s 0.20.0-M1. I also believe I addressed all your feedback and everything I wanted to change.

I assume we're not pursuing version-parity with http4s, so I left it as 0.19, not 0.20.

If everything is correct, it should be ready for M1.

@rossabaker
Copy link
Member

Version parity has always been coincidental, but maybe it's nice since it has recently been in lockstep. I guess it might get more complicated when both projects hit 1.0. I don't have a strong opinion there.

Copy link
Member

@zarthross zarthross left a comment

Choose a reason for hiding this comment

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

I'm still not comfortable with the way the Auth has played out yet. So lets release this as M1 and I'll work on something before we get to M2.

@zarthross zarthross added this to the v0.19.0-M1 milestone Oct 30, 2018
@zarthross zarthross merged commit a12cbe1 into http4s:master Nov 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants