httputil

package
v1.51.5 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package httputil provides HTTP-related validation utilities and constants.

Index

Constants

View Source
const (
	StatusCodeLength = 3   // Standard length of HTTP status codes (e.g., "200", "404")
	MinStatusCode    = 100 // Minimum valid HTTP status code
	MaxStatusCode    = 599 // Maximum valid HTTP status code
	WildcardChar     = 'X' // Wildcard character used in status code patterns (e.g., "2XX")
)

HTTP Status Code Constants

View Source
const (
	MethodGet     = "get"
	MethodPut     = "put"
	MethodPost    = "post"
	MethodDelete  = "delete"
	MethodOptions = "options"
	MethodHead    = "head"
	MethodPatch   = "patch"
	MethodTrace   = "trace"   // OAS 3.0+ only
	MethodConnect = "connect" // Standard HTTP method, rarely used in APIs
	MethodQuery   = "query"   // OAS 3.2+ only
)

HTTP Method Constants

Variables

View Source
var StandardHTTPStatusCodes = map[string]bool{

	"100": true, "101": true, "102": true, "103": true,

	"200": true, "201": true, "202": true, "203": true, "204": true, "205": true,
	"206": true, "207": true, "208": true, "226": true,

	"300": true, "301": true, "302": true, "303": true, "304": true, "305": true,
	"307": true, "308": true,

	"400": true, "401": true, "402": true, "403": true, "404": true, "405": true,
	"406": true, "407": true, "408": true, "409": true, "410": true, "411": true,
	"412": true, "413": true, "414": true, "415": true, "416": true, "417": true,
	"418": true, "421": true, "422": true, "423": true, "424": true, "425": true,
	"426": true, "428": true, "429": true, "431": true, "451": true,

	"500": true, "501": true, "502": true, "503": true, "504": true, "505": true,
	"506": true, "507": true, "508": true, "510": true, "511": true,
}

StandardHTTPStatusCodes contains RFC 9110 officially defined HTTP status codes. These are used in strict mode validation to warn about non-standard codes.

Functions

func IsStandardStatusCode

func IsStandardStatusCode(code string) bool

IsStandardStatusCode checks if a status code is a well-defined standard HTTP code. Returns true only for codes in StandardHTTPStatusCodes map.

func IsValidMediaType

func IsValidMediaType(mediaType string) bool

IsValidMediaType validates a media type string according to RFC 2045/2046. Handles wildcards (*/* and type/*) and prevents invalid combinations (*/subtype).

func ValidateStatusCode

func ValidateStatusCode(code string) bool

ValidateStatusCode checks if a status code string is valid according to OpenAPI spec. Valid values are:

  • "default" for default response
  • Extension fields starting with "x-"
  • Wildcard patterns: 1XX, 2XX, 3XX, 4XX, 5XX
  • Numeric codes: 100-599

Types

This section is empty.

Jump to

Keyboard shortcuts

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