http

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2020 License: Apache-2.0 Imports: 11 Imported by: 2

Documentation

Overview

Package http implements an HTTP CloudEvents binding.

Index

Constants

View Source
const ContentType = "Content-Type"

Variables

This section is empty.

Functions

func EncodeHttpRequest added in v1.1.0

func EncodeHttpRequest(ctx context.Context, m binding.Message, req *http.Request, transformerFactories binding.TransformerFactories) error

Fill the provided req with the message m. Using context you can tweak the encoding processing (more details on binding.Translate documentation).

func EncodeHttpResponse added in v1.1.0

func EncodeHttpResponse(ctx context.Context, m binding.Message, res *http.Response, transformerFactories binding.TransformerFactories) error

Fill the provided res with the message m. Using context you can tweak the encoding processing (more details on binding.Translate documentation).

func NewSender

func NewSender(client *http.Client, target *url.URL, options ...SenderOptionFunc) binding.Sender

Types

type Message

type Message struct {
	Header     nethttp.Header
	BodyReader io.ReadCloser

	OnFinish func(error) error
	// contains filtered or unexported fields
}

Message holds the Header and Body of a HTTP Request or Response.

func NewMessage

func NewMessage(header nethttp.Header, body io.ReadCloser) (*Message, error)

NewMessage returns a Message with header and data from body. Reads and closes body.

func (*Message) Binary added in v0.11.0

func (m *Message) Binary(ctx context.Context, encoder binding.BinaryEncoder) error

func (*Message) Encoding added in v1.1.0

func (m *Message) Encoding() binding.Encoding

func (*Message) Finish

func (m *Message) Finish(err error) error

func (*Message) Structured

func (m *Message) Structured(ctx context.Context, encoder binding.StructuredEncoder) error

type Receiver

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

Receiver for CloudEvents as HTTP requests. Implements http.Handler, To receive messages, associate it with a http.Server.

func NewReceiver

func NewReceiver() *Receiver

NewReceiver creates a receiver

func (*Receiver) Receive

func (r *Receiver) Receive(ctx context.Context) (binding.Message, error)

Receive the next incoming HTTP request as a CloudEvent. Returns non-nil error if the incoming HTTP request fails to parse as a CloudEvent Returns io.EOF if the receiver is closed.

func (*Receiver) ServeHTTP

func (r *Receiver) ServeHTTP(rw http.ResponseWriter, req *http.Request)

ServeHTTP implements http.Handler. Blocks until Message.Finish is called.

type Sender

type Sender struct {
	// Client is the HTTP client used to send events as HTTP requests
	Client *http.Client
	// Target is the URL to send event requests to.
	Target *url.URL
	// contains filtered or unexported fields
}

func (*Sender) Send

func (s *Sender) Send(ctx context.Context, m binding.Message) (err error)

type SenderOptionFunc added in v0.11.0

type SenderOptionFunc func(sender *Sender)

func WithTranscoder added in v0.11.0

func WithTranscoder(factory binding.TransformerFactory) SenderOptionFunc

Jump to

Keyboard shortcuts

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