daurnimator / lua-http

HTTP Library for Lua. Supports HTTP(S) 1.0, 1.1 and 2.0; client and server.
https://daurnimator.github.io/lua-http/
MIT License
778 stars 80 forks source link

High level API and/or documentation for working with WebSockets #184

Closed AntonPetrochenko closed 3 years ago

AntonPetrochenko commented 3 years ago

Can be used at a very high level without need to understand the transportation of HTTP data (other than connection addresses).

This straight up doesn't stand true for many use cases, and WebSocket is one of them. Compared to the rest of the library, making a WebSocket server folds back into low level operations and server-blocking i/o.

daurnimator commented 3 years ago

making a WebSocket server folds back into low level operations and server-blocking i/o.

howso?

Reading/writing from a websocket has it's own api, but it's different in terms of "server blocking i/o" than other request handling.

AntonPetrochenko commented 3 years ago

To accept a WebSocket connection I have to cobble together a socket on my own, and then implement my own cqueues loop to have it accept frames at all. Perhaps not just lua-http, but lua in general is not what I need for my use case. Can't even get a list of clients, have to make one myself.

AntonPetrochenko commented 3 years ago

The same stands for TLS. As soon as any TLS is involved, which in 2021 is synonymous with "any HTTP", you need to speak luaossl and https on your own. You could honestly remove luaossl from dependencies, given you have to attach it yourself manually anyway. http.tls is a helpful set of helpers and constants, but it doesn't even take in anything from the rest of the library - it's just there to help you set up TLS with manual stream manipulation.

I wouldn't call implementing the entire HTTPS handshake "high level", unless there's something undocumented that I'm missing

daurnimator commented 3 years ago

attach it yourself manually anyway

??

lua-http handles tls for you. e.g. client side, if you provide a url that's https, then it will use TLS; likewise if a http url redirects to a https one. server side, by default lua-http listens for both TLS and non TLS connections.

AntonPetrochenko commented 3 years ago

Apologies, I missed that part in the documentation. I'm tasked with making lua talk websocket and the deadline is "asap", not like I can pay much attention

daurnimator commented 3 years ago

Closing as there is no issue to solve here

RussellHaley commented 3 years ago

Apologies, I missed that part in the documentation. I'm tasked with making lua talk websocket and the deadline is "asap", not like I can pay much attention

I have a crappy lua-http example apps here:

https://github.com/RussellHaley/lua-http-endpoints https://github.com/RussellHaley/we-client https://github.com/RussellHaley/Lua-WeGateway

This one is kindof neat. It combines cqueues with websockets and pttys: https://github.com/RussellHaley/minecraft-runner