Skip to content

Commit

Permalink
Merge pull request #3 from foomo/http
Browse files Browse the repository at this point in the history
Http
  • Loading branch information
franklinkim authored Sep 23, 2024
2 parents fa78550 + 7745b1e commit 172ac73
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 4 deletions.
5 changes: 2 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,13 @@ linters:
- bodyclose # checks whether HTTP response body is closed successfully [fast: false, auto-fix: false]
- containedctx # containedctx is a linter that detects struct contained context.Context field [fast: false, auto-fix: false]
- contextcheck # check whether the function uses a non-inherited context [fast: false, auto-fix: false]
#- copyloopvar # (go >= 1.22) copyloopvar is a linter detects places where loop variables are copied [fast: true, auto-fix: false]
- copyloopvar # (go >= 1.22) copyloopvar is a linter detects places where loop variables are copied [fast: true, auto-fix: false]
- decorder # check declaration order and count of types, constants, variables and functions [fast: true, auto-fix: false]
- durationcheck # check for two durations multiplied together [fast: false, auto-fix: false]
- errchkjson # Checks types passed to the json encoding functions. Reports unsupported types and reports occations, where the check for the returned error can be omitted. [fast: false, auto-fix: false]
- errname # Checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`. [fast: false, auto-fix: false]
- errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13. [fast: false, auto-fix: false]
- exhaustive # check exhaustiveness of enum switch statements [fast: false, auto-fix: false]
- exportloopref # checks for pointers to enclosing loop variables [fast: false, auto-fix: false]
- forbidigo # Forbids identifiers [fast: false, auto-fix: false]
- forcetypeassert # finds forced type assertions [fast: true, auto-fix: false]
- gocheckcompilerdirectives # Checks that go compiler directive comments (//go:) are valid. [fast: true, auto-fix: false]
Expand All @@ -109,7 +108,7 @@ linters:
- grouper # Analyze expression groups. [fast: true, auto-fix: false]
- importas # Enforces consistent import aliases [fast: false, auto-fix: false]
- inamedparam # reports interfaces with unnamed method parameters [fast: true, auto-fix: false]
#- intrange # (go >= 1.22) intrange is a linter to find places where for loops could make use of an integer range. [fast: true, auto-fix: false]
- intrange # (go >= 1.22) intrange is a linter to find places where for loops could make use of an integer range. [fast: true, auto-fix: false]
- loggercheck # (logrlint) Checks key value pairs for common logger libraries (kitlog,klog,logr,zap). [fast: false, auto-fix: false]
- makezero # Finds slice declarations with non-zero initial length [fast: false, auto-fix: false]
- misspell # Finds commonly misspelled English words [fast: true, auto-fix: true]
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/foomo/gostandards

go 1.21
go 1.22

require github.com/stretchr/testify v1.9.0

Expand Down
25 changes: 25 additions & 0 deletions http/authprefix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package http

type AuthPrefix string

const (
AuthPrefixBasic AuthPrefix = "Basic" // Basic Authentication
AuthPrefixBearer AuthPrefix = "Bearer" // Bearer Token Authentication (commonly used with OAuth 2.0 and JWT)
AuthPrefixDigest AuthPrefix = "Digest" // Digest Authentication
AuthPrefixHOBA AuthPrefix = "HOBA" // HTTP Origin-Bound Authentication
AuthPrefixMutual AuthPrefix = "Mutual" // Mutual Authentication (used with TLS)
AuthPrefixAWS4HMAC AuthPrefix = "AWS4-HMAC-SHA256" // AWS Signature Version 4
AuthPrefixNTLM AuthPrefix = "NTLM" // NT LAN Manager (Microsoft's proprietary authentication protocol)
AuthPrefixNegotiate AuthPrefix = "Negotiate" // SPNEGO-based Kerberos and NTLM Authentication
AuthPrefixOAuth AuthPrefix = "OAuth" // OAuth 1.0 Authentication
AuthPrefixSCRAMSHA256 AuthPrefix = "SCRAM-SHA-256" // Salted Challenge Response Authentication Mechanism (SCRAM)
AuthPrefixAPIKey AuthPrefix = "ApiKey" // Custom API key-based authentication
)

func (p AuthPrefix) String() string {
return string(p)
}

func (p AuthPrefix) Set(value string) string {
return p.String() + " " + value
}
15 changes: 15 additions & 0 deletions http/encoding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package http

type Encoding string

const (
EncodingGzip Encoding = "gzip" // Gzip compression
EncodingDeflate Encoding = "deflate" // Deflate compression
EncodingBr Encoding = "br" // Brotli compression
EncodingIdentity Encoding = "identity" // No transformation or compression
EncodingCompress Encoding = "compress" // Deprecated Unix 'compress' algorithm
)

func (e Encoding) String() string {
return string(e)
}
145 changes: 145 additions & 0 deletions http/header.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package http

import (
"net/http"
)

type Header string

const (
HeaderAIM Header = "A-IM"
HeaderAccept Header = "Accept"
HeaderAcceptCharset Header = "Accept-Charset"
HeaderAcceptDatetime Header = "Accept-Datetime"
HeaderAcceptEncoding Header = "Accept-Encoding"
HeaderAcceptLanguage Header = "Accept-Language"
HeaderAcceptPatch Header = "Accept-Patch"
HeaderAcceptRanges Header = "Accept-Ranges"
HeaderAccessControlAllowCredentials Header = "Access-Control-Allow-Credentials"
HeaderAccessControlAllowHeaders Header = "Access-Control-Allow-Headers"
HeaderAccessControlAllowMethods Header = "Access-Control-Allow-Methods"
HeaderAccessControlAllowOrigin Header = "Access-Control-Allow-Origin"
HeaderAccessControlExposeHeaders Header = "Access-Control-Expose-Headers"
HeaderAccessControlMaxAge Header = "Access-Control-Max-Age"
HeaderAccessControlRequestHeaders Header = "Access-Control-Request-Headers"
HeaderAccessControlRequestMethod Header = "Access-Control-Request-Method"
HeaderAge Header = "Age"
HeaderAllow Header = "Allow"
HeaderAltSvc Header = "Alt-Svc"
HeaderAuthorization Header = "Authorization"
HeaderBaggage Header = "Baggage" // W3C Baggage header for passing contextual information
HeaderCFAuthorization Header = "CF-Authorization" // Used for Cloudflare Access (for securing endpoints)
HeaderCFBypass Header = "CF-Bypass" // Bypass rules for Cloudflare Access or other services
HeaderCFCacheStatus Header = "CF-Cache-Status" // Cache status (HIT, MISS, EXPIRED, etc.)
HeaderCFConnectingIP Header = "CF-Connecting-IP" // Original client IP address as seen by Cloudflare
HeaderCFIPCountry Header = "CF-IPCountry" // Country of the requester's IP address
HeaderCFRailgun Header = "CF-Railgun" // Railgun performance information (used in Cloudflare Railgun optimization)
HeaderCFRay Header = "CF-RAY" // Unique request ID (used for tracing through Cloudflare's network)
HeaderCFRequestID Header = "CF-Request-ID" // Unique ID for the request for tracking purposes
HeaderCFRocketLoader Header = "CF-Rocket-Loader" // Related to Cloudflare's Rocket Loader optimization
HeaderCFVisitor Header = "CF-Visitor" // Information about the protocol (HTTP/HTTPS) used by the visitor
HeaderCFWorker Header = "CF-Worker" // Header set by Cloudflare Workers
HeaderCacheControl Header = "Cache-Control"
HeaderConnection Header = "Connection"
HeaderContentDisposition Header = "Content-Disposition"
HeaderContentEncoding Header = "Content-Encoding"
HeaderContentLanguage Header = "Content-Language"
HeaderContentLength Header = "Content-Length"
HeaderContentLocation Header = "Content-Location"
HeaderContentMD5 Header = "Content-MD5"
HeaderContentRange Header = "Content-Range"
HeaderContentSecurityPolicy Header = "Content-Security-Policy"
HeaderContentSecurityPolicyReportOnly Header = "Content-Security-Policy-Report-Only"
HeaderContentType Header = "Content-Type"
HeaderCookie Header = "Cookie"
HeaderDAV Header = "DAV"
HeaderDate Header = "Date"
HeaderDepth Header = "Depth"
HeaderDestination Header = "Destination"
HeaderETag Header = "ETag"
HeaderExpect Header = "Expect"
HeaderExpires Header = "Expires"
HeaderForwarded Header = "Forwarded"
HeaderFrom Header = "From"
HeaderHost Header = "Host"
HeaderIf Header = "If"
HeaderIfMatch Header = "If-Match"
HeaderIfModifiedSince Header = "If-Modified-Since"
HeaderIfNoneMatch Header = "If-None-Match"
HeaderIfRange Header = "If-Range"
HeaderIfUnmodifiedSince Header = "If-Unmodified-Since"
HeaderLastModified Header = "Last-Modified"
HeaderLink Header = "Link"
HeaderLocation Header = "Location"
HeaderLockToken Header = "Lock-Token"
HeaderMaxForwards Header = "Max-Forwards"
HeaderOrigin Header = "Origin"
HeaderP3P Header = "P3P"
HeaderPragma Header = "Pragma"
HeaderProxyAuthenticate Header = "Proxy-Authenticate"
HeaderProxyAuthorization Header = "Proxy-Authorization"
HeaderPublicKeyPins Header = "Public-Key-Pins"
HeaderRange Header = "Range"
HeaderReferer Header = "Referer"
HeaderReferrerPolicy Header = "Referrer-Policy"
HeaderRetryAfter Header = "Retry-After"
HeaderServer Header = "Server"
HeaderSetCookie Header = "Set-Cookie"
HeaderStrictTransportSecurity Header = "Strict-Transport-Security"
HeaderTE Header = "TE"
HeaderTimeout Header = "Timeout"
HeaderTk Header = "Tk"
HeaderTraceParent Header = "traceparent" // W3C Trace Context header for trace propagation
HeaderTraceState Header = "tracestate" // W3C Trace Context header for vendor-specific trace information
HeaderTrailer Header = "Trailer"
HeaderTransferEncoding Header = "Transfer-Encoding"
HeaderUpgrade Header = "Upgrade"
HeaderUpgradeInsecureRequests Header = "Upgrade-Insecure-Requests"
HeaderUserAgent Header = "User-Agent"
HeaderVary Header = "Vary"
HeaderVia Header = "Via"
HeaderWWWAuthenticate Header = "WWW-Authenticate"
HeaderWarning Header = "Warning"
HeaderXAccelRedirect Header = "X-Accel-Redirect" // Internal redirect by reverse proxy (e.g., Nginx)
HeaderXAmznTraceID Header = "X-Amzn-Trace-Id" // AWS X-Ray trace header
HeaderXB3Flags Header = "X-B3-Flags" // B3 Debug flag
HeaderXB3ParentSpanID Header = "X-B3-ParentSpanId" // B3 Parent Span ID used for distributed tracing
HeaderXB3Sampled Header = "X-B3-Sampled" // B3 Sampling flag (whether or not the request is sampled)
HeaderXB3SpanID Header = "X-B3-SpanId" // B3 Span ID used for distributed tracing
HeaderXB3TraceID Header = "X-B3-TraceId" // B3 Trace ID used for distributed tracing
HeaderXCSRFToken Header = "X-CSRF-Token"
HeaderXCache Header = "X-Cache" // Cache status of the request (e.g., HIT or MISS)
HeaderXCloudTraceContext Header = "X-Cloud-Trace-Context" // Google Cloud Trace context header
HeaderXContentDuration Header = "X-Content-Duration" // Duration of the content (e.g., media file)
HeaderXContentTypeOptions Header = "X-Content-Type-Options"
HeaderXCorrelationID Header = "X-Correlation-ID" // Correlation ID for tracing requests
HeaderXDNSPrefetchControl Header = "X-DNS-Prefetch-Control" //
HeaderXDownloadOptions Header = "X-Download-Options" // Prevents file download behavior in IE
HeaderXForwardedFor Header = "X-Forwarded-For" // Original client IP behind proxy
HeaderXForwardedHost Header = "X-Forwarded-Host" // Original host requested by the client
HeaderXForwardedProto Header = "X-Forwarded-Proto" // Original protocol (HTTP or HTTPS) used by the client
HeaderXFrameOptions Header = "X-Frame-Options"
HeaderXOTSpanContext Header = "X-OT-Span-Context" // OpenTracing Span Context (legacy, pre-OpenTelemetry)
HeaderXPermittedCrossDomainPolicies Header = "X-Permitted-Cross-Domain-Policies" // Adobe Flash Player policy control
HeaderXPoweredBy Header = "X-Powered-By" //
HeaderXRateLimitLimit Header = "X-RateLimit-Limit" // Limit for the number of requests in a given time
HeaderXRateLimitRemaining Header = "X-RateLimit-Remaining" // Number of remaining requests in the current rate limit window
HeaderXRateLimitReset Header = "X-RateLimit-Reset" // Time at which the rate limit resets
HeaderXRealIP Header = "X-Real-IP" // The original client IP address
HeaderXRequestID Header = "X-Request-ID" // Unique request ID for tracing
HeaderXRobotsTag Header = "X-Robots-Tag" // Search engine control
HeaderXUACompatible Header = "X-UA-Compatible" // Compatibility mode for Internet Explorer
HeaderXXSSProtection Header = "X-XSS-Protection"
)

func (h Header) String() string {
return string(h)
}

func (h Header) Add(header http.Header, value string) {
header.Add(h.String(), value)
}

func (h Header) Get(header http.Header) string {
return header.Get(h.String())
}

0 comments on commit 172ac73

Please sign in to comment.