Help us shape the future of Go! Take the 2026 Go Developer Survey

http

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2022 License: BSD-3-Clause Imports: 18 Imported by: 5

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
  headers = table
}
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 NewFileRequest added in v0.1.7

func NewFileRequest(L *lua.LState) int

http.filerequest(url, files, params) returns user-data, error

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