camo

package
v2.3.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2018 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package camo provides an HTTP proxy server with content type restrictions as well as regex host allow list support.

Index

Examples

Constants

This section is empty.

Variables

View Source
var ValidReqHeaders = map[string]bool{
	"Accept":         true,
	"Accept-Charset": true,

	"Accept-Encoding":   false,
	"Accept-Language":   true,
	"Cache-Control":     true,
	"If-None-Match":     true,
	"If-Modified-Since": true,
	"X-Forwarded-For":   true,
}

ValidReqHeaders are http request headers that are acceptable to pass from the client to the remote server. Only those present and true, are forwarded. Empty implies no filtering.

View Source
var ValidRespHeaders = map[string]bool{

	"Accept-Ranges":    false,
	"Cache-Control":    true,
	"Content-Encoding": true,
	"Content-Type":     true,
	"Etag":             true,
	"Expires":          true,
	"Last-Modified":    true,

	"Server":            false,
	"Transfer-Encoding": true,
}

ValidRespHeaders are http response headers that are acceptable to pass from the remote server to the client. Only those present and true, are forwarded. Empty implies no filtering.

Functions

This section is empty.

Types

type Config

type Config struct {
	// HMACKey is a byte slice to be used as the hmac key
	HMACKey []byte
	// AllowList is a list of string represenstations of regex (not compiled
	// regex) that are used as a whitelist filter. If an AllowList is present,
	// then anything not matching is dropped. If no AllowList is present,
	// no Allow filtering is done.
	AllowList []string
	// Server name used in Headers and Via checks
	ServerName string
	// MaxSize is the maximum valid image size response (in bytes).
	MaxSize int64
	// MaxRedirects is the maximum number of redirects to follow.
	MaxRedirects int
	// Request timeout is a timeout for fetching upstream data.
	RequestTimeout time.Duration
	// Keepalive enable/disable
	DisableKeepAlivesFE bool
	DisableKeepAlivesBE bool
	// Skip verification of a server's certificate chain, and host name
	SkipTLSVerify bool
}

Config holds configuration data used when creating a Proxy with New.

type Proxy

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

A Proxy is a Camo like HTTP proxy, that provides content type restrictions as well as regex host allow list support.

func New

func New(pc Config) (*Proxy, error)

New returns a new Proxy. An error is returned if there was a failure to parse the regex from the passed Config.

func (*Proxy) ServeHTTP

func (p *Proxy) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServerHTTP handles the client request, validates the request is validly HMAC signed, filters based on the Allow list, and then proxies valid requests to the desired endpoint. Responses are filtered for proper image content types.

func (*Proxy) SetMetricsCollector

func (p *Proxy) SetMetricsCollector(pm ProxyMetrics)

SetMetricsCollector sets a proxy metrics (ProxyMetrics interface) for the proxy

type ProxyMetrics

type ProxyMetrics interface {
	AddBytes(bc int64)
	AddServed()
}

ProxyMetrics interface for Proxy to use for stats/metrics. This must be goroutine safe, as AddBytes and AddServed will be called from many goroutines.

Example
package main

import (
	"fmt"
	"os"

	"github.com/arachnys/go-camo/pkg/camo"
	"github.com/arachnys/go-camo/pkg/stats"
)

func main() {
	config := camo.Config{}
	proxy, err := camo.New(config)
	if err != nil {
		fmt.Println("Error: ", err)
		os.Exit(1)
	}

	ps := &stats.ProxyStats{}
	proxy.SetMetricsCollector(ps)
}
Output:

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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