Coder Social home page Coder Social logo

gluahttp's People

Contributors

cjoudrey avatar erikdubbelboer avatar ilius avatar johannes-larsson avatar uamana avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

gluahttp's Issues

Add "response" table

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

res.Body isn't being closed on successful request

// 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:

body, err := ioutil.ReadAll(res.Body)

Contex BUG!

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) }

How to add `Content-Type` header

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.

Connection limiting

Add a way to set max_connections and max_connections_per_host to simulate browsers behaviour.

how to close the auto-redirection

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.

Command line usage

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.

https://github.com/yuin/gopher-lua#standalone-interpreter

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.