protocol

package
v0.0.0-...-c4ccf5f Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2018 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DumpRequestTo

func DumpRequestTo(w io.Writer, req *http.Request) error

DumpRequestTo is httputil.DumpRequest with some modifications. It will dump the request to the provided io.Writer with the body always, consuming the body in the process.

TODO we should support h2!

func IsStreamable

func IsStreamable(p Protocol) bool

IsStreamable says whether the given protocol can be used for streaming into hot functions.

Types

type CallInfo

type CallInfo interface {
	CallID() string
	ContentType() string
	Input() io.Reader

	// ProtocolType let's function/fdk's know what type original request is. Only 'http' for now.
	// This could be abstracted into separate Protocol objects for each type and all the following information could go in there.
	// This is a bit confusing because we also have the protocol's for getting information in and out of the function containers.
	ProtocolType() string
	Request() *http.Request
	RequestURL() string
	Headers() map[string][]string
}

CallInfo is passed into dispatch with only the required data the protocols require

func NewCallInfo

func NewCallInfo(call *models.Call, req *http.Request) CallInfo

type CallRequestHTTP

type CallRequestHTTP struct {
	Type       string      `json:"type"`
	RequestURL string      `json:"request_url"`
	Headers    http.Header `json:"headers"`
}

CallRequestHTTP for the protocol that was used by the end user to call this function. We only have HTTP right now.

type CallResponseHTTP

type CallResponseHTTP struct {
	StatusCode int         `json:"status_code,omitempty"`
	Headers    http.Header `json:"headers,omitempty"`
}

CallResponseHTTP for the protocol that was used by the end user to call this function. We only have HTTP right now.

type ContainerIO

type ContainerIO interface {
	IsStreamable() bool

	// Dispatch will handle sending stdin and stdout to a container. Implementers
	// of Dispatch may format the input and output differently. Dispatch must respect
	// the req.Context() timeout / cancellation.
	Dispatch(ctx context.Context, ci CallInfo, w io.Writer) error
}

ContainerIO defines the interface used to talk to a hot function. Internally, a protocol must know when to alternate between stdin and stdout. It returns any protocol error, if present.

func New

func New(p Protocol, in io.Writer, out io.Reader) ContainerIO

New creates a valid protocol handler from a I/O pipe representing containers stdin/stdout.

type DefaultProtocol

type DefaultProtocol struct{}

DefaultProtocol is the protocol used by cold-containers

func (*DefaultProtocol) Dispatch

func (d *DefaultProtocol) Dispatch(ctx context.Context, ci CallInfo, w io.Writer) error

func (*DefaultProtocol) IsStreamable

func (p *DefaultProtocol) IsStreamable() bool

type HTTPProtocol

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

HTTPProtocol converts stdin/stdout streams into HTTP/1.1 compliant communication. It relies on Content-Length to know when to stop reading from containers stdout. It also mandates valid HTTP headers back and forth, thus returning errors in case of parsing problems.

func (*HTTPProtocol) Dispatch

func (h *HTTPProtocol) Dispatch(ctx context.Context, ci CallInfo, w io.Writer) error

this is just an http.Handler really TODO handle req.Context better with io.Copy. io.Copy could push us over the timeout. TODO maybe we should take io.Writer, io.Reader but then we have to dump the request to a buffer again :(

func (*HTTPProtocol) IsStreamable

func (p *HTTPProtocol) IsStreamable() bool

type JSONProtocol

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

JSONProtocol converts stdin/stdout streams from HTTP into JSON format.

func (*JSONProtocol) Dispatch

func (h *JSONProtocol) Dispatch(ctx context.Context, ci CallInfo, w io.Writer) error

func (*JSONProtocol) IsStreamable

func (p *JSONProtocol) IsStreamable() bool

type Protocol

type Protocol string

Protocol defines all protocols that operates a ContainerIO.

const (
	Default Protocol = models.FormatDefault
	HTTP    Protocol = models.FormatHTTP
	JSON    Protocol = models.FormatJSON
	Empty   Protocol = ""
)

hot function protocols

func (Protocol) MarshalJSON

func (p Protocol) MarshalJSON() ([]byte, error)

func (*Protocol) UnmarshalJSON

func (p *Protocol) UnmarshalJSON(b []byte) error

Jump to

Keyboard shortcuts

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