http

package module
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2025 License: MIT Imports: 18 Imported by: 0

README

go-http

Introduction

This is a library implemented in Go (Golang) that provides some functionality to deal with HTTP requests and certain headers.

Usage

Install using go get codeberg.org/THREATINT/go-http.

Quality Values

Use ParseQualityValues() to parse client headers like Accept-Language. (e.g. fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5)

Please see RFC #9110, 12.4.2 Quality Values for details.

ClientIP

ClientIP() returns the client ip address from HTTP headers. It works with X-Forwarded-For (used by most reverse proxies) and is aware of True-Client-IP and CF-Connecting-IP (both implemented by CloudFlare) and others.

ETagMiddleware

ETagMiddleware() adds strong ETag headers to HTTP responses as defined in RFC #9110, 8.3.3 ETag.

MimeType

MimeTypeByExtension() provides a mapping for know file extension to mime type (e.g. .html -> text/html) based on the builtin mime.TypeByExtension and svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types.

Part of the source code for this functionality is generated by GenMimeType.py. (also provided in this repository)

LoadTemplates()

LoadTemplates() recursively loads all templates (*.html) from a given directory.

FileServer

Serves static files, but don't allow directory listings (-> HTTP 404).

Feedback

We would love to hear from you! Please contact us at help@fstpn.eu for feedback and general requests. Kindly raise an issue in Github if you find a problem in the code.

License

Release under the MIT License. (see LICENSE)

QA

Codacy Badge

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientIP

func ClientIP(req *http.Request) (string, error)

ClientIP returns the client's IP address from HTTP headers

func ETagMiddleware

func ETagMiddleware(config *ETagMiddlewareConfig) func(http.Handler) http.Handler

ETagMiddleware middleware to add strong ETags , see https://www.rfc-editor.org/rfc/rfc9110#name-etag for details

func FilterAllowedParams

func FilterAllowedParams(urlParameters url.Values, allowedParams []string) (url.Values, bool)

func LoadTemplates

func LoadTemplates(dir string) (*template.Template, error)

LoadTemplate recursively load all html templates (*.html) from a directory

func MimeTypeByExtension

func MimeTypeByExtension(extension string) string

MimeTypeByExtension (extension) Return matching MimeType for file extension

Types

type ETagMiddlewareConfig

type ETagMiddlewareConfig struct {
	Panic      bool
	Logger     *log.Logger
	IgnoreURLs []string
	// contains filtered or unexported fields
}

type FileServer

type FileServer struct {
	FS http.FileSystem
}

FileServer serve static files, don't allow directory listings

func (FileServer) Open

func (n FileServer) Open(name string) (http.File, error)

type QualityValue

type QualityValue struct {
	Q     float64
	Value string
}

QualityValue represents a values with quality factor, see https://www.rfc-editor.org/rfc/rfc9110.html#name-quality-values

func ParseQualityValues

func ParseQualityValues(header string) ([]QualityValue, error)

ParseQualityValues parses a string containing values and quality factor, see https://www.rfc-editor.org/rfc/rfc9110.html#name-quality-values

Jump to

Keyboard shortcuts

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