Documentation
¶
Overview ¶
Package httpserver provides common HTTP server functionality.
Index ¶
- Constants
- func AcceptsMediaType(w http.ResponseWriter, r *http.Request, strict bool, mts ...string) (string, bool)
- func DecodeAnnounceMessage(w http.ResponseWriter, r *http.Request) (message.Message, string, error)
- func EnableCors(w http.ResponseWriter)
- func HandleError(w http.ResponseWriter, err error, reqType string)
- func MethodOK(w http.ResponseWriter, r *http.Request, method string) bool
- func WriteJsonResponse(w http.ResponseWriter, status int, body []byte)
Constants ¶
const ( // AnnounceEncodingJSON and AnnounceEncodingCBOR are the encoding labels // returned by DecodeAnnounceMessage. AnnounceEncodingJSON = "json" AnnounceEncodingCBOR = "cbor" )
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
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 WriteJsonResponse ¶
func WriteJsonResponse(w http.ResponseWriter, status int, body []byte)
Types ¶
This section is empty.