Documentation
¶
Index ¶
- Constants
- Variables
- func AcceptsJSON(r *http.Request) bool
- func BytesReceivedConversion(b int) string
- func CheckUUID(s string) bool
- func Contains(all []string, target string) bool
- func DebugHTTP(r *http.Request, showBody bool) string
- func DebugHTTPDump(l *zerolog.Logger, r *http.Request, showBody bool)
- func DurationSeconds(duration time.Duration) int
- func GenKSUID() string
- func GenRandomString(n int) string
- func GenUUID() string
- func GetIP(r *http.Request) string
- func HTTPDownload(w http.ResponseWriter, description, filename string, filesize int64)
- func HTTPResponse(w http.ResponseWriter, cType string, code int, data interface{})
- func InFutureTime(t time.Time) string
- func Intersect(slice1, slice2 []uint) []uint
- func PastFutureTimes(t time.Time) string
- func PastFutureTimesEpoch(ts int64) string
- func PastTimeAgo(t time.Time) string
- func RandomForNames() string
- func RemoteIP(r *http.Request) string
- func SendRequest(reqType, reqURL string, params io.Reader, headers map[string]string) (int, []byte, error)
- func SetTrustedProxies(cidrs []string)
- func StringToBoolean(s string) bool
- func StringToInteger(s string) int64
- func StringifyTime(seconds int) string
- func TimeTimestamp(t time.Time) string
Constants ¶
const Authorization string = "Authorization"
Authorization for header key
const CacheControl string = "Cache-Control"
CacheControl for header key
const CacheControlMustRevalidate string = "must-revalidate, post-check=0, pre-check=0"
CacheControlMustRevalidate for header key
const Connection string = "Connection"
Connection for header key
const ContentDescription string = "Content-Description"
ContentDescription for header key
const ContentDisposition string = "Content-Disposition"
ContentDisposition for header key
const ContentLength string = "Content-Length"
ContentLength for header key
const ContentTransferEncoding string = "Content-Transfer-Encoding"
ContentTransferEncoding for header key
const ContentType string = "Content-Type"
ContentType for header key
const Expires string = "Expires"
Expires for header key
const JSONApplication string = "application/json"
JSONApplication for Content-Type headers
const JSONApplicationUTF8 string = JSONApplication + "; charset=UTF-8"
JSONApplicationUTF8 for Content-Type headers, UTF charset
const KeepAlive string = "Keep-Alive"
KeepAlive for Connection headers
const OctetStream string = "application/octet-stream"
OctetStream for Content-Type headers
const OsctrlUserAgent string = "osctrl-http-client/1.1"
OsctrlUserAgent for customized User-Agent
const Pragma string = "Pragma"
Pragma for header key
const PragmaPublic string = "public"
PragmaPublic for header key
const TextPlain string = "text/plain"
TextPlain for Content-Type headers
const TextPlainUTF8 string = TextPlain + "; charset=UTF-8"
TextPlainUTF8 for Content-Type headers, UTF charset
const TransferEncodingBinary string = "binary"
TransferEncodingBinary for header key
const UserAgent string = "User-Agent"
UserAgent for header key
const XForwardedFor string = "X-Forwarded-For"
const XRealIP string = "X-Real-IP"
XRealIP for header key
Variables ¶
Functions ¶
func AcceptsJSON ¶ added in v0.5.2
AcceptsJSON reports whether the request's Accept header signals JSON. Used by the auth middleware to choose between 401 JSON (for SPA/XHR clients) and 302 redirect (for browser navigation).
func BytesReceivedConversion ¶
BytesReceivedConversion - Helper to format bytes received into KB, MB, TB... Binary format
func DebugHTTPDump ¶
DebugHTTPDump - Helper for debugging purposes and dump a full HTTP request
func DurationSeconds ¶
DurationSeconds - Helper to get the seconds value fom a Duration
func GenKSUID ¶
func GenKSUID() string
GenKSUID - Helper to generate a KSUID See https://github.com/segmentio/ksuid for more info about KSUIDs
func GenRandomString ¶
GenRandomString - Helper to generate a random string of n characters
func GenUUID ¶
func GenUUID() string
GenUUID - Helper to generate a UUID See https://github.com/google/uuid for more info about UUIDs
func GetIP ¶
GetIP returns the client IP for r. When trusted-proxies are configured AND r.RemoteAddr's IP is inside one of them, the right-most untrusted hop from X-Forwarded-For (or X-Real-IP) is used (per RFC 7239 §5.2 the right-most-untrusted is the IP the trusted edge actually saw connect). Otherwise the forwarding headers are ignored and the connection's RemoteAddr IP is returned.
func HTTPDownload ¶
func HTTPDownload(w http.ResponseWriter, description, filename string, filesize int64)
HTTPDownload - Helper to send HTTP response with a file
func HTTPResponse ¶
func HTTPResponse(w http.ResponseWriter, cType string, code int, data interface{})
HTTPResponse - Helper to send HTTP response
func InFutureTime ¶
InFutureTime - Helper to format future times only returning one value (minute, hour, day)
func PastFutureTimes ¶
PastFutureTimes - Helper to format past or future times
func PastFutureTimesEpoch ¶
PastFutureTimesEpoch - Helper to format past or future times
func PastTimeAgo ¶
PastTimeAgo - Helper to format past times only returning one value (minute, hour, day)
func RandomForNames ¶
func RandomForNames() string
Helper to generate a random MD5 to be used with queries/carves
func RemoteIP ¶ added in v0.5.3
RemoteIP returns the direct connection peer's IP, ignoring every forwarding header. Unlike GetIP, this never trusts X-Forwarded-For or X-Real-IP even when --trusted-proxies is configured.
Use RemoteIP for any key that an attacker could weaponize by rotating header values — chiefly rate-limit bucket keys. A typical edge proxy (nginx, ELB, Cloudflare with default settings) appends to X-Forwarded-For rather than replacing it, so when GetIP walks right-to-left looking for the first untrusted hop it lands on an attacker-controlled value. RemoteIP defeats that bypass by keying on the TCP peer the trusted proxy itself terminates against, which the attacker cannot influence.
Use GetIP for audit-log fields and anything where the operator wants to see the "real" client IP even though it transits a proxy. The trade-off is documented: audit accuracy vs. rate-limit authenticity.
func SendRequest ¶
func SendRequest(reqType, reqURL string, params io.Reader, headers map[string]string) (int, []byte, error)
SendRequest - Helper function to send HTTP requests
func SetTrustedProxies ¶ added in v0.5.2
func SetTrustedProxies(cidrs []string)
SetTrustedProxies configures the CIDR allowlist for forwarding-header trust. Pass an empty slice (or call with no args) to revert to the safe-by-default "ignore forwarding headers" posture. Each CIDR string must parse via net.ParseCIDR; invalid entries are logged and skipped.
func StringToBoolean ¶
StringToBoolean - Helper to convert a string into boolean
func StringToInteger ¶
StringToInteger - Helper to convert a string into integer
func StringifyTime ¶
StringifyTime - Helper to get a string based on the difference of two times
func TimeTimestamp ¶
TimeTimestamp - Helper to format times in timestamp format
Types ¶
This section is empty.