Documentation
¶
Overview ¶
Package requests provides the requests HTTP client library.
Index ¶
Constants ¶
const LibraryName = "requests"
LibraryName is the script-visible name of the requests library.
Variables ¶
var RequestsLibrary = newRequestsLibrary(&requestsLib{})
var ResponseClass = &object.Class{ Name: "Response", Methods: map[string]object.Object{ "json": &object.Builtin{ Fn: func(ctx context.Context, kwargs object.Kwargs, args ...object.Object) object.Object { if err := errors.ExactArgs(args, 1); err != nil { return err } if instance, ok := args[0].(*object.Instance); ok { if body, err := instance.Field("body").AsString(); err == nil { return conversion.MustParseJSON(body) } } return errors.NewError("json() called on non-Response object") }, HelpText: `json() - Parses the response body as JSON and returns the parsed object`, }, "raise_for_status": &object.Builtin{ Fn: func(ctx context.Context, kwargs object.Kwargs, args ...object.Object) object.Object { if err := errors.ExactArgs(args, 1); err != nil { return err } if instance, ok := args[0].(*object.Instance); ok { if statusCode, err := instance.Field("status_code").AsInt(); err == nil { if statusCode >= 400 { kind := "Client" if statusCode >= 500 { kind = "Server" } return &object.Exception{ ExceptionType: "HTTPError", Message: fmt.Sprintf("HTTPError: %d %s Error", statusCode, kind), Raised: true, } } return &object.Null{} } } return errors.NewError("raise_for_status() called on non-Response object") }, HelpText: `raise_for_status() - Raises an exception if the status code indicates an error`, }, }, }
ResponseClass defines the Response class with its methods
Functions ¶
func Register ¶
func Register(registrar interface{ RegisterLibrary(*object.Library) }, cfg ...*netsecurity.Config)
Register registers the requests library, under the network policy cfg when one is given. A CA bundle a script names with verify="path" may be any file: use RegisterConfigured to confine it.
func RegisterConfigured ¶
func RegisterConfigured(registrar interface{ RegisterLibrary(*object.Library) }, paths fssecurity.Config, policy *netsecurity.Config)
RegisterConfigured registers the requests library with a filesystem allow-path policy and a network policy, as the os library and the CLI's --allowed-paths and --network-policy use them: a CA bundle a script names with verify="path" must lie within paths' allowed directories (else an uncatchable PermissionError), and every request passes the network policy. A zero fssecurity.Config and a nil policy register it unrestricted.
func RequestsMaxParallelLimit ¶
func RequestsMaxParallelLimit() int
RequestsMaxParallelLimit returns the current ceiling on requests.parallel's max_parallel, 0 when none.
func SetRequestsMaxParallelLimit ¶
func SetRequestsMaxParallelLimit(n int)
SetRequestsMaxParallelLimit caps the max_parallel a script may request from requests.parallel. A script asking for more than the ceiling silently gets the ceiling; it is a resource policy for the host, not an error for the script. A limit of 0 removes the ceiling; negative values are treated as 0. The check is one atomic load per parallel() call.
Types ¶
This section is empty.