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

SocketApp refactoring, ability to provide custom websocket config #2338

Merged
merged 7 commits into from
Aug 5, 2023

Conversation

vigoo
Copy link
Contributor

@vigoo vigoo commented Jul 28, 2023

Refactors SocketApp[R] so it also implements a Request => Option[WebSocketConfig] function that allows customizing the websocket connection including the handshake based on the actual request.

Resolves #2278
/claim #2278


import zio._

final case class SocketApp[-R](
Copy link
Member

Choose a reason for hiding this comment

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

maybe we can rename this WebSocketApp while we're at it.


final case class SocketApp[-R](
handler: Handler[R, Throwable, WebSocketChannel, Any],
customConfig: Handler[R, Throwable, Request, Option[WebSocketConfig]],
Copy link
Member

Choose a reason for hiding this comment

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

This seems too powerful. I'd prefer Option[WebSocketConfig], or if that cannot be done, something like <subset of Request> => WebSocketConfig.

But it feels like the config should be done at the route pattern level, e.g.:

val route = Method.GET / "connect" -> handler(socketApp.withConfig(...))

You already know the route and pattern there and can set config on a per-route basis. You indeed have access to the full request.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The author of the issue wanted to have a way to customize the handshaking based on the request (actual contents of some headers)

Copy link
Contributor

Choose a reason for hiding this comment

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

<subset of Request> => WebSocketConfig would be great, especially if the result was passed into Handler.webSocket. As it is right now there's no way to negotiate the websocket sub-protocol for a single endpoint (such as choosing between graphql-ws and graphql-transport-ws), which would be really nice to do.

@codecov-commenter
Copy link

codecov-commenter commented Jul 28, 2023

Codecov Report

Patch coverage: 71.42% and project coverage change: -0.39% ⚠️

Comparison is base (538761f) 63.21% compared to head (bcee070) 62.82%.
Report is 1 commits behind head on main.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2338      +/-   ##
==========================================
- Coverage   63.21%   62.82%   -0.39%     
==========================================
  Files         135      136       +1     
  Lines        7032     7236     +204     
  Branches     1185     1230      +45     
==========================================
+ Hits         4445     4546     +101     
- Misses       2587     2690     +103     
Files Changed Coverage Δ
...io-http/src/main/scala/zio/http/ClientDriver.scala 100.00% <ø> (ø)
zio-http/src/main/scala/zio/http/Response.scala 48.76% <ø> (+0.39%) ⬆️
...o-http/src/main/scala/zio/http/ZClientAspect.scala 64.00% <ø> (ø)
...cala/zio/http/netty/client/NettyClientDriver.scala 100.00% <ø> (ø)
zio-http/src/main/scala/zio/http/package.scala 66.66% <ø> (ø)
...io-http/src/main/scala/zio/http/WebSocketApp.scala 60.00% <60.00%> (ø)
zio-http/src/main/scala/zio/http/Handler.scala 63.23% <100.00%> (-1.06%) ⬇️
zio-http/src/main/scala/zio/http/ZClient.scala 42.75% <100.00%> (ø)
...a/zio/http/netty/server/ServerInboundHandler.scala 82.87% <100.00%> (+0.11%) ⬆️

... and 12 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions github-actions bot added the docs label Jul 28, 2023
@kyri-petrou
Copy link
Collaborator

Hi @vigoo, is this PR planned to be added to the next RC release? At Caliban we're currently blocked on updating zio-http since we need to be able to do the same as #2278 for GraphQL subscriptions

@vigoo
Copy link
Contributor Author

vigoo commented Aug 4, 2023

Yes this should be in the next release

@adamgfraser adamgfraser merged commit d1997c6 into main Aug 5, 2023
25 checks passed
@adamgfraser adamgfraser deleted the socket-app-refactor branch August 5, 2023 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Response.fromSocketApp erases headers.
6 participants