protocol

package
v0.0.0-...-2853c3c Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2017 License: Apache-2.0 Imports: 10 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 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(w io.Writer, req *http.Request) 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(w io.Writer, req *http.Request) 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(w io.Writer, req *http.Request) 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(w io.Writer, req *http.Request) error

func (*JSONProtocol) DumpJSON

func (h *JSONProtocol) DumpJSON(req *http.Request) 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