http_ns

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2024 License: MIT Imports: 74 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HTTP_UPLOAD_RATE_LIMIT_NAME  = "http/upload"
	HTTP_REQUEST_RATE_LIMIT_NAME = "http/request"

	DEFAULT_HTTP_CLIENT_TIMEOUT = 10 * time.Second

	MISSING_URL_ARG           = "missing core.URL argument"
	OPTION_DOES_NOT_EXIST_FMT = "option '%s' does not exist"

	CERT_MAGIG_LOG_SRC = "http/certmagic"
)
View Source
const (
	CSP_HEADER_NAME          = "Content-Security-Policy"
	DEFAULT_NONCE_BYTE_COUNT = 16
)
View Source
const (
	INOX_FILE_EXTENSION            = inoxconsts.INOXLANG_FILE_EXTENSION
	PATH_PARAMS_CTX_DATA_NAMESPACE = core.Path("/path-params/")

	FS_ROUTING_LOG_SRC = "fs-routing"
)
View Source
const (
	DEFAULT_SELF_SIGNED_CERT_VALIDITY_DURATION = time.Hour * 24 * 180
	RELATIVE_SELF_SIGNED_CERT_FILEPATH         = "./" + inoxconsts.DEV_DIR_NAME + "/self_signed.cert"
	RELATIVE_SELF_SIGNED_CERT_KEY_FILEPATH     = "./" + inoxconsts.DEV_DIR_NAME + "/self_signed.key"
)
View Source
const (
	HTTP_READ_PERM_MIGHT_BE_MISSING    = "http read permission might be missing"
	HTTP_WRITE_PERM_MIGHT_BE_MISSING   = "http write permission might be missing"
	HTTP_DELETE_PERM_MIGHT_BE_MISSING  = "http delete permission might be missing"
	HTTP_PROVIDE_PERM_MIGHT_BE_MISSING = "http provide permission might be missing"
)
View Source
const (
	RESULT_INIT_STATUS_PROPNAME  = "status"
	RESULT_INIT_BODY_PROPNAME    = "body"
	RESULT_INIT_HEADERS_PROPNAME = "headers"
	RESULT_INIT_SESSION_PROPNAME = "session"
)
View Source
const (
	//socket
	SOCKET_RLIMIT_WINDOW       = 10 * time.Second
	SOCKET_MAX_READ_REQ_COUNT  = 10
	SOCKET_MAX_WRITE_REQ_COUNT = 5

	//ip level
	SHARED_READ_BURST_WINDOW     = 10 * time.Second
	SHARED_READ_BURST_WINDOW_REQ = 60

	SHARED_WRITE_BURST_WINDOW     = 10 * time.Second
	SHARED_WRITE_BURST_WINDOW_REQ = 10
)
View Source
const (
	DEFAULT_HTTP_SERVER_READ_HEADER_TIMEOUT = 3 * time.Second
	DEFAULT_HTTP_SERVER_READ_TIMEOUT        = DEFAULT_HTTP_SERVER_READ_HEADER_TIMEOUT + 8*time.Second
	DEFAULT_HTTP_SERVER_WRITE_TIMEOUT       = 2 * (DEFAULT_HTTP_SERVER_READ_TIMEOUT - DEFAULT_HTTP_SERVER_READ_HEADER_TIMEOUT)
	DEFAULT_HTTP_SERVER_MAX_HEADER_BYTES    = 1 << 12
	DEFAULT_HTTP_SERVER_TX_TIMEOUT          = 20 * time.Second
	SSE_STREAM_WRITE_TIMEOUT                = 500 * time.Second

	HTTP_SERVER_STARTING_WAIT_TIME        = 5 * time.Millisecond
	HTTP_SERVER_GRACEFUL_SHUTDOWN_TIMEOUT = 5 * time.Second

	NO_HANDLER_PLACEHOLDER_MESSAGE = "hello"

	HANDLING_DESC_ROUTING_PROPNAME     = "routing"
	HANDLING_DESC_DEFAULT_CSP_PROPNAME = "default-csp"
	HANDLING_DESC_CERTIFICATE_PROPNAME = "certificate"
	HANDLING_DESC_KEY_PROPNAME         = "key"

	HANDLING_DESC_DEFAULT_LIMITS_PROPNAME = "default-limits"
	HANDLING_DESC_MAX_LIMITS_PROPNAME     = "max-limits"
	HANDLING_DESC_SESSIONS_PROPNAME       = "sessions"
	SESSIONS_DESC_COLLECTION_PROPNAME     = "collection"

	HTTP_SERVER_SRC = "http/server"

	SESSION_ID_PROPNAME = "id"
)
View Source
const (
	DEFAULT_HTTPS_PORT = "443"

	SERVER_HANDLING_ARG_NAME = "handler/handling"
)
View Source
const (
	MIN_SESSION_ID_BYTE_COUNT      = 16
	MAX_SESSION_ID_BYTE_COUNT      = 32
	DEFAULT_SESSION_ID_BYTE_COUNT  = MIN_SESSION_ID_BYTE_COUNT
	DEFAULT_SESSION_ID_COOKIE_NAME = "session-id"

	SESSION_CTX_DATA_KEY = core.Path("/session")
)
View Source
const (
	INITIAL_SSE_CLIENT_BUFFER_SIZE = 4096
	MAX_SSE_CLIENT_BUFFER_SIZE     = 1 << 16
)
View Source
const (
	VIEW_UPDATE_WATCHING_TIMEOUT        = 10 * time.Millisecond
	VIEW_UPDATE_SSE_STREAM_STOP_TIMEOUT = 10 * time.Millisecond
)
View Source
const DEFAULT_ACCEPT_HEADER = "*/*"
View Source
const DEFAULT_EVENT_STREAM_BUFFER_SIZE = 200
View Source
const DEFAULT_SUBSCRIPTION_CHAN_SIZE = 50
View Source
const (
	REQUEST_ID_LOG_FIELD_NAME = "reqID"
)
View Source
const (
	STOPPING_SUB_WAIT_TIME = time.Millisecond
)

Variables

View Source
var (
	DEFAULT_PUSHED_BYTESTREAM_CHUNK_SIZE_RANGE = core.NewIntRange(100, 1000)
	BYTESTREAM_SSE_STREAM_STOP_TIMEOUT         = 10 * time.Millisecond
	BYTESTREAM_CHUNK_WAIT_TIMEOUT              = 2 * time.Millisecond
)
View Source
var (
	DEFAULT_CSP, _ = NewCSPWithDirectives(nil)

	HANDLER_DISABLED_ARGS = []bool{true, true}
)
View Source
var (
	STATUS_NAMESPACE = core.NewNamespace("status", map[string]core.Value{

		"OK": StatusCode(http.StatusOK),

		"MOVED_PERMANENTLY":  StatusCode(http.StatusMovedPermanently),
		"SEE_OTHER":          StatusCode(http.StatusSeeOther),
		"TEMPORARY_REDIRECT": StatusCode(http.StatusTemporaryRedirect),
		"PERMANENT_REDIRECT": StatusCode(http.StatusPermanentRedirect),

		"BAD_REQUEST":        StatusCode(http.StatusBadRequest),
		"UNAUTHORIZED":       StatusCode(http.StatusUnauthorized),
		"FORBIDDEN":          StatusCode(http.StatusForbidden),
		"NOT_FOUND":          StatusCode(http.StatusNotFound),
		"METHOD_NOT_ALLOWED": StatusCode(http.StatusMethodNotAllowed),
		"NOT_ACCEPTABLE":     StatusCode(http.StatusNotAcceptable),

		"INTERNAL_SERVER_ERROR":      StatusCode(http.StatusInternalServerError),
		"BAD_GATEWAY":                StatusCode(http.StatusBadGateway),
		"GATEWAY_TIMEOUT":            StatusCode(http.StatusGatewayTimeout),
		"HTTP_VERSION_NOT_SUPPORTED": StatusCode(http.StatusHTTPVersionNotSupported),
	})

	MAKE_STATUS_CODE_PARAMS      = &[]symbolic.Value{http_symbolic.STATUS_CODE_INT_VALUE}
	MAKE_STATUS_CODE_PARAM_NAMES = []string{"code"}
)
View Source
var (
	CALLABLE_HTTP_REQUEST_PATTERN = &core.TypePattern{
		Name:             "http.req",
		Type:             reflect.TypeOf(&Request{}),
		SymbolicValue:    &http_symbolic.Request{},
		CallImpl:         createRequestPattern,
		SymbolicCallImpl: createSymbolicRequestPattern,
	}

	HTTP_REQUEST_PATTERN_PATTERN = &core.TypePattern{
		Name:          "http.req-pattern",
		Type:          reflect.TypeOf(&RequestPattern{}),
		SymbolicValue: http_symbolic.ANY_REQUEST_PATTERN,
	}
)
View Source
var (
	ErrNotAcceptedContentType                   = errors.New("not accepted content type")
	ErrCannotMutateWriterOfFinishedResponse     = errors.New("cannot mutate writer of finished response")
	ErrCannotMutateWriterWithDetachedRespWriter = errors.New("cannot mutate writer with detached response writer")
	ErrStatusAlreadySent                        = errors.New("status already sent")
)
View Source
var (
	ErrHandlerNotSharable            = errors.New("handler is not sharable")
	ErrCannotMutateInitializedServer = errors.New("cannot mutate initialized server")

	HTTP_ROUTING_SYMB_OBJ = symbolic.NewInexactObject(map[string]symbolic.Serializable{
		"static":  symbolic.ANY_ABS_DIR_PATH,
		"dynamic": symbolic.ANY_ABS_DIR_PATH,
	}, map[string]struct{}{
		"static":  {},
		"dynamic": {},
	}, nil)

	SESSIONS_CONFIG_SYMB_OBJ = symbolic.NewInexactObject2(map[string]symbolic.Serializable{
		SESSIONS_DESC_COLLECTION_PROPNAME: symb_containers.NewSetWithPattern(symbolic.ANY_PATTERN, common.NewPropertyValueUniqueness(SESSION_ID_PROPNAME)),
	})

	SYMBOLIC_HANDLING_DESC = symbolic.NewInexactObject(map[string]symbolic.Serializable{
		HANDLING_DESC_ROUTING_PROPNAME: symbolic.AsSerializableChecked(symbolic.NewMultivalue(
			symbolic.ANY_INOX_FUNC,
			symbolic.NewMapping(),
			HTTP_ROUTING_SYMB_OBJ,
		)),
		HANDLING_DESC_DEFAULT_CSP_PROPNAME:    http_ns_symb.ANY_CSP,
		HANDLING_DESC_CERTIFICATE_PROPNAME:    symbolic.ANY_STR_LIKE,
		HANDLING_DESC_KEY_PROPNAME:            symbolic.ANY_SECRET,
		HANDLING_DESC_DEFAULT_LIMITS_PROPNAME: symbolic.ANY_OBJ,
		HANDLING_DESC_MAX_LIMITS_PROPNAME:     symbolic.ANY_OBJ,
		HANDLING_DESC_SESSIONS_PROPNAME:       SESSIONS_CONFIG_SYMB_OBJ,
	}, map[string]struct{}{

		HANDLING_DESC_DEFAULT_CSP_PROPNAME:    {},
		HANDLING_DESC_CERTIFICATE_PROPNAME:    {},
		HANDLING_DESC_KEY_PROPNAME:            {},
		HANDLING_DESC_DEFAULT_LIMITS_PROPNAME: {},
		HANDLING_DESC_MAX_LIMITS_PROPNAME:     {},
		HANDLING_DESC_SESSIONS_PROPNAME:       {},
	}, nil)

	NEW_SERVER_SINGLE_PARAM_NAME = []string{"host"}
	NEW_SERVER_TWO_PARAM_NAMES   = []string{"host", "handling"}
)
View Source
var (
	MIN_SESSION_ID_LEN   = hex.EncodedLen(MIN_SESSION_ID_BYTE_COUNT)
	MAX_SESSION_ID_LEN   = hex.EncodedLen(MAX_SESSION_ID_BYTE_COUNT)
	ErrSessionNotFound   = errors.New("session not found")
	ErrSessionIdTooLong  = errors.New("session id is too long")
	ErrSessionIdTooShort = errors.New("session id is too short")
)
View Source
var (
	SSE_ID_HEADER    = []byte("id:")
	SSE_DATA_HEADER  = []byte("data:")
	SSE_EVENT_HEADER = []byte("event:")
	SSE_RETRY_HEADER = []byte("retry:")
)
View Source
var (
	DEFAULT_DIRECTIVE_VALUES = map[string][]CSPDirectiveValue{
		"default-src": {{/* contains filtered or unexported fields */}},

		"frame-ancestors": {{/* contains filtered or unexported fields */}},
		"frame-src":       {{/* contains filtered or unexported fields */}},

		"script-src-elem": {{/* contains filtered or unexported fields */}},
		"connect-src":     {{/* contains filtered or unexported fields */}},

		"font-src":       {{/* contains filtered or unexported fields */}},
		"img-src":        {{/* contains filtered or unexported fields */}},
		"style-src-elem": {{/* contains filtered or unexported fields */}},
	}
)
View Source
var (
	DEFAULT_HTTP_PROFILE_CONFIG = ClientConfig{
		SaveCookies: false,
	}
)
View Source
var DEFAULT_HTTP_REQUEST_OPTIONS = &RequestOptions{
	Timeout:            DEFAULT_HTTP_CLIENT_TIMEOUT,
	InsecureSkipVerify: false,
}
View Source
var (
	ErrOutOfBoundsStatusCode = errors.New("out of bounds status code")
)
View Source
var (
	//methods allowed in handler module filenames.
	FS_ROUTING_METHODS = spec.FS_ROUTING_METHODS
)
View Source
var (
	NEWLINE_BYTES = []byte{'\n'}
)

Functions

func DeserializeHttpRequestPattern

func DeserializeHttpRequestPattern(ctx *core.Context, it *jsoniter.Iterator, pattern core.Pattern, try bool) (_ core.Pattern, finalErr error)

func GenerateSelfSignedCertAndKey

func GenerateSelfSignedCertAndKey(args SelfSignedCertParams) (cert *pem.Block, key *pem.Block, err error)

func GetTLSConfig

func GetTLSConfig(ctx *core.Context, pemEncodedCert string, pemEncodedKey string) (*tls.Config, error)

func HttpRead

func HttpRead(ctx *core.Context, u core.URL, args ...core.Value) (result core.Value, finalErr error)

func IsMutationMethod

func IsMutationMethod(method string) bool

func MakeHTTPProxy

func MakeHTTPProxy(ctx *core.Context, params HTTPProxyParams) (*http.Server, error)

StartHTTPProxy starts an HTTP proxy listening on 127.0.0.1:<port>. The connection between the client and an HTTP proxy is not encrypted, https://chromium.googlesource.com/chromium/src/+/HEAD/net/docs/proxy.md#http-proxy-scheme.

func Mime_

func Mime_(ctx *core.Context, arg core.String) (core.Mimetype, error)

func NewGolangHttpServer

func NewGolangHttpServer(ctx *core.Context, config GolangHttpServerConfig) (*http.Server, error)

func NewHttpNamespace

func NewHttpNamespace() *core.Namespace

func PercentDecode

func PercentDecode(ctx *core.Context, s core.StringLike) (core.String, error)

func PercentEncode

func PercentEncode(ctx *core.Context, s core.StringLike) core.String

func ServeFile

func ServeFile(ctx *core.Context, rw *ResponseWriter, r *Request, pth core.Path) error

ServeFile is a thin wrapper around serveFileNativeRequest.

Types

type API

type API = spec.API

type ApiEndpoint

type ApiEndpoint = spec.ApiEndpoint

type CSPDirective

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

type CSPDirectiveValue

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

type CSPHeaderValueParams

type CSPHeaderValueParams struct {
	ScriptsNonce string //optional
}

type Client

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

A Client represents a high level http client, Client implements core.ProtocolClient.

func NewClient

func NewClient(ctx *core.Context, configObject *core.Object) (*Client, error)

func NewHttpClientFromPreExistingClient

func NewHttpClientFromPreExistingClient(client *http.Client, insecure bool) *Client

func (*Client) DoRequest

func (c *Client) DoRequest(ctx *core.Context, req *Request) (*Response, error)

func (*Client) Equal

func (c *Client) Equal(ctx *core.Context, other core.Value, alreadyCompared map[uintptr]uintptr, depth int) bool

func (*Client) GetGoMethod

func (c *Client) GetGoMethod(name string) (*core.GoFunction, bool)

func (*Client) GetHostCookieObjects

func (c *Client) GetHostCookieObjects(ctx *core.Context, h core.Host) *core.List

func (*Client) GetHostCookies

func (c *Client) GetHostCookies(h core.Host) []*http.Cookie

func (*Client) IsMutable

func (c *Client) IsMutable() bool

func (*Client) MakeRequest

func (c *Client) MakeRequest(ctx *core.Context, method string, u core.URL, body io.Reader, contentType string, opts *RequestOptions) (*Request, error)

func (*Client) PrettyPrint

func (c *Client) PrettyPrint(w *bufio.Writer, config *core.PrettyPrintConfig, depth int, parentIndentCount int)

func (*Client) Prop

func (c *Client) Prop(ctx *core.Context, name string) core.Value

func (*Client) PropertyNames

func (*Client) PropertyNames(ctx *core.Context) []string

func (*Client) Schemes

func (c *Client) Schemes() []core.Scheme

func (*Client) SetProp

func (*Client) SetProp(ctx *core.Context, name string, value core.Value) error

func (*Client) ToSymbolicValue

func (c *Client) ToSymbolicValue(ctx *core.Context, encountered map[uintptr]symbolic.Value) (symbolic.Value, error)

type ClientConfig

type ClientConfig struct {
	Insecure     bool
	SaveCookies  bool
	Finalization *core.Dictionary
}

type ContentSecurityPolicy

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

func NewCSP

func NewCSP(ctx *core.Context, desc *core.Object) (*ContentSecurityPolicy, error)

func NewCSPWithDirectives

func NewCSPWithDirectives(directives []CSPDirective) (*ContentSecurityPolicy, error)

NewCSPWithDirectives creates a CSP with the default directives and a list of given directives.

func (*ContentSecurityPolicy) Directive

func (c *ContentSecurityPolicy) Directive(directiveName string) (CSPDirective, bool)

func (*ContentSecurityPolicy) Equal

func (c *ContentSecurityPolicy) Equal(ctx *core.Context, other core.Value, alreadyCompared map[uintptr]uintptr, depth int) bool

func (*ContentSecurityPolicy) HeaderValue

func (c *ContentSecurityPolicy) HeaderValue(params CSPHeaderValueParams) string

func (*ContentSecurityPolicy) IsMutable

func (*ContentSecurityPolicy) IsMutable() bool

func (*ContentSecurityPolicy) PrettyPrint

func (csp *ContentSecurityPolicy) PrettyPrint(w *bufio.Writer, config *core.PrettyPrintConfig, depth int, parentIndentCount int)

func (*ContentSecurityPolicy) String

func (csp *ContentSecurityPolicy) String() string

func (*ContentSecurityPolicy) ToSymbolicValue

func (*ContentSecurityPolicy) ToSymbolicValue(ctx *core.Context, encountered map[uintptr]symbolic.Value) (symbolic.Value, error)

func (*ContentSecurityPolicy) WriteJSONRepresentation

func (c *ContentSecurityPolicy) WriteJSONRepresentation(ctx *core.Context, w *jsoniter.Stream, config core.JSONSerializationConfig, depth int) error

func (*ContentSecurityPolicy) WriteRepresentation

func (c *ContentSecurityPolicy) WriteRepresentation(ctx *core.Context, w io.Writer, config *core.ReprConfig, depth int) error

type GolangHttpServerConfig

type GolangHttpServerConfig struct {
	//hostname:port or :port
	Addr    string
	Handler http.Handler

	PemEncodedCert string
	PemEncodedKey  string

	AllowSelfSignedCertCreationEvenIfExposed bool
	//if true the certificate and key files are persisted on the filesystem for later reuse.
	PersistCreatedLocalCert        bool
	SelfSignedCertValidityDuration time.Duration //defaults to DEFAULT_SELF_SIGNED_CERT_VALIDITY_DURATION

	ReadHeaderTimeout time.Duration // defaults to DEFAULT_HTTP_SERVER_READ_HEADER_TIMEOUT
	ReadTimeout       time.Duration // defaults to DEFAULT_HTTP_SERVER_READ_TIMEOUT
	WriteTimeout      time.Duration // defaults to DEFAULT_HTTP_SERVER_WRITE_TIMEOUT
	MaxHeaderBytes    int           // defaults to DEFAULT_HTTP_SERVER_MAX_HEADER_BYTES
}

type HTTPProxyParams

type HTTPProxyParams struct {
	Port int

	//OnRequest is invoked before GetContext and before any permissions is checked to forward the request.
	//If a non nil response is returned it it sent to the client.
	OnRequest func(req *http.Request, proxyCtx *goproxy.ProxyCtx) (*http.Request, *http.Response)

	//GetContext is called to retrieve the context for the request, the context is used to check permissions.
	GetContext func(req *http.Request) *core.Context

	RemovedRequestHeaders []string

	Logger zerolog.Logger
}

type HttpsServer

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

HttpsServer implements the GoValue interface.

func NewFileServer

func NewFileServer(ctx *core.Context, args ...core.Value) (*HttpsServer, error)

NewFileServer returns an HttpServer that uses Go's http.FileServer(dir) to handle requests

func NewHttpsServer

func NewHttpsServer(ctx *core.Context, host core.Host, args ...core.Value) (*HttpsServer, error)

NewHttpsServer creates a listening HTTPS server. The server's defaultLimits are constructed by merging the default request handling limits with the default-limits in arguments. The server's maxLimits are constructed by merging the default max request handling limits with the max-limits in arguments.

func (*HttpsServer) Close

func (serv *HttpsServer) Close(ctx *core.Context)

func (*HttpsServer) Equal

func (s *HttpsServer) Equal(ctx *core.Context, other core.Value, alreadyCompared map[uintptr]uintptr, depth int) bool

func (*HttpsServer) GetGoMethod

func (serv *HttpsServer) GetGoMethod(name string) (*core.GoFunction, bool)

func (*HttpsServer) ImmediatelyClose

func (serv *HttpsServer) ImmediatelyClose(ctx *core.Context)

func (*HttpsServer) IsMutable

func (serv *HttpsServer) IsMutable() bool

func (*HttpsServer) ListeningAddr

func (serv *HttpsServer) ListeningAddr() core.Host

func (*HttpsServer) PrettyPrint

func (s *HttpsServer) PrettyPrint(w *bufio.Writer, config *core.PrettyPrintConfig, depth int, parentIndentCount int)

func (*HttpsServer) Prop

func (s *HttpsServer) Prop(ctx *core.Context, name string) core.Value

func (*HttpsServer) PropertyNames

func (*HttpsServer) PropertyNames(ctx *core.Context) []string

func (*HttpsServer) SetProp

func (*HttpsServer) SetProp(ctx *core.Context, name string, value core.Value) error

func (*HttpsServer) ToSymbolicValue

func (serv *HttpsServer) ToSymbolicValue(ctx *core.Context, encountered map[uintptr]symbolic.Value) (symbolic.Value, error)

func (*HttpsServer) WaitClosed

func (serv *HttpsServer) WaitClosed(ctx *core.Context)

type IncomingRequestInfo

type IncomingRequestInfo struct {
	ULID     ulid.ULID
	Path     core.Path
	Hostname string
	Method   string
	//VMethod                  VMethod
	//ResourceTypeName         ModelName
	ContentType        string
	RemoteAddrAndPort  string
	Referer            string
	URL                core.URL
	UserAgent          string
	ResponseStatusCode int

	CreationTime                    time.Time
	EndTime                         time.Time //rename ?
	HandlingDurationMillis          int64
	SessionCookieStart              string
	CookieNames                     []string
	Errors                          []string
	Info                            []string
	SetCookieHeaderValueStart       string
	HeaderNames                     []string
	SeeOtherRedirectURL             string
	ResourceWaitingDurationMicrosec int64
	SentBodyBytes                   int
}

should not contain super sensitive information (full cookie, email address, ...)

func NewIncomingRequestInfo

func NewIncomingRequestInfo(r *Request) *IncomingRequestInfo

func (IncomingRequestInfo) RemoteIpAddress

func (reqInfo IncomingRequestInfo) RemoteIpAddress() string

type Request

type Request struct {
	ULID       ulid.ULID
	ULIDString string

	//accessible from inox
	Method             core.String //.url.Method from the *http.Request ("GET" if empty)
	URL                core.URL    //.url.URL from the *http.Request
	Path               core.Path   //.url.Path from the *http.Request (already escaped)
	Body               *core.Reader
	Cookies            []*http.Cookie
	ParsedAcceptHeader mimeheader.AcceptHeader
	AcceptHeader       string
	ContentType        mimeheader.MimeType
	Session            *core.Object //can be nil

	//
	CreationTime      time.Time
	HeaderNames       []string
	UserAgent         string
	Hostname          string
	RemoteAddrAndPort netaddr.RemoteAddrWithPort //empty for client side requests
	RemoteIpAddr      netaddr.RemoteIpAddr       //empty for client side requests
	// contains filtered or unexported fields
}

Request is considered immutable from the viewpoint of Inox code, it should NOT be mutated.

func NewClientSideRequest

func NewClientSideRequest(r *http.Request) (*Request, error)

func NewServerSideRequest

func NewServerSideRequest(r *http.Request, logger zerolog.Logger, server *HttpsServer) (*Request, error)

func (*Request) AcceptAny

func (req *Request) AcceptAny() bool

func (*Request) Equal

func (r *Request) Equal(ctx *core.Context, other core.Value, alreadyCompared map[uintptr]uintptr, depth int) bool

func (*Request) GetGoMethod

func (req *Request) GetGoMethod(name string) (*core.GoFunction, bool)

func (*Request) IsGetOrHead

func (req *Request) IsGetOrHead() bool

func (*Request) IsMutable

func (req *Request) IsMutable() bool

func (*Request) IsSharable

func (req *Request) IsSharable(originState *core.GlobalState) (bool, string)

func (*Request) IsShared

func (req *Request) IsShared() bool

func (*Request) PrettyPrint

func (r *Request) PrettyPrint(w *bufio.Writer, config *core.PrettyPrintConfig, depth int, parentIndentCount int)

func (*Request) Prop

func (req *Request) Prop(ctx *core.Context, name string) core.Value

func (*Request) PropertyNames

func (*Request) PropertyNames(ctx *core.Context) []string

func (*Request) Request

func (req *Request) Request() *http.Request

func (*Request) SetProp

func (*Request) SetProp(ctx *core.Context, name string, value core.Value) error

func (*Request) Share

func (req *Request) Share(originState *core.GlobalState)

func (*Request) SmartLock

func (req *Request) SmartLock(state *core.GlobalState)

func (*Request) SmartUnlock

func (req *Request) SmartUnlock(state *core.GlobalState)

func (*Request) ToSymbolicValue

func (req *Request) ToSymbolicValue(ctx *core.Context, encountered map[uintptr]symbolic.Value) (symbolic.Value, error)

func (*Request) WriteJSONRepresentation

func (r *Request) WriteJSONRepresentation(ctx *core.Context, w *jsoniter.Stream, config core.JSONSerializationConfig, depth int) error

func (*Request) WriteRepresentation

func (r *Request) WriteRepresentation(ctx *core.Context, w io.Writer, config *core.ReprConfig, depth int) error

type RequestOptions

type RequestOptions struct {
	Timeout            time.Duration
	InsecureSkipVerify bool
	Jar                http.CookieJar
}

type RequestPattern

type RequestPattern struct {
	core.NotCallablePatternMixin
	// contains filtered or unexported fields
}

func (*RequestPattern) Equal

func (p *RequestPattern) Equal(ctx *core.Context, other core.Value, alreadyCompared map[uintptr]uintptr, depth int) bool

func (*RequestPattern) IsMutable

func (*RequestPattern) IsMutable() bool

func (*RequestPattern) Iterator

func (*RequestPattern) PrettyPrint

func (p *RequestPattern) PrettyPrint(w *bufio.Writer, config *core.PrettyPrintConfig, depth int, parentIndentCount int)

func (*RequestPattern) Random

func (*RequestPattern) Random(ctx *core.Context, options ...core.Option) core.Value

func (*RequestPattern) StringPattern

func (*RequestPattern) StringPattern() (core.StringPattern, bool)

func (*RequestPattern) Test

func (p *RequestPattern) Test(ctx *core.Context, v core.Value) bool

func (*RequestPattern) ToSymbolicValue

func (*RequestPattern) ToSymbolicValue(ctx *core.Context, encountered map[uintptr]symbolic.Value) (symbolic.Value, error)

func (*RequestPattern) WriteJSONRepresentation

func (p *RequestPattern) WriteJSONRepresentation(ctx *core.Context, w *jsoniter.Stream, config core.JSONSerializationConfig, depth int) error

type Response

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

func HttpDelete

func HttpDelete(ctx *core.Context, args ...core.Value) (*Response, error)

func HttpGet

func HttpGet(ctx *core.Context, u core.URL, args ...core.Value) (*Response, error)

func HttpPatch

func HttpPatch(ctx *core.Context, args ...core.Value) (*Response, error)

func HttpPost

func HttpPost(ctx *core.Context, args ...core.Value) (*Response, error)

func (*Response) Body

func (resp *Response) Body(ctx *core.Context) io.ReadCloser

func (*Response) ContentType

func (resp *Response) ContentType(ctx *core.Context) (core.Mimetype, bool, error)

func (*Response) Equal

func (r *Response) Equal(ctx *core.Context, other core.Value, alreadyCompared map[uintptr]uintptr, depth int) bool

func (*Response) GetGoMethod

func (resp *Response) GetGoMethod(name string) (*core.GoFunction, bool)

func (*Response) IsMutable

func (resp *Response) IsMutable() bool

func (*Response) PrettyPrint

func (r *Response) PrettyPrint(w *bufio.Writer, config *core.PrettyPrintConfig, depth int, parentIndentCount int)

func (*Response) Prop

func (resp *Response) Prop(ctx *core.Context, name string) core.Value

func (*Response) PropertyNames

func (*Response) PropertyNames(ctx *core.Context) []string

func (*Response) SetProp

func (*Response) SetProp(ctx *core.Context, name string, value core.Value) error

func (*Response) Status

func (resp *Response) Status(ctx *core.Context) string

func (*Response) StatusCode

func (resp *Response) StatusCode(ctx *core.Context) int

func (*Response) ToSymbolicValue

func (resp *Response) ToSymbolicValue(ctx *core.Context, encountered map[uintptr]symbolic.Value) (symbolic.Value, error)

type ResponseWriter

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

func NewResponseWriter

func NewResponseWriter(req *Request, rw http.ResponseWriter, serverLogger zerolog.Logger) *ResponseWriter

func (*ResponseWriter) AddHeader

func (rw *ResponseWriter) AddHeader(ctx *core.Context, k, v core.String)

func (*ResponseWriter) DetachBodyWriter

func (rw *ResponseWriter) DetachBodyWriter() io.Writer

DetachBodyWriter writes the headers and the planned status if they have not been sent yet, then it detachs the underlying response writer and returns it. The HttpResponseWriter should not be used afterwards.

func (*ResponseWriter) DetachRespWriter

func (rw *ResponseWriter) DetachRespWriter() http.ResponseWriter

DetachBodyWriter detachs the underlying response writer and returns it. The HttpResponseWriter should not be used afterwards.

func (*ResponseWriter) Equal

func (rw *ResponseWriter) Equal(ctx *core.Context, other core.Value, alreadyCompared map[uintptr]uintptr, depth int) bool

func (*ResponseWriter) FinalLog

func (rw *ResponseWriter) FinalLog()

func (*ResponseWriter) Finish

func (rw *ResponseWriter) Finish(ctx *core.Context)

func (*ResponseWriter) GetGoMethod

func (rw *ResponseWriter) GetGoMethod(name string) (*core.GoFunction, bool)

func (*ResponseWriter) IsMutable

func (resp *ResponseWriter) IsMutable() bool

func (*ResponseWriter) IsStatusSent

func (rw *ResponseWriter) IsStatusSent() bool

func (ResponseWriter) PlannedStatus

func (rw ResponseWriter) PlannedStatus() int

func (*ResponseWriter) PrettyPrint

func (rw *ResponseWriter) PrettyPrint(w *bufio.Writer, config *core.PrettyPrintConfig, depth int, parentIndentCount int)

func (*ResponseWriter) Prop

func (rw *ResponseWriter) Prop(ctx *core.Context, name string) core.Value

func (*ResponseWriter) PropertyNames

func (rw *ResponseWriter) PropertyNames(ctx *core.Context) []string

func (ResponseWriter) SentStatus

func (rw ResponseWriter) SentStatus() int

func (*ResponseWriter) SetContentType

func (rw *ResponseWriter) SetContentType(s string)

func (*ResponseWriter) SetCookie

func (rw *ResponseWriter) SetCookie(ctx *core.Context, obj *core.Object) error

func (*ResponseWriter) SetProp

func (*ResponseWriter) SetProp(ctx *core.Context, name string, value core.Value) error

func (*ResponseWriter) SetStatus

func (rw *ResponseWriter) SetStatus(ctx *core.Context, status StatusCode)

func (*ResponseWriter) SetWriteDeadline

func (rw *ResponseWriter) SetWriteDeadline(timeout time.Duration)

func (*ResponseWriter) ToSymbolicValue

func (resp *ResponseWriter) ToSymbolicValue(ctx *core.Context, encountered map[uintptr]symbolic.Value) (symbolic.Value, error)

func (*ResponseWriter) WriteBinary

func (rw *ResponseWriter) WriteBinary(ctx *core.Context, bytes *core.ByteSlice) (core.Int, error)

func (*ResponseWriter) WriteCSS

func (rw *ResponseWriter) WriteCSS(ctx *core.Context, v core.Value) (core.Int, error)

func (*ResponseWriter) WriteError

func (rw *ResponseWriter) WriteError(ctx *core.Context, err core.Error, code StatusCode)

func (*ResponseWriter) WriteHTML

func (rw *ResponseWriter) WriteHTML(ctx *core.Context, v core.Value) (core.Int, error)

func (*ResponseWriter) WriteHeaders

func (rw *ResponseWriter) WriteHeaders(ctx *core.Context, status *core.OptionalParam[StatusCode])

func (*ResponseWriter) WriteJS

func (rw *ResponseWriter) WriteJS(ctx *core.Context, v core.Value) (core.Int, error)

func (*ResponseWriter) WriteJSON

func (rw *ResponseWriter) WriteJSON(ctx *core.Context, v core.Serializable) (core.Int, error)

func (*ResponseWriter) WritePlainText

func (rw *ResponseWriter) WritePlainText(ctx *core.Context, bytes *core.ByteSlice) (core.Int, error)

type Result

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

func NewResult

func NewResult(ctx *core.Context, init *core.Object) *Result

func (*Result) Equal

func (r *Result) Equal(ctx *core.Context, other core.Value, alreadyCompared map[uintptr]uintptr, depth int) bool

func (*Result) IsMutable

func (resp *Result) IsMutable() bool

func (*Result) PrettyPrint

func (r *Result) PrettyPrint(w *bufio.Writer, config *core.PrettyPrintConfig, depth int, parentIndentCount int)

func (*Result) ToSymbolicValue

func (res *Result) ToSymbolicValue(ctx *core.Context, encountered map[uintptr]symbolic.Value) (symbolic.Value, error)

type SelfSignedCertParams

type SelfSignedCertParams struct {
	Localhost        bool
	NonLocalhostIPs  bool
	ValidityDuration time.Duration //should be >= 100ms, defaults to DEFAULT_SELF_SIGNED_CERT_VALIDITY_DURATION
}

type ServerSentEvent

type ServerSentEvent struct {
	ID      []byte
	Data    []byte
	Event   []byte
	Retry   []byte
	Comment []byte
	// contains filtered or unexported fields
}

func (*ServerSentEvent) HasContent

func (e *ServerSentEvent) HasContent() bool

func (*ServerSentEvent) ToEvent

func (e *ServerSentEvent) ToEvent() *core.Event

type ServerSentEventSource

type ServerSentEventSource struct {
	core.EventSourceBase
	// contains filtered or unexported fields
}

func NewEventSource

func NewEventSource(ctx *core.Context, resourceNameOrPattern core.Value) (*ServerSentEventSource, error)

func (*ServerSentEventSource) Close

func (evs *ServerSentEventSource) Close()

func (*ServerSentEventSource) Equal

func (evs *ServerSentEventSource) Equal(ctx *core.Context, other core.Value, alreadyCompared map[uintptr]uintptr, depth int) bool

func (*ServerSentEventSource) GetGoMethod

func (evs *ServerSentEventSource) GetGoMethod(name string) (*core.GoFunction, bool)

func (*ServerSentEventSource) IsClosed

func (evs *ServerSentEventSource) IsClosed() bool

func (*ServerSentEventSource) IsMutable

func (*ServerSentEventSource) IsMutable() bool

func (*ServerSentEventSource) Iterator

func (*ServerSentEventSource) PrettyPrint

func (evs *ServerSentEventSource) PrettyPrint(w *bufio.Writer, config *core.PrettyPrintConfig, depth int, parentIndentCount int)

func (*ServerSentEventSource) Prop

func (evs *ServerSentEventSource) Prop(ctx *core.Context, name string) core.Value

func (*ServerSentEventSource) PropertyNames

func (*ServerSentEventSource) PropertyNames(ctx *core.Context) []string

func (*ServerSentEventSource) SetProp

func (*ServerSentEventSource) SetProp(ctx *core.Context, name string, value core.Value) error

func (*ServerSentEventSource) ToSymbolicValue

func (evs *ServerSentEventSource) ToSymbolicValue(ctx *core.Context, encountered map[uintptr]symbolic.Value) (symbolic.Value, error)

type SseServer

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

func NewSseServer

func NewSseServer() *SseServer

func (*SseServer) Close

func (s *SseServer) Close()

Close closes all the streams.

func (*SseServer) CreateStream

func (s *SseServer) CreateStream(id string) *multiSubscriptionSSEStream

func (*SseServer) Publish

func (s *SseServer) Publish(streamId string, event *ServerSentEvent)

func (*SseServer) PushSubscriptionEvents

func (s *SseServer) PushSubscriptionEvents(config eventPushConfig)

PushSubscriptionEvents writes the headers required for event streaming & push events.

func (*SseServer) RemoveStream

func (s *SseServer) RemoveStream(id string)

type Status

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

func MakeStatus

func MakeStatus(code StatusCode) (Status, error)

func ParseStatus

func ParseStatus(str string) (Status, error)

func (Status) Code

func (s Status) Code() StatusCode

func (Status) Equal

func (s Status) Equal(ctx *core.Context, other core.Value, alreadyCompared map[uintptr]uintptr, depth int) bool

func (Status) FullText

func (s Status) FullText() string

func (*Status) GetGoMethod

func (*Status) GetGoMethod(name string) (*core.GoFunction, bool)

func (Status) IsMutable

func (s Status) IsMutable() bool

func (Status) PrettyPrint

func (s Status) PrettyPrint(w *bufio.Writer, config *core.PrettyPrintConfig, depth int, parentIndentCount int)

func (*Status) Prop

func (s *Status) Prop(ctx *core.Context, name string) core.Value

func (Status) PropertyNames

func (Status) PropertyNames(*core.Context) []string

func (Status) ReasonPhrase

func (s Status) ReasonPhrase() string

func (Status) SetProp

func (Status) SetProp(ctx *core.Context, name string, value core.Value) error

func (Status) ToSymbolicValue

func (s Status) ToSymbolicValue(ctx *core.Context, encountered map[uintptr]symbolic.Value) (symbolic.Value, error)

func (Status) WriteJSONRepresentation

func (s Status) WriteJSONRepresentation(ctx *core.Context, w *jsoniter.Stream, config core.JSONSerializationConfig, depth int) error

func (Status) WriteRepresentation

func (Status) WriteRepresentation(ctx *core.Context, w io.Writer, config *core.ReprConfig, depth int) error

type StatusCode

type StatusCode uint16

func MakeStatusCode

func MakeStatusCode(_ *core.Context, n core.Int) (StatusCode, error)

func (StatusCode) Equal

func (c StatusCode) Equal(ctx *core.Context, other core.Value, alreadyCompared map[uintptr]uintptr, depth int) bool

func (StatusCode) IsMutable

func (c StatusCode) IsMutable() bool

func (StatusCode) PrettyPrint

func (c StatusCode) PrettyPrint(w *bufio.Writer, config *core.PrettyPrintConfig, depth int, parentIndentCount int)

func (StatusCode) ToSymbolicValue

func (c StatusCode) ToSymbolicValue(ctx *core.Context, encountered map[uintptr]symbolic.Value) (symbolic.Value, error)

func (StatusCode) WriteJSONRepresentation

func (c StatusCode) WriteJSONRepresentation(ctx *core.Context, w *jsoniter.Stream, config core.JSONSerializationConfig, depth int) error

func (StatusCode) WriteRepresentation

func (StatusCode) WriteRepresentation(ctx *core.Context, w io.Writer, config *core.ReprConfig, depth int) error

type Subscription

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

func (*Subscription) IsStopped

func (s *Subscription) IsStopped() bool

func (*Subscription) StopAsync

func (s *Subscription) StopAsync()

StopAsync causes the server to stop the event stream after all other events have been sent.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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