proxy

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2023 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package proxy implements a proxy server that forwards http requests with iShare Bearer tokens.

The requests need to provide the extra information in the HTTP headers. The headers are specified as constants.

A typical request requires the headers

X-Ishare-Adapter-Key: some-very-secret-key
X-Ishare-Server-Eori: 00000000001
X-Ishare-Token-Url:   scheme.ishare.net
X-Ishare-Service-Url: http://scheme.ishare.net/capabilities

When a client wants to send a get request to e.g. https://scheme.ishare.net/capabilities, then it needs to provide the parameters in the headers as shown above.

The proxy clones the request except for the headers shown above, and sends it to the url passed in "X-Ishare-Server-Resource".

The server caches the iShare capable clients to limit the token requests.

Index

Constants

View Source
const (
	// HeaderAPIKey is the header for the apiKey
	HeaderAPIKey = "X-Ishare-Adapter-Key"
	// HeaderTokenURL is the header name that must contain the base url of the server.
	// It is used in the iShare Config.
	HeaderTokenURL = "X-Ishare-Token-Url"
	// HeaderServerEORI contains the EORI of the server.
	HeaderServerEORI = "X-Ishare-Server-Eori"
	// HeaderResource contains the resource the client wants to send the request to.
	// This must be a valid url.
	HeaderServiceURL = "X-Ishare-Service-Url"
)

Variables

This section is empty.

Functions

func DecodeContent

func DecodeContent(h http.Header, body []byte) ([]byte, error)

func GUnzip

func GUnzip(d []byte) ([]byte, error)

func HasContentEncoding

func HasContentEncoding(h http.Header, encoding string) bool

func HasContentType

func HasContentType(header http.Header, typeSubtype string) bool

func HeadersKV added in v0.0.8

func HeadersKV(h http.Header) []any

HeadersKV returns key-value pairs for the headers. The name of the key is header.<header name>.<header index>

e.g header "content-encoding: gzip; deflate" produces "header.content-encoding.0", "gzip", "header.content-encoding.1", "deflate"

func IsContentType

func IsContentType(value string, typeSubtype string) bool

IsContentType checks if the value is of cType. According to RFC 1341 the type subtype value is case insensitive.

Types

type Server

type Server struct {
	// handler holds the
	*http.ServeMux
	// contains filtered or unexported fields
}

A Server implements the proxy.

func New

func New(icfg *isharecredentials.Config, apiKey string, log logr.Logger) *Server

New creates a new proxy server.

  • addr is the addres that the proxy will listen on.

  • apiKey, if specified, protects the adapter with an api key that must be specified in the X-Ishare-Adapter-Key header.

  • log specifies the zap sugared logger. Can be nil for no logging.

  • icfg must be an isharecredentials.Config, see below

    icfg is used as a template, the following fields are used:

  • ClientEORI

  • Cert

  • Key

  • CACerts

  • RootCerts

  • TokenBackdate

Jump to

Keyboard shortcuts

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