Skip to content

Commit

Permalink
Merge pull request #1603 from rsoeldner/ws-naming
Browse files Browse the repository at this point in the history
Rename read/write to send/receive
  • Loading branch information
rossabaker committed Dec 19, 2017
2 parents 0b31047 + cb667d4 commit 10e1293
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ class Http4sWSStage[F[_]](ws: ws4s.Websocket[F])(implicit F: Effect[F], val ec:

val wsStream = for {
dead <- deadSignal
in = inputstream.to(ws.write).onFinalize(onStreamFinalize)
out = ws.read.onFinalize(onStreamFinalize).to(snk).drain
in = inputstream.to(ws.receive).onFinalize(onStreamFinalize)
out = ws.send.onFinalize(onStreamFinalize).to(snk).drain
merged <- in.mergeHaltR(out).interruptWhen(dead).onFinalize(sendClose).run
} yield merged

Expand Down
13 changes: 10 additions & 3 deletions core/src/main/scala/org/http4s/websocket/Websocket.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import fs2._
import org.http4s.websocket.WebsocketBits.WebSocketFrame

private[http4s] final case class Websocket[F[_]](
read: Stream[F, WebSocketFrame],
write: Sink[F, WebSocketFrame]
)
@deprecatedName('read) send: Stream[F, WebSocketFrame],
@deprecatedName('write) receive: Sink[F, WebSocketFrame]
) {

@deprecated("Parameter has been renamed to `send`", "0.18.0-M7")
def read: Stream[F, WebSocketFrame] = send

@deprecated("Parameter has been renamed to `receive`", "0.18.0-M7")
def write: Sink[F, WebSocketFrame] = receive
}
15 changes: 7 additions & 8 deletions server/src/main/scala/org/http4s/server/websocket/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ package object websocket {
/**
* Build a response which will accept an HTTP websocket upgrade request and initiate a websocket connection using the
* supplied exchange to process and respond to websocket messages.
* @param read The read side of the Exchange represents the stream of messages that should be sent to the client
* @param write The write side of the Exchange is a sink to which the framework will push the websocket messages
* received from the client.
* @param send The send side of the Exchange represents the outgoing stream of messages that should be sent to the client
* @param receive The receive side of the Exchange is a sink to which the framework will push the incoming websocket messages
* Once both streams have terminated, the server will initiate a close of the websocket connection.
* As defined in the websocket specification, this means the server
* will send a CloseFrame to the client and wait for a CloseFrame in response before closing the
Expand All @@ -40,13 +39,13 @@ package object websocket {
* @param status The status code to return to a client making a non-websocket HTTP request to this route
*/
def WS[F[_]](
read: Stream[F, WebSocketFrame],
write: Sink[F, WebSocketFrame],
send: Stream[F, WebSocketFrame],
receive: Sink[F, WebSocketFrame],
status: F[Response[F]])(implicit F: Functor[F]): F[Response[F]] =
status.map(_.withAttribute(AttributeEntry(websocketKey[F], Websocket(read, write))))
status.map(_.withAttribute(AttributeEntry(websocketKey[F], Websocket(send, receive))))

def WS[F[_]](read: Stream[F, WebSocketFrame], write: Sink[F, WebSocketFrame])(
def WS[F[_]](send: Stream[F, WebSocketFrame], receive: Sink[F, WebSocketFrame])(
implicit F: Monad[F],
W: EntityEncoder[F, String]): F[Response[F]] =
WS(read, write, Response[F](Status.NotImplemented).withBody("This is a WebSocket route."))
WS(send, receive, Response[F](Status.NotImplemented).withBody("This is a WebSocket route."))
}

0 comments on commit 10e1293

Please sign in to comment.