protocol

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package protocol defines the IPC message types for communication between the httpcloak daemon and language SDKs (Python, Node.js, etc.)

The daemon reads JSON messages from stdin and writes responses to stdout. Each message is a single JSON object followed by a newline.

Index

Constants

View Source
const (
	ErrCodeTimeout           = "TIMEOUT"
	ErrCodeConnectionRefused = "CONNECTION_REFUSED"
	ErrCodeDNSFailure        = "DNS_FAILURE"
	ErrCodeTLSFailure        = "TLS_FAILURE"
	ErrCodeInvalidURL        = "INVALID_URL"
	ErrCodeInvalidSession    = "INVALID_SESSION"
	ErrCodeInvalidRequest    = "INVALID_REQUEST"
	ErrCodeInternal          = "INTERNAL_ERROR"
)

Common error codes

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthConfig

type AuthConfig struct {
	Type     string `json:"type"`               // "basic", "bearer", "digest"
	Username string `json:"username,omitempty"` // For basic/digest
	Password string `json:"password,omitempty"` // For basic/digest
	Token    string `json:"token,omitempty"`    // For bearer
}

AuthConfig specifies authentication

type Cookie struct {
	Name    string `json:"name"`
	Value   string `json:"value"`
	Domain  string `json:"domain"`
	Path    string `json:"path"`
	Secure  bool   `json:"secure"`
	Expires int64  `json:"expires,omitempty"` // Unix timestamp
}

Cookie represents a single cookie

type CookieAllRequest

type CookieAllRequest struct {
	ID      string      `json:"id"`
	Type    MessageType `json:"type"`
	Session string      `json:"session"`
}

CookieAllRequest gets all cookies for a session

type CookieClearRequest

type CookieClearRequest struct {
	ID      string      `json:"id"`
	Type    MessageType `json:"type"`
	Session string      `json:"session"`
}

CookieClearRequest clears all cookies for a session

type CookieGetRequest

type CookieGetRequest struct {
	ID      string      `json:"id"`
	Type    MessageType `json:"type"`
	Session string      `json:"session"`
	URL     string      `json:"url"` // URL to get cookies for
}

CookieGetRequest gets cookies for a URL

type CookieResponse

type CookieResponse struct {
	ID      string              `json:"id"`
	Type    MessageType         `json:"type"`
	Cookies map[string]string   `json:"cookies,omitempty"` // For simple get (name -> value)
	All     map[string][]Cookie `json:"all,omitempty"`     // For all cookies (domain -> cookies)
	Error   *ErrorInfo          `json:"error,omitempty"`
}

CookieResponse contains cookie data

type CookieSetRequest

type CookieSetRequest struct {
	ID      string      `json:"id"`
	Type    MessageType `json:"type"`
	Session string      `json:"session"`
	URL     string      `json:"url"`               // URL domain for the cookie
	Name    string      `json:"name"`              // Cookie name
	Value   string      `json:"value"`             // Cookie value
	Path    string      `json:"path"`              // Cookie path (optional)
	Domain  string      `json:"domain"`            // Cookie domain (optional)
	Secure  bool        `json:"secure"`            // Secure flag
	Expires int64       `json:"expires,omitempty"` // Unix timestamp (0 = session cookie)
}

CookieSetRequest sets a cookie

type ErrorInfo

type ErrorInfo struct {
	Code    string `json:"code"`              // Error code (e.g., "TIMEOUT", "CONNECTION_REFUSED")
	Message string `json:"message"`           // Human-readable error message
	Details string `json:"details,omitempty"` // Additional details
}

ErrorInfo contains error details

type MessageType

type MessageType string

MessageType represents the type of IPC message

const (
	// Request/Response types
	TypeRequest  MessageType = "request"
	TypeResponse MessageType = "response"

	// Session management
	TypeSessionCreate MessageType = "session.create"
	TypeSessionClose  MessageType = "session.close"
	TypeSessionList   MessageType = "session.list"

	// Cookie management
	TypeCookieGet   MessageType = "cookie.get"
	TypeCookieSet   MessageType = "cookie.set"
	TypeCookieClear MessageType = "cookie.clear"
	TypeCookieAll   MessageType = "cookie.all"

	// Control messages
	TypePing     MessageType = "ping"
	TypePong     MessageType = "pong"
	TypeError    MessageType = "error"
	TypeShutdown MessageType = "shutdown"

	// Info
	TypePresetList MessageType = "preset.list"
)

type PingResponse

type PingResponse struct {
	ID      string      `json:"id"`
	Type    MessageType `json:"type"`
	Version string      `json:"version"`
}

PingResponse responds to ping

type PresetListResponse

type PresetListResponse struct {
	ID      string      `json:"id"`
	Type    MessageType `json:"type"`
	Presets []string    `json:"presets"`
}

PresetListResponse lists available presets

type Request

type Request struct {
	ID      string            `json:"id"`                // Unique request ID for correlation
	Type    MessageType       `json:"type"`              // Message type
	Session string            `json:"session,omitempty"` // Session ID (empty for one-shot requests)
	Method  string            `json:"method,omitempty"`  // HTTP method (GET, POST, etc.)
	URL     string            `json:"url,omitempty"`     // Target URL
	Headers map[string]string `json:"headers,omitempty"` // Custom headers
	Body    string            `json:"body,omitempty"`    // Request body (base64 encoded for binary)
	Options *RequestOptions   `json:"options,omitempty"` // Request options
}

Request represents an incoming IPC request

type RequestOptions

type RequestOptions struct {
	// Timeout in milliseconds (0 = use session/default timeout)
	Timeout int `json:"timeout,omitempty"`

	// Redirect behavior
	FollowRedirects *bool `json:"followRedirects,omitempty"` // nil = use session default
	MaxRedirects    int   `json:"maxRedirects,omitempty"`

	// Protocol forcing
	ForceProtocol string `json:"forceProtocol,omitempty"` // "auto", "h2", "h3"

	// Fetch mode (affects Sec-Fetch-* headers)
	FetchMode string `json:"fetchMode,omitempty"` // "navigate" (default), "cors"
	FetchSite string `json:"fetchSite,omitempty"` // "auto", "none", "same-origin", "same-site", "cross-site"
	Referer   string `json:"referer,omitempty"`   // Referer header

	// Authentication
	Auth *AuthConfig `json:"auth,omitempty"`

	// Query parameters (merged with URL params)
	Params map[string]string `json:"params,omitempty"`

	// Disable retry for this request
	DisableRetry bool `json:"disableRetry,omitempty"`

	// User-Agent override (empty = use preset)
	UserAgent string `json:"userAgent,omitempty"`

	// Body encoding: "text" (default), "base64" (for binary data)
	BodyEncoding string `json:"bodyEncoding,omitempty"`
}

RequestOptions contains optional request configuration

type Response

type Response struct {
	ID       string            `json:"id"`                 // Correlates with request ID
	Type     MessageType       `json:"type"`               // Message type
	Session  string            `json:"session,omitempty"`  // Session ID if applicable
	Status   int               `json:"status,omitempty"`   // HTTP status code
	Headers  map[string]string `json:"headers,omitempty"`  // Response headers
	Body     string            `json:"body,omitempty"`     // Response body
	URL      string            `json:"url,omitempty"`      // Final URL after redirects
	Protocol string            `json:"protocol,omitempty"` // "h2" or "h3"
	Timing   *Timing           `json:"timing,omitempty"`   // Request timing breakdown
	Error    *ErrorInfo        `json:"error,omitempty"`    // Error details if failed

	// Body metadata
	BodyEncoding string `json:"bodyEncoding,omitempty"` // "text" or "base64"
	BodySize     int    `json:"bodySize,omitempty"`     // Original body size in bytes
}

Response represents an outgoing IPC response

func NewErrorResponse

func NewErrorResponse(reqID string, code string, message string) *Response

NewErrorResponse creates an error response

func NewResponse

func NewResponse(reqID string) *Response

NewResponse creates a new response for a request

type SessionCloseRequest

type SessionCloseRequest struct {
	ID      string      `json:"id"`
	Type    MessageType `json:"type"`
	Session string      `json:"session"`
}

SessionCloseRequest closes a session

type SessionConfig

type SessionConfig struct {
	// Browser fingerprint preset (e.g., "chrome-143", "firefox-133")
	Preset string `json:"preset,omitempty"`

	// Base URL for relative paths
	BaseURL string `json:"baseUrl,omitempty"`

	// Proxy URL (http://, https://, socks5://)
	Proxy string `json:"proxy,omitempty"`

	// Default timeout in milliseconds
	Timeout int `json:"timeout,omitempty"`

	// Redirect behavior
	FollowRedirects bool `json:"followRedirects,omitempty"`
	MaxRedirects    int  `json:"maxRedirects,omitempty"`

	// Retry configuration
	RetryEnabled  bool  `json:"retryEnabled,omitempty"`
	MaxRetries    int   `json:"maxRetries,omitempty"`
	RetryWaitMin  int   `json:"retryWaitMin,omitempty"`  // Milliseconds
	RetryWaitMax  int   `json:"retryWaitMax,omitempty"`  // Milliseconds
	RetryOnStatus []int `json:"retryOnStatus,omitempty"` // Status codes to retry

	// TLS options
	InsecureSkipVerify bool `json:"insecureSkipVerify,omitempty"`

	// Connection options
	DisableKeepAlives bool `json:"disableKeepAlives,omitempty"`
	DisableHTTP3      bool `json:"disableHttp3,omitempty"`

	// Default authentication (can be overridden per-request)
	Auth *AuthConfig `json:"auth,omitempty"`
}

SessionConfig contains session configuration

type SessionCreateRequest

type SessionCreateRequest struct {
	ID      string         `json:"id"`
	Type    MessageType    `json:"type"`
	Options *SessionConfig `json:"options,omitempty"`
}

SessionCreateRequest creates a new session with optional configuration

type SessionCreateResponse

type SessionCreateResponse struct {
	ID      string      `json:"id"`
	Type    MessageType `json:"type"`
	Session string      `json:"session"`
	Error   *ErrorInfo  `json:"error,omitempty"`
}

SessionCreateResponse contains the created session info

func NewSessionResponse

func NewSessionResponse(reqID string, sessionID string) *SessionCreateResponse

NewSessionResponse creates a session create response

type SessionListResponse

type SessionListResponse struct {
	ID       string      `json:"id"`
	Type     MessageType `json:"type"`
	Sessions []string    `json:"sessions"`
}

SessionListResponse lists all active sessions

type Timing

type Timing struct {
	DNSLookup    float64 `json:"dnsLookup"`    // DNS lookup time (0 = cached/reused)
	TCPConnect   float64 `json:"tcpConnect"`   // TCP connection time (0 = reused)
	TLSHandshake float64 `json:"tlsHandshake"` // TLS handshake time (0 = reused)
	FirstByte    float64 `json:"firstByte"`    // Time to first response byte
	Total        float64 `json:"total"`        // Total request time
}

Timing contains request timing breakdown in milliseconds

Jump to

Keyboard shortcuts

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