http

package
v0.1.15 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2023 License: MPL-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package http provides an HTTP interface allowing HTTP clients to interact with otf.

Index

Constants

View Source
const (
	ModuleV1Prefix = "/v1/modules/"
	APIPrefixV2    = "/api/v2/"
)

Variables

View Source
var Encoder = schema.NewEncoder()

Encoder for encoding structs into queries: caches structs, and safe for sharing

View Source
var InsecureTransport http.RoundTripper

Functions

func APIRouter

func APIRouter(r *mux.Router) *mux.Router

APIRouter wraps the given router with a router suitable for API routes.

func Absolute

func Absolute(r *http.Request, path string) string

Absolute returns an absolute URL for the given path. It uses the http request to determine the correct hostname and scheme to use. Handles situations where otf is sitting behind a reverse proxy, using the X-Forwarded-* headers the proxy sets.

func ExternalHost

func ExternalHost(r *http.Request) string

ExternalHost uses the incoming HTTP request to determine the host:port on which this server can be reached externally by clients and the internet.

func GetClientIP

func GetClientIP(r *http.Request) (string, error)

GetClientIP gets the client's IP address

func SanitizeAddress

func SanitizeAddress(address string) (string, error)

SanitizeAddress ensures address is in format https://<host>:<port>

func SanitizeHostname

func SanitizeHostname(hostname string) (string, error)

SanitizeHostname ensures hostname is in the format <host>:<port>

Types

type Server

type Server struct {
	logr.Logger
	ServerConfig
	// contains filtered or unexported fields
}

Server is the http server for OTF

func NewServer

func NewServer(logger logr.Logger, cfg ServerConfig) (*Server, error)

NewServer constructs the http server for OTF

func (*Server) Start

func (s *Server) Start(ctx context.Context, ln net.Listener) (err error)

Start starts serving http traffic on the given listener and waits until the server exits due to error or the context is cancelled.

type ServerConfig

type ServerConfig struct {
	SSL                  bool
	CertFile, KeyFile    string
	EnableRequestLogging bool
	DevMode              bool

	Handlers   []internal.Handlers
	Middleware []mux.MiddlewareFunc
}

ServerConfig is the http server config

Directories

Path Synopsis
Package decode contains decoders for various HTTP artefacts
Package decode contains decoders for various HTTP artefacts
Package html contains code relating specifically to the web UI.
Package html contains code relating specifically to the web UI.
paths
Package paths provides rails-style path helpers for use with the web app.
Package paths provides rails-style path helpers for use with the web app.

Jump to

Keyboard shortcuts

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