cjoudrey / gluahttp Goto Github PK
View Code? Open in Web Editor NEWgluahttp: an http module for gopher-lua
License: MIT License
gluahttp: an http module for gopher-lua
License: MIT License
Default value should be true
.
When set to false
, HTTP redirects are not followed.
It might be useful to have a helper to set basic auth headers, would you accept PR?
Example usage:
http.request_batch({
{"GET", "http://example.com", {query="page=1"}},
{"POST", "http://example.com", {form="username=bob&password=secret"}},
})
Instead of returning body, status, headers
on success and nil, error
on failure, we will return response
on success and nil, error
on failure.
response
table will have the following properties:
body
string
cookies
table
headers
table
status_code
number
// The http Client and Transport guarantee that Body is always
// non-nil, even on responses without a body or responses with
// a zero-length body. It is the caller's responsibility to
// close Body. The default HTTP client's Transport does not
// attempt to reuse HTTP/1.0 or HTTP/1.1 TCP connections
// ("keep-alive") unless the Body is read to completion and is
// closed.
It seems like we currently are not closing res.Body
on successful request:
Line 189 in 9597a1d
VM blocked on Recv even after cancelling context. So the function of doRequest
may should add follow code:
ctx := L.Context() if ctx != nil { req = req.WithContext(ctx) }
Maybe this is a silly question but I'm trying to use this and I'm having trouble setting the request headers.
I used the example in the readme:
import "github.com/yuin/gopher-lua"
import "github.com/cjoudrey/gluahttp"
func main() {
L := lua.NewState()
defer L.Close()
L.PreloadModule("http", NewHttpModule(&http.Client{}).Loader)
if err := L.DoString(`
local http = require("http")
response, error_message = http.request("GET", "http://example.com", {
query="page=1",
timeout="30s",
headers={
Accept="*/*",
Content-Type="application/json", // THIS DOES NOT WORK?
}
})
`); err != nil {
panic(err)
}
}
The headers that are passed in are of type table. But for a tables field name I can't use the -
character. For http header like Content-Type
this character is necessary. Is there a way to work around this.
Add a way to set max_connections
and max_connections_per_host
to simulate browsers behaviour.
I need response.headers['Location'], and in python I can do it by http.post(url, data, allow_redirects=false), I wonder how can I make it in gluahttp.
Signature: http.get(url [, options])
Is it possible?
$ cat sun.lua
local http = require("http")
$ glua sun.lua
sun.lua:1: module http not found:
no field package.preload['http']
CreateFile .\http.lua: The system cannot find the file specified.
CreateFile C:\opt\lua\http.lua: The system cannot find the path specified.
CreateFile C:\opt\lua\http\init.lua: The system cannot find the path specified.
Signature: http.post(url [, options])
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.