http

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2019 License: Apache-2.0 Imports: 12 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

This section is empty.

Types

type BinaryEncoder

type BinaryEncoder struct{}

func (BinaryEncoder) Encode

func (BinaryEncoder) Encode(e ce.Event) (binding.Message, error)

type Message

type Message struct {
	Header   nethttp.Header
	Body     []byte
	OnFinish func(error) error
}

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

func NewBinary

func NewBinary(e ce.Event) (*Message, error)

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 NewStruct

func NewStruct(mediaType string, data []byte) *Message

func (*Message) Event

func (m *Message) Event() (e ce.Event, err error)

func (*Message) Finish

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

func (*Message) Structured

func (m *Message) Structured() (string, []byte)

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(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
}

func NewSender

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

func (*Sender) Send

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

type StructEncoder

type StructEncoder struct{ Format format.Format }

func (StructEncoder) Encode

func (enc StructEncoder) Encode(e ce.Event) (binding.Message, error)

Jump to

Keyboard shortcuts

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