http

package
v0.0.0-...-f7fb57a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2019 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	// default http User Agent
	DefaultUserAgent = `gopher-lua`
	// default http timeout
	DefaultTimeout = 10 * time.Second
)

Variables

This section is empty.

Functions

func DoRequest

func DoRequest(L *lua.LState) int

DoRequest(): lua http_client_ud:do_request() http_client_ud:do_request(http_request_ud) returns (response, error)

response: {
  code=http_code (200, 201, ..., 500, ...),
  body=string
}
Example

http_client_ud:do_request(request)

package main

import (
	"log"

	http "github.com/vadv/gopher-lua-libs/http"
	lua "github.com/yuin/gopher-lua"
)

func main() {
	state := lua.NewState()
	http.Preload(state)
	source := `
    local http = require("http")
    local client = http.client()
    local request = http.request("GET", "https://google.com")
    local result, err = client:do_request(request)
    if err then error(err) end
    print(result.code)
`
	if err := state.DoString(source); err != nil {
		log.Fatal(err.Error())
	}
}
Output:

200

func HeaderSet

func HeaderSet(L *lua.LState) int

request:header_set(key, value)

func Loader

func Loader(L *lua.LState) int

Loader is the module loader function.

func New

func New(L *lua.LState) int

http.client(config) returns (user data, error) config table:

{
  proxy="http(s)://<user>:<password>@host:<port>",
  timeout= 10,
  insecure_ssl=false,
  user_agent = "gopher-lua",
  basic_auth_user = "",
  basic_auth_password = "",
  headers = {"key"="value"},
  debug = false,
}

func NewRequest

func NewRequest(L *lua.LState) int

http.request(verb, url, body) returns user-data, error

func Preload

func Preload(L *lua.LState)

Preload adds http_client to the given Lua state's package.preload table. After it has been preloaded, it can be loaded using require:

local http_client = require("http_client")

func SetBasicAuth

func SetBasicAuth(L *lua.LState) int

request:set_basic_auth(username, password)

Types

type LuaClient

type LuaClient struct {
	*http.Client
	// contains filtered or unexported fields
}

func (*LuaClient) DoRequest

func (client *LuaClient) DoRequest(req *http.Request) (*http.Response, error)

DoRequest() process request with needed settings for request

func (*LuaClient) PostFormRequest

func (client *LuaClient) PostFormRequest(url string, data url.Values) (*http.Response, error)

PostFormRequest() process Form

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL