-
-
Notifications
You must be signed in to change notification settings - Fork 251
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
Add request handler for play websocket requests #1063
Conversation
342979a
to
197e131
Compare
Hi! What's the jitpack file doing? It seems to cause the CI to fail and I am not sure what it is for. |
Sorry, the jitpack stuff was so I could actually build and test in my app. I'll scrub it out. All that being said, while this patch works, it's only 1/2 useful because there's no way to do the equivalent of the httpRequestWrapper for webSockets. I'm playing with a solution to do this using the zio context but haven't quite gotten all the type gymnastics worked out yet. |
197e131
to
5cbcda2
Compare
@ghostdogpr I've mostly run aground attempting to solve the problem of passing the authentication token into the subscription provider. The root problem is that the pattern in use for play and akka http relies on a fiber ref, and as things stand, passing that fiber ref into the stream doesn't work. I'm not familiar enough with the guts of zio streams to know if there's a way to force them to somehow instantiate and run on the same the same fiber as they are instantiated on, but the few naive things I've tried have run ground. The brute force approach is to just allow a All that being said, I think this PR as it stands is an improvement on the current state (no more misspelled and unused methods and at least you can enforce security on subscriptions) so perhaps it's best to merge it and deal with passing context into subscriptions elsewhere. I'm happy either way. |
Definitely 👍 on fixing the typo! |
9dd44f2
to
9f772b6
Compare
Ok, I think I've got this working. The root issue here is that the web socket request is a two stage process, where we first respond to the http request, and then hand off a flow to play. That flow now receives the play RequestHeaders and re-runs the handleWebSocketRequest to ensure thread locals are set before starting the subscription stream. There's also now a There's a fairly detailed test in the ExecutionSpec that tests passing authentication context via a wrapper similiar to the play and http4s wrappers. (Un)fortunately it doesn't demonstrate the failure since it's specific to the Task-Future boundary , but I think it's a useful addition to the test suite since it demonstrates deriving a custom schema for a custom environment and tests the underlying mechanisms use by the play and akka http authentication examples. In any case, I think this PR is ready for review. |
@ghostdogpr sure I’ll take a look tomorrow! |
@easel I would prefer to keep it simple and only allow It looks like some of the new tests are failing with Scala 3. |
Ok, I've dropped the I've also dropped the new test. That said, the test exercises generating custom schemas and works on everything but scala3. I worry it exposes some limitations in the schema derivation under scala 3. Is it worth splitting it out into a new PR to chase down? |
338662d
to
becf1e8
Compare
Yeah let's drop Okay for adding a new PR with the Scala 3 failing test, I can take a look at it. Thanks! |
Minor: can you clean and sort imports? |
Imports should be cleaned up now. |
Got the OK from @paulpdaniels. While reviewing, I was thinking, maybe we should be consistent with We could either add |
@ghostdogpr I considered trying to merge them as well. I can say that for my use case the implementations are almost identical. I guess the challenge is that the semantics aren't quite the same -- for websockets failures are on the error channel, while request wrapper just provides an opportunity to side effect the environment and execute the effect or not. That said, if we changed, perhaps I can experiment with some options -- I think it would be unfortunate to change the signature of If we can introduce a At some point we could also deprecate the one-parameter Is that what you had in mind? |
I like your last idea. Deprecate the existing method and expose one with the unified semantics (with a different name for RequestWrapper so that both the old way and the new way can work at the same time?). And if the old way implementation could actually use the new way under the hood, the code stays simple. |
Ok, I've implemented more or less what I described above. Let me know what you think. I still need to wire it into my production app and see how it behaves. There really aren't tests exercising this stuff atm so it's possible I've screwed up the type gymnastics someplace. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Do you want to do some testing on your project before we merge it?
So I've got this wired and have been using it for a while, seemingly successfully. I'm happy to merge whenever you are. |
Thanks for the merge @ghostdogpr |
@easel I'd love your feedback on this ongoing PR: #1125 |
PlayAdapter now includes
def handleWebSocketRequestHeader: RequestHeader => ZIO[R, Result, Unit]
and always passes websocket requests through webSocketOrResult to allow for authentication. Play auth example
now authenticates websocket requests.