http

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2020 License: Apache-2.0 Imports: 14 Imported by: 3

Documentation

Overview

Package http implements an HTTP CloudEvents binding.

Index

Constants

View Source
const ContentType = "Content-Type"

Variables

This section is empty.

Functions

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
}

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(encoder binding.BinaryEncoder) error

func (*Message) Event

func (m *Message) Event(encoder binding.EventEncoder) error

func (*Message) Finish

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

func (*Message) Structured

func (m *Message) Structured(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 ForceBinary added in v0.11.0

func ForceBinary() SenderOptionFunc

func ForceStructured added in v0.11.0

func ForceStructured() SenderOptionFunc

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