Documentation
¶
Overview ¶
SPDX-License-Identifier: AGPL-3.0-or-later
SPDX-License-Identifier: AGPL-3.0-or-later
SPDX-License-Identifier: AGPL-3.0-or-later
Index ¶
Constants ¶
const ( // MaxDocumentSize is the maximum document size allowed (50 MB) MaxDocumentSize = 50 * 1024 * 1024 // DialTimeout is the timeout for establishing connection DialTimeout = 10 * time.Second // HeaderTimeout is the timeout for receiving response headers HeaderTimeout = 30 * time.Second // TotalTimeout is the total timeout for the entire request TotalTimeout = 5 * time.Minute // RateLimitPerIP is the rate limit per IP address (60/min) RateLimitPerIP = 60 // RateLimitPerIPDoc is the rate limit per IP+document combination (20/min) RateLimitPerIPDoc = 20 // RateLimitPerDoc is the rate limit per document (300/min) RateLimitPerDoc = 300 // RateLimitWindow is the time window for rate limiting RateLimitWindow = time.Minute )
Configuration constants for the proxy
const ( ErrCodeMIMENotAllowed shared.ErrorCode = "MIME_NOT_ALLOWED" ErrCodeFileTooLarge shared.ErrorCode = "FILE_TOO_LARGE" ErrCodeTimeout shared.ErrorCode = "TIMEOUT" ErrCodeBadGateway shared.ErrorCode = "BAD_GATEWAY" ErrCodeURLMismatch shared.ErrorCode = "URL_MISMATCH" ErrCodeInvalidURL shared.ErrorCode = "INVALID_URL" ErrCodeUpstreamError shared.ErrorCode = "UPSTREAM_ERROR" ErrCodeContentLenMissing shared.ErrorCode = "CONTENT_LENGTH_MISSING" )
ErrorCode constants for proxy-specific errors
Variables ¶
var AllowedMIMETypes = map[string]bool{ "application/pdf": true, "image/png": true, "image/jpeg": true, "image/gif": true, "image/webp": true, "image/svg+xml": true, "text/html": true, "text/markdown": true, "text/plain": true, }
AllowedMIMETypes is the whitelist of allowed MIME types
Functions ¶
func IsAllowedMIMEType ¶
IsAllowedMIMEType checks if a MIME type is allowed
Types ¶
type DocumentGetter ¶
type DocumentGetter interface {
GetByDocID(ctx context.Context, docID string) (*models.Document, error)
}
DocumentGetter defines the interface for getting documents
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler handles proxy requests for streaming external documents
func NewHandler ¶
func NewHandler(documentGetter DocumentGetter) *Handler
NewHandler creates a new proxy handler
func (*Handler) HandleProxy ¶
func (h *Handler) HandleProxy(w http.ResponseWriter, r *http.Request)
HandleProxy handles GET /api/proxy?url={encoded_url}&doc={doc_id}
func (*Handler) SetAllowLocalURLs ¶
SetAllowLocalURLs enables or disables local URL access (for testing only)
type RateLimitResult ¶
type RateLimitResult struct {
Allowed bool
RetryAfter time.Duration
LimitType string // "ip", "ip_doc", or "doc"
}
RateLimitResult contains the result of a rate limit check
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter provides multi-tier rate limiting for the proxy
func NewRateLimiter ¶
func NewRateLimiter(limitPerIP, limitPerIPDoc, limitPerDoc int, window time.Duration) *RateLimiter
NewRateLimiter creates a new multi-tier rate limiter
func (*RateLimiter) Check ¶
func (rl *RateLimiter) Check(ip, docID string) RateLimitResult
Check checks if a request is allowed and records it if so
func (*RateLimiter) Stop ¶
func (rl *RateLimiter) Stop()
Stop stops the rate limiter's cleanup goroutine