Skip to content

socket protocol utilities for http apis #7374

Description

@harrysolovay

What is the problem this feature would solve?

Streamline including socket protocols in the client, and parsing socket protocols in http APIs.

What is the feature you are proposing to solve the problem?

Some minimal socket protocol utils.

export const SocketProtocolsKey = "Sec-WebSocket-Protocol" as const

const SocketProtocols = S.String.pipe(
  S.decodeTo(S.Array(S.Trim), {
    decode: SchemaGetter.split({ separator: "," }),
    encode: SchemaGetter.transform((arr) => arr.join(",")),
  }),
)

Ideally there'd also be a requirement that we could optionally provide to any SocketConstructor.

mySocketClient.pipe(
  Layer.provide(Socket.layerWebSocketConstructorGlobal.pipe(Layer.provide(SocketProtocols.layer(["a", "b", "c"]))))
)

And a piece of http middleware for parsing the protocols from an HttpServerRequest.

const handler = Effect.gen(function*() {
  const protocols = yield* SocketProtocols
})

What alternatives have you considered?

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions