httpserver

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: Apache-2.0, MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package httpserver provides common HTTP server functionality.

Index

Constants

View Source
const (
	// AnnounceEncodingJSON and AnnounceEncodingCBOR are the encoding labels
	// returned by DecodeAnnounceMessage.
	AnnounceEncodingJSON = "json"
	AnnounceEncodingCBOR = "cbor"
)
View Source
const (
	MediaTypeNDJson = "application/x-ndjson"
	MediaTypeJson   = "application/json"
	MediaTypeAny    = "*/*"
)

Variables

This section is empty.

Functions

func AcceptsMediaType added in v0.13.0

func AcceptsMediaType(w http.ResponseWriter, r *http.Request, strict bool, mts ...string) (string, bool)

AcceptsMediaType checks whether the request Accept header matches one of the given media types and returns the first match. When strict is false and Accept is empty, it accepts. On mismatch or invalid Accept, it writes StatusNotAcceptable and returns false.

func DecodeAnnounceMessage added in v0.14.0

func DecodeAnnounceMessage(w http.ResponseWriter, r *http.Request) (message.Message, string, error)

DecodeAnnounceMessage reads an IPNI announce Message from the request body. JSON is used when the Content-Type media type is application/json, including when a charset parameter is present. Any other Content-Type is decoded as CBOR.

func EnableCors added in v0.13.0

func EnableCors(w http.ResponseWriter)

EnableCors sets Access-Control-Allow-Origin to allow any origin.

func HandleError

func HandleError(w http.ResponseWriter, err error, reqType string)

func MethodOK added in v0.5.9

func MethodOK(w http.ResponseWriter, r *http.Request, method string) bool

func WriteJsonResponse

func WriteJsonResponse(w http.ResponseWriter, status int, body []byte)

Types

This section is empty.

Jump to

Keyboard shortcuts

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