starlarkhttp

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const ModuleName = "http.star"

ModuleName defines the expected name for this Module when used in starlark's load() function, eg: load('http.star', 'http')

Variables

This section is empty.

Functions

func AsString

func AsString(x starlark.Value) (string, error)

AsString unquotes a starlark string value

func LoadModule

func LoadModule() (starlark.StringDict, error)

LoadModule creates an http Module

func SetBody

func SetBody(req *http.Request, body starlark.String, formData *starlark.Dict, formEncoding starlark.String, jsondata starlark.Value) error

Types

type Module

type Module struct {
	// contains filtered or unexported fields
}

Module joins http tools to a dataset, allowing dataset to follow along with http requests

func (*Module) StringDict

func (m *Module) StringDict() starlark.StringDict

StringDict returns all module methods in a starlark.StringDict

func (*Module) Struct

func (m *Module) Struct() *starlarkstruct.Struct

Struct returns this module's methods as a starlark Struct

type RequestGuard

type RequestGuard interface {
	Allowed(thread *starlark.Thread, req *http.Request) (*http.Request, error)
}

RequestGuard controls access to http by checking before making requests if Allowed returns an error the request will be denied

var (
	// StarlarkHTTPClient is the http client used to create the http module. override with
	// a custom client before calling LoadModule
	StarlarkHTTPClient = http.DefaultClient
	// StarlarkHTTPGuard is a global RequestGuard used in LoadModule. override with a custom
	// implementation before calling LoadModule
	StarlarkHTTPGuard RequestGuard
)

type Response

type Response struct {
	http.Response
}

Response represents an HTTP response, wrapping a go http.Response with starlark methods

func (*Response) HeadersDict

func (r *Response) HeadersDict() *starlark.Dict

HeadersDict flops

func (*Response) JSON

func (r *Response) JSON(thread *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

JSON attempts to parse the response body as JSON

func (*Response) Struct

func (r *Response) Struct() *starlarkstruct.Struct

Struct turns a response into a *starlark.Struct

func (*Response) Text

func (r *Response) Text(thread *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

Text returns the raw data as a string

Jump to

Keyboard shortcuts

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