http

package
v0.0.0-...-045890f Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2019 License: Apache-2.0 Imports: 31 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ContentTypeJSON  = "application/json"
	ContentTypeProto = "application/octet-stream"
)
View Source
const (
	//IgnoreNR is the option flag to ignore newrelic for this method
	IgnoreNR = "IGNORE_NR"
)

Variables

View Source
var (
	//ContentTypeMap is the mapping of content-type with marshaling type
	ContentTypeMap = map[string]string{
		ContentTypeJSON:                   modifiers.JSON,
		"application/jsonpb":              modifiers.JSONPB,
		"application/x-jsonpb":            modifiers.JSONPB,
		"application/protobuf":            modifiers.ProtoBuf,
		"application/proto":               modifiers.ProtoBuf,
		"application/x-proto":             modifiers.ProtoBuf,
		"application/vnd.google.protobuf": modifiers.ProtoBuf,
		ContentTypeProto:                  modifiers.ProtoBuf,
	}

	// DefaultHTTPResponseHeaders are response headers that are whitelisted by default
	DefaultHTTPResponseHeaders = []string{
		"Content-Type",
	}
)

Functions

func AcceptTypeFromHeaders

func AcceptTypeFromHeaders(ctx context.Context) string

AcceptTypeFromHeaders searches for a mathing accept type

func ContentTypeFromHeaders

func ContentTypeFromHeaders(ctx context.Context) string

ContentTypeFromHeaders searches for a matching content type

func DefaultEncoder

func DefaultEncoder(req *http.Request, r interface{}) error

DefaultEncoder encodes a HTTP request if none are registered. This encoder populates the proto message with URL route variables or fields from a JSON body if either are available.

func DefaultWSUpgrader

func DefaultWSUpgrader(w http.ResponseWriter, r *http.Request, responseHeader http.Header) (*websocket.Conn, error)

DefaultWSUpgrader upgrades a websocket if none are registered.

func GrpcErrorToHTTP

func GrpcErrorToHTTP(err error, defaultStatus int, defaultMessage string) (int, string)

GrpcErrorToHTTP converts gRPC error code into HTTP response status code. See: https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto

func NewHTTPHandler

func NewHTTPHandler(config Config) handlers.Handler

NewHTTPHandler creates a new HTTP handler

Types

type Config

type Config struct {
	handlers.CommonConfig
	EnableProtoURL bool
}

Config is the configuration for HTTP Handler

Jump to

Keyboard shortcuts

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