http2stream

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 20, 2016 License: Apache-2.0 Imports: 11 Imported by: 5

README

This package is loosely based on Google's grpc-go project.

Copyright 2014, Google Inc. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Documentation

Overview

Package http2stream provides an implementation of an HTTP/2 server and client that allows piping streams (useful for creating proxies).

Index

Constants

View Source
const PackageName = "http2stream"

PackageName is the name of this package.

Variables

This section is empty.

Functions

This section is empty.

Types

type FilterFun

type FilterFun func(MsgItem) []MsgItem

FilterFun is a function that modifies a message before proxying it.

type HTTP2Client

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

HTTP2Client represents a collection of client HTTP2 connections. The structure manages a connection pool internally.

func NewHTTP2Client

func NewHTTP2Client(
	connectionConnectTimeout time.Duration,
	connectionExpiry time.Duration) (*HTTP2Client, error)

NewHTTP2Client creates a new HTTP2Client.

func (*HTTP2Client) KeepAlive

func (client *HTTP2Client) KeepAlive(addr string)

KeepAlive resets the connection to addr's expiry.

func (*HTTP2Client) NewStream

func (client *HTTP2Client) NewStream(addr string) (*HTTP2Stream, error)

NewStream creates a new HTTP2 stream to the provided server address. Also creates the underlying HTTP2 connection if it doesn't already exist.

type HTTP2Server

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

HTTP2Server represents a HTTP2 server which listens for connections.

func NewHTTP2Server

func NewHTTP2Server() *HTTP2Server

NewHTTP2Server returns a new instance of HTTP2Server.

func (*HTTP2Server) Serve

func (server *HTTP2Server) Serve(
	protocol string, listenAddr string,
	streamHandler StreamHandler) (net.Listener, chan struct{}, error)

Serve listens for connections on provided address.

func (*HTTP2Server) Stop

func (server *HTTP2Server) Stop()

Stop causes the server to close all open connections and exit any serving loops.

type HTTP2Stream

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

HTTP2Stream represents a HTTP2Stream connected to an endpoint (either client or server).

func (*HTTP2Stream) Closed

func (stream *HTTP2Stream) Closed() <-chan struct{}

Closed returns a channel that is closed when the stream is closed.

func (*HTTP2Stream) GetHeaders

func (stream *HTTP2Stream) GetHeaders() map[string][]string

GetHeaders returns the headers received from the client. These are available only to server streams.

func (*HTTP2Stream) GetReceiveBuffer

func (stream *HTTP2Stream) GetReceiveBuffer() *leverutil.UnboundedChannel

GetReceiveBuffer returns the buffer of MsgItem's that can be consumed by a user application to handle messages from the stream.

func (*HTTP2Stream) ProxyTo

func (stream *HTTP2Stream) ProxyTo(
	destStream *HTTP2Stream, filterTo FilterFun, filterFrom FilterFun)

ProxyTo causes the current stream to be proxied to provided destStream.

func (*HTTP2Stream) Write

func (stream *HTTP2Stream) Write(item MsgItem)

Write can be used to send messages on the wire.

type MsgBytes

type MsgBytes struct {
	Data      []byte
	EndStream bool
	// AfterRead needs to be called after the data has been consumed, to signal
	// the peer that it's ok to send more (flow control update window).
	AfterRead func()
}

MsgBytes represents a chunk of data sent / received by a HTTP2Stream on the wire.

type MsgEOF

type MsgEOF struct {
}

MsgEOF represents the end data sent / received by a HTTP2Stream on the wire.

type MsgError

type MsgError struct {
	Err error
}

MsgError represents a transport error of a HTTP2Stream.

type MsgHeaders

type MsgHeaders struct {
	Headers   map[string][]string
	EndStream bool
}

MsgHeaders represents headers sent / received in a HTTP2Stream. Note: This may appear multiple times on a stream.

type MsgItem

type MsgItem interface {
	// contains filtered or unexported methods
}

MsgItem is a message sent / received from a stream (bytes, headers, errors or EOF).

type StreamHandler

type StreamHandler func(stream *HTTP2Stream)

StreamHandler is a function that handles incoming streams.

Jump to

Keyboard shortcuts

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