proxy

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package proxy provides a default function invocation proxy method for OpenFaaS providers.

The function proxy logic is used by the Gateway when `direct_functions` is set to false. This means that the provider will direct call the function and return the results. This involves resolving the function by name and then copying the result into the original HTTP request.

openfaas-provider has implemented a standard HTTP HandlerFunc that will handle setting timeout values, parsing the request path, and copying the request/response correctly.

bootstrapHandlers := bootTypes.FaaSHandlers{
	FunctionProxy:  proxy.NewHandlerFunc(timeout, resolver),
	DeleteHandler:  handlers.MakeDeleteHandler(clientset),
	DeployHandler:  handlers.MakeDeployHandler(clientset),
	FunctionReader: handlers.MakeFunctionReader(clientset),
	ReplicaReader:  handlers.MakeReplicaReader(clientset),
	ReplicaUpdater: handlers.MakeReplicaUpdater(clientset),
	InfoHandler:    handlers.MakeInfoHandler(),
}

proxy.NewHandlerFunc is optional, but does simplify the logic of your provider.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHandlerFunc

func NewHandlerFunc(config types.FaaSConfig, resolver BaseURLResolver, logger hclog.Logger) http.HandlerFunc

NewHandlerFunc creates a standard http.HandlerFunc to proxy function requests. The returned http.HandlerFunc will ensure:

  • proper proxy request timeouts
  • proxy requests for GET, POST, PATCH, PUT, and DELETE
  • path parsing including support for extracing the function name, sub-paths, and query paremeters
  • passing and setting the `X-Forwarded-Host` and `X-Forwarded-For` headers
  • logging errors and proxy request timing to stdout

Note that this will panic if `resolver` is nil.

func NewProxyClient

func NewProxyClient(timeout time.Duration, maxIdleConns int, maxIdleConnsPerHost int) *http.Client

NewProxyClient creates a new http.Client designed for proxying requests, this is exposed as a convenience method for internal or advanced uses. Most people should use NewProxyClientFromConfig.

func NewProxyClientFromConfig

func NewProxyClientFromConfig(config types.FaaSConfig) *http.Client

NewProxyClientFromConfig creates a new http.Client designed for proxying requests and enforcing certain minimum configuration values.

Types

type BaseURLResolver

type BaseURLResolver interface {
	Resolve(functionName string) (url.URL, error)
}

BaseURLResolver URL resolver for proxy requests

The FaaS provider implementation is responsible for providing the resolver function implementation. BaseURLResolver.Resolve will receive the function name and should return the URL of the function service.

Jump to

Keyboard shortcuts

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