https://github.com/squeek502/coro-http-luv
coro-http from Lit converted to work with plain Lua + Luv
https://github.com/squeek502/coro-http-luv
Last synced: about 1 month ago
JSON representation
coro-http from Lit converted to work with plain Lua + Luv
- Host: GitHub
- URL: https://github.com/squeek502/coro-http-luv
- Owner: squeek502
- License: other
- Created: 2019-04-17T04:45:02.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-09-07T23:22:58.000Z (over 3 years ago)
- Last Synced: 2025-03-27T01:03:16.527Z (about 2 months ago)
- Language: Lua
- Size: 350 KB
- Stars: 12
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
coro-http-luv
=============[](https://github.com/squeek502/coro-http-luv/actions/workflows/ci.yml)
`coro-http` from [Lit](https://github.com/luvit/lit) converted to work with plain Lua + [Luv](https://github.com/luvit/luv).
## Requirements
- Lua (>= 5.1 or LuaJIT)
- [Luv](https://github.com/luvit/luv)
- (optional) for HTTPS:
+ [lua-openssl](https://github.com/zhaozg/lua-openssl)
+ (for PUC Lua 5.1 only) [LuaBitOp](https://luarocks.org/modules/luarocks/luabitop)## Installation
Via [Luarocks](http://luarocks.org/modules/squeek502/coro-http-luv):
```
luarocks install coro-http-luv
```## Changes from the Lit version
- Everything is now in a `coro-http-luv` module, e.g. `http-codec` is now `require`'d as `coro-http-luv.http-codec`
- `root_ca.dat` in `secure-socket` replaced with `root_ca.lua`, which uses a string literal for the binary data (encoded by [arbitrary-binary-string](https://github.com/squeek502/lua-arbitrary-binary-string))
- Bitwise operations in `secure-socket` will use whatever is available (Lua 5.3 operators, 'bit32', or 'bit')
- `require('uv')` replaced with `require('luv')`## Usage
```lua
local luv = require 'luv'
local http = require 'coro-http-luv'
local unpack = table.unpack or unpackcoroutine.wrap(function()
local res, data = http.request('GET', 'http://localhost/')-- status code
print(res.code)-- print headers
for i = 1, #res do
local key, value = unpack(res[i])
print(key, value)
end-- print response body
print(data)
end)()-- start the luv event loop
luv.run()
```