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

Implement TLSSocket#applicationProtocol on JS #2741

Merged
merged 3 commits into from
Dec 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions io/js/src/main/scala/fs2/io/net/tls/TLSSocketPlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,19 @@ private[tls] trait TLSSocketCompanionPlatform { self: TLSSocket.type =>
sessionRef.discrete.unNone.head
.concurrently(Stream.eval(errorDef.get.flatMap(F.raiseError[Unit])))
.compile
.lastOrError
.lastOrError,
F.delay[Any](tlsSock.asInstanceOf[tlsMod.TLSSocket].alpnProtocol).flatMap {
case false => "".pure // mimicking JVM
case protocol: String => protocol.pure
case _ => F.raiseError(new NoSuchElementException)
}
)

private[tls] final class AsyncTLSSocket[F[_]: Async](
sock: tlsMod.TLSSocket,
readStream: SuspendedStream[F, Byte],
val session: F[SSLSession]
val session: F[SSLSession],
val applicationProtocol: F[String]
) extends Socket.AsyncSocket[F](sock.asInstanceOf[netMod.Socket], readStream)
with UnsealedTLSSocket[F]
}
2 changes: 1 addition & 1 deletion io/jvm/src/main/scala/fs2/io/net/tls/TLSEngine.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private[tls] object TLSEngine {

def beginHandshake = Sync[F].delay(engine.beginHandshake())
def session = Sync[F].delay(engine.getSession())
def applicationProtocol = Sync[F].delay(engine.getApplicationProtocol())
def applicationProtocol = Sync[F].delay(Option(engine.getApplicationProtocol()).get)
def stopWrap = Sync[F].delay(engine.closeOutbound())
def stopUnwrap = Sync[F].delay(engine.closeInbound()).attempt.void

Expand Down
3 changes: 0 additions & 3 deletions io/jvm/src/main/scala/fs2/io/net/tls/TLSSocketPlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ private[tls] trait TLSSocketPlatform[F[_]] {
/** Initiates handshaking -- either the initial or a renegotiation. */
def beginHandshake: F[Unit]

/** Provides access to the current application protocol that has been negotiated.
*/
def applicationProtocol: F[String]
}

private[tls] trait TLSSocketCompanionPlatform { self: TLSSocket.type =>
Expand Down
4 changes: 4 additions & 0 deletions io/shared/src/main/scala/fs2/io/net/tls/TLSSocket.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ sealed trait TLSSocket[F[_]] extends Socket[F] with TLSSocketPlatform[F] {
*/
def session: F[SSLSession]

/** Provides access to the current application protocol that has been negotiated.
*/
def applicationProtocol: F[String]

}

object TLSSocket extends TLSSocketCompanionPlatform {
Expand Down