### Initialize HTTP server with GraphQL handler Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/api-reference.md Example showing how to configure the Resolver and start an HTTP server using the Hetty API handler. ```go resolver := &api.Resolver{ ProjectService: projSvc, RequestLogService: reqLogSvc, InterceptService: interceptSvc, SenderService: senderSvc, } handler := api.HTTPHandler(resolver, "/api/graphql/") httpServer := &http.Server{ Addr: ":8080", Handler: handler, } httpServer.ListenAndServe() ``` -------------------------------- ### Install Hetty on Windows Source: https://github.com/dstotijn/hetty/blob/main/README.md Use the Scoop package manager to install Hetty on Windows. ```sh scoop bucket add hettysoft https://github.com/hettysoft/scoop-bucket.git scoop install hettysoft/hetty ``` -------------------------------- ### Install Hetty on Linux Source: https://github.com/dstotijn/hetty/blob/main/README.md Use snap to install the Hetty package on Linux distributions. ```sh sudo snap install hetty ``` -------------------------------- ### Start Hetty Source: https://github.com/dstotijn/hetty/blob/main/README.md Launch the Hetty server using the default configuration. ```sh hetty ``` -------------------------------- ### Initialize and Start Proxy Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/proxy.md Create a new proxy instance using a CA certificate and key, then assign it to an HTTP server. ```go caCert, caKey, _ := proxy.LoadOrCreateCA(keyPath, certPath) p, _ := proxy.NewProxy(proxy.Config{ CACert: caCert, CAKey: caKey, Logger: logger, }) httpServer := &http.Server{Handler: p} httpServer.ListenAndServe() ``` -------------------------------- ### Install Hetty on macOS Source: https://github.com/dstotijn/hetty/blob/main/README.md Use Homebrew to install the Hetty binary on macOS systems. ```sh brew install hettysoft/tap/hetty ``` -------------------------------- ### Example usage of Rule.Match Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/scope.md Demonstrates configuring a rule with URL and header regexes and checking for a match. ```go rule := scope.Rule{ URL: regexp.MustCompile(".*api\\.example\\.com.*"), Header: scope.Header{ Key: regexp.MustCompile("Authorization"), Value: regexp.MustCompile("Bearer.*"), }, } matches := rule.Match(req, body) // True if URL contains api.example.com // OR if Authorization header has Bearer token ``` -------------------------------- ### Configure Scope Rules Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/scope.md Examples of defining scope rules to match specific header keys, values, or both. ```go // Match any Authorization header rule1 := scope.Rule{ Header: scope.Header{ Key: regexp.MustCompile("Authorization"), }, } // Match Bearer tokens rule2 := scope.Rule{ Header: scope.Header{ Value: regexp.MustCompile("Bearer.*"), }, } // Match Authorization: Bearer * rule3 := scope.Rule{ Header: scope.Header{ Key: regexp.MustCompile("Authorization"), Value: regexp.MustCompile("Bearer.*"), }, } ``` -------------------------------- ### Usage of LoadOrCreateCA Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/proxy.md Example of loading or creating a CA certificate from specified file paths. ```go caCert, caKey, err := proxy.LoadOrCreateCA( "/home/user/.hetty/hetty_key.pem", "/home/user/.hetty/hetty_cert.pem", ) if err != nil { log.Fatal(err) } ``` -------------------------------- ### activeProject Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/endpoints.md Get the currently open project. ```APIDOC ## Query activeProject ### Description Get the currently open project. ### Response - **Project | null** - Returns null if no project is open. ``` -------------------------------- ### Apply Request Filter Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/sender.md Example of configuring a filter to search for requests with a specific HTTP method using an infix expression. ```go svc.SetFilter(sender.FindRequestsFilter{ ProjectID: projID, OnlyInScope: true, SearchExpr: filter.InfixExpression{ Left: filter.StringLiteral{Value: "method"}, Operator: filter.TokOpEq, Right: filter.StringLiteral{Value: "POST"}, }, }) ``` -------------------------------- ### Filter Expression Syntax Examples Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/filter.md Examples of various filter expressions including equality, regex matching, numeric comparisons, and logical operators. ```text method == GET status == 200 ``` ```text status != 200 method != POST ``` ```text url =~ /example\.com/ body =~ /api.*endpoint/ ``` ```text url !~ /internal/ body !~ /password/ ``` ```text status >= 400 status < 300 ``` ```text method == POST AND status >= 400 method == GET OR method == HEAD (method == POST OR method == PUT) AND status == 200 ``` ```text (method == GET OR method == HEAD) AND status >= 400 AND url =~ /api/ ``` -------------------------------- ### Database Transaction Execution Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/database.md Example of performing a write operation using an internal transaction. ```go // Internal transaction (automatic) err := db.StoreSenderRequest(ctx, request) if err != nil { log.Fatal(err) } ``` -------------------------------- ### Query.scope Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/api-reference.md Get active project scope rules. ```APIDOC ## Query.scope ### Description Get active project scope rules. ### Returns - `[]ScopeRule` (Array of scope rules) ``` -------------------------------- ### Implement RequestModifier middleware Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/proxy.md Example implementation of a request modification middleware function. ```go func (svc *Service) RequestModifier(next proxy.RequestModifyFunc) proxy.RequestModifyFunc { return func(req *http.Request) { // Modify req before passing to next handler next(req) } } ``` -------------------------------- ### Regexp GraphQL Scalar Example Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/api-reference.md Demonstrates the usage of the Regexp scalar type in a GraphQL mutation. ```graphql mutation { setScope(scope: [ { url: ".*example\\.com.*" # Regexp scalar } ]) } ``` -------------------------------- ### URL GraphQL Scalar Example Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/api-reference.md Demonstrates the usage of the URL scalar type in a GraphQL query. ```graphql { httpRequestLog(id: "01ARZ3NDEKTSV4RRFFQ69G5FAV") { url # URL scalar } } ``` -------------------------------- ### Install CA certificate in system trust stores Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/configuration.md Commands to add the generated CA certificate to macOS and Linux system trust stores for MITM interception. ```bash sudo security add-trusted-cert -d -r trustRoot \ -k /Library/Keychains/System.keychain \ ~/.hetty/hetty_cert.pem ``` ```bash sudo cp ~/.hetty/hetty_cert.pem /usr/local/share/ca-certificates/ sudo update-ca-certificates ``` -------------------------------- ### Get active project Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/endpoints.md Retrieves the currently open project and its interception settings. Returns null if no project is active. ```graphql query { activeProject { id name isActive settings { intercept { requestsEnabled responsesEnabled requestFilter responseFilter } } } } ``` -------------------------------- ### Initialize Proxy and Retrieve Logs Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/README.md Demonstrates package-qualified initialization of the proxy and retrieval of request logs. ```go // From pkg/proxy p, _ := proxy.NewProxy(config) // From pkg/reqlog logs, _ := reqlog.Service.FindRequests(ctx) ``` -------------------------------- ### Initialize Project Service Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/project.md Instantiate the project service by providing the required database repository and sub-service dependencies. ```go projSvc, err := proj.NewService(proj.Config{ Repository: boltDB, InterceptService: interceptSvc, ReqLogService: reqLogSvc, SenderService: senderSvc, Scope: scope, }) ``` -------------------------------- ### Filter Expression Example Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/README.md Example of a filter expression used for searching requests based on method and status. ```text method == POST AND status >= 400 ``` -------------------------------- ### Open Existing Project Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/project.md Switch the active project context. This updates all sub-services and loads project-specific settings from the database. ```go project, err := projSvc.OpenProject(ctx, projectID) if err != nil { if errors.Is(err, proj.ErrProjectNotFound) { log.Println("Project not found") } return } log.Printf("Opened project: %s\n", project.Name) ``` -------------------------------- ### scope Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/endpoints.md Get current scope rules. ```APIDOC ## Query scope ### Description Get current scope rules. ### Response - **[ScopeRule!]!** - Array of active scope rules, empty array if no rules are set. ``` -------------------------------- ### Create and Open Project Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/project.md Workflow for creating a new project and setting it as the active project. ```go // Create project project, err := projSvc.CreateProject(ctx, "Security Audit") if err != nil { log.Fatal(err) } // Open it _, err = projSvc.OpenProject(ctx, project.ID) if err != nil { log.Fatal(err) } // Now all services work with this project ``` -------------------------------- ### View Hetty Help Source: https://github.com/dstotijn/hetty/blob/main/README.md Display the command-line interface help text and available options. ```sh $ hetty --help Usage: hetty [flags] [subcommand] [flags] Runs an HTTP server with (MITM) proxy, GraphQL service, and a web based admin interface. Options: --cert Path to root CA certificate. Creates file if it doesn't exist. (Default: "~/.hetty/hetty_cert.pem") --key Path to root CA private key. Creates file if it doesn't exist. (Default: "~/.hetty/hetty_key.pem") --db Database file path. Creates file if it doesn't exist. (Default: "~/.hetty/hetty.db") --addr TCP address for HTTP server to listen on, in the form "host:port". (Default: ":8080") --chrome Launch Chrome with proxy settings applied and certificate errors ignored. (Default: false) --verbose Enable verbose logging. --json Encode logs as JSON, instead of pretty/human readable output. --version, -v Output version. --help, -h Output this usage text. Subcommands: - cert Certificate management Run `hetty --help` for subcommand specific usage instructions. Visit https://hetty.xyz to learn more about Hetty. ``` -------------------------------- ### Query.httpRequestLogFilter Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/api-reference.md Get current HTTP request log filter. ```APIDOC ## Query.httpRequestLogFilter ### Description Get current HTTP request log filter. ### Returns - `HTTPRequestLogFilter` (The filter object) ### Fields - **onlyInScope** (bool) - **searchExpression** (string) - Optional ``` -------------------------------- ### httpRequestLogFilter Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/endpoints.md Get the current filter settings for HTTP request logs. ```APIDOC ## Query httpRequestLogFilter ### Description Get the current filter settings for HTTP request logs. ### Response - **HttpRequestLogFilter | null** ``` -------------------------------- ### Initialize Request Logging Service Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/reqlog.md Instantiate a new service using the required configuration parameters. ```go reqLogSvc := reqlog.NewService(reqlog.Config{ ActiveProjectID: projectID, Scope: scope, Repository: boltDB, Logger: logger, }) ``` -------------------------------- ### Initialize Sender Service Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/sender.md Create a new instance of the sender service using the required repository and log service configurations. ```go senderSvc := sender.NewService(sender.Config{ Repository: boltDB, ReqLogService: reqLogService, Scope: scope, }) ``` -------------------------------- ### Launch Chrome with Proxy Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/configuration.md Automatically launch Chrome with proxy settings configured to point to the Hetty instance. ```bash hetty --chrome # Auto-detect and launch Chrome hetty --addr 127.0.0.1:8080 --chrome # Explicit address ``` -------------------------------- ### Create Project Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/endpoints.md Initializes a new project with a specified name. The name must be alphanumeric and contain only whitespace. ```graphql mutation { createProject(name: "My Project") { id name isActive } } ``` -------------------------------- ### Create Project Mutation Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/api-reference.md Initializes a new project with a validated alphanumeric name. ```go func (r *mutationResolver) CreateProject(ctx context.Context, name string) (*Project, error) ``` -------------------------------- ### Switch Between Projects Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/project.md Listing available projects and switching the active project context. ```go // List all projects projects, err := projSvc.ListProjects(ctx) for _, p := range projects { log.Printf("Project: %s (%s)\n", p.Name, p.ID) } // Switch to a different project projSvc.OpenProject(ctx, projects[0].ID) ``` -------------------------------- ### Create a profile-specific wrapper script Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/configuration.md Use a shell script to define custom configurations for specific environments, passing additional arguments through to the binary. ```bash #!/bin/bash # run-hetty-staging.sh hetty \ --cert /etc/hetty/staging/ca.pem \ --key /etc/hetty/staging/ca-key.pem \ --db /var/lib/hetty/staging.db \ --addr 127.0.0.1:8080 \ "$@" ``` -------------------------------- ### Retrieve the active project Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/api-reference.md Returns the currently open project including its settings. ```go func (r *queryResolver) ActiveProject(ctx context.Context) (*Project, error) ``` -------------------------------- ### Get HTTP request log filter settings Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/endpoints.md Retrieves the current filter configuration for HTTP request logs. ```graphql query { httpRequestLogFilter { onlyInScope searchExpression } } ``` -------------------------------- ### Retrieve all projects Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/database.md Fetches a list of all projects stored in the database. ```go func (db *Database) Projects(ctx context.Context) ([]proj.Project, error) ``` -------------------------------- ### GetSettings Database Method Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/database.md Retrieves project settings from the projects bucket using a ULID project identifier. ```go func (db *Database) GetSettings( ctx context.Context, projectID ulid.ULID, ) (proj.Settings, error) ``` -------------------------------- ### Define Project Service Configuration Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/project.md Defines the configuration structure required to initialize the project service. ```go type Config struct { Repository Repository InterceptService *intercept.Service ReqLogService *reqlog.Service SenderService *sender.Service Scope *scope.Scope } ``` -------------------------------- ### Create a New Request Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/sender.md Initialize a new HTTP request with specific methods, headers, and body content using functional options. ```go url, _ := url.Parse("https://example.com/api") req, err := senderSvc.CreateRequest(ctx, url, sender.WithMethod("POST"), sender.WithHeaders(http.Header{"Content-Type": []string{"application/json"}}), sender.WithBody([]byte(`{"key":"value"}`)), ) ``` -------------------------------- ### Get scope rules Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/endpoints.md Retrieves the current scope rules used for URL and body matching. Returns an empty array if no rules are defined. ```graphql query { scope { url # Regexp pattern for URL matching body # Regexp pattern for body matching header { key # Regexp pattern for header key value # Regexp pattern for header value } } } ``` -------------------------------- ### Configure Certificate and Key Paths Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/configuration.md Specify custom paths for the root CA certificate and private key files. ```bash hetty --cert /etc/hetty/ca_cert.pem --key /etc/hetty/ca_key.pem ``` -------------------------------- ### Retrieve all projects Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/endpoints.md Lists all available projects. ```graphql query { projects { id name isActive settings { intercept { ... } } } } ``` -------------------------------- ### HTTPHandler Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/api-reference.md The HTTPHandler function creates an http.Handler that routes GraphQL queries and mutations via POST requests and serves the GraphQL Playground via GET requests. ```APIDOC ## HTTPHandler ### Description Creates an http.Handler for the GraphQL API. It handles POST requests for GraphQL operations and GET requests for the GraphQL Playground. ### Signature `func HTTPHandler(resolver *Resolver, gqlEndpoint string) http.Handler` ### Parameters - **resolver** (*Resolver) - Required - Resolver with service dependencies. - **gqlEndpoint** (string) - Required - GraphQL endpoint path (e.g., /api/graphql/). ### Returns - **http.Handler** - The configured HTTP handler. ### Example ```go resolver := &api.Resolver{ ProjectService: projSvc, RequestLogService: reqLogSvc, InterceptService: interceptSvc, SenderService: senderSvc, } handler := api.HTTPHandler(resolver, "/api/graphql/") httpServer := &http.Server{ Addr: ":8080", Handler: handler, } httpServer.ListenAndServe() ``` ``` -------------------------------- ### Create New Project Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/project.md Create a project with a specific name. The name must be alphanumeric and whitespace only, or an ErrInvalidName error will be returned. ```go project, err := projSvc.CreateProject(ctx, "My Test Project") if err != nil { if errors.Is(err, proj.ErrInvalidName) { log.Println("Invalid project name") } return } fmt.Printf("Created project: %s\n", project.ID) ``` -------------------------------- ### Check Version Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/configuration.md Display the current version of the Hetty application. ```bash $ hetty --version v0.13.0 ``` -------------------------------- ### Define Project struct Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/types.md Represents the project workspace. ```go type Project struct { ID ulid.ULID Name string Settings Settings isActive bool } ``` -------------------------------- ### Service Constructor Signature Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/README.md Standard Go function signature for initializing a new service instance. ```go func NewService(cfg Config) *Service ``` -------------------------------- ### CreateProject Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/project.md Creates a new project with a unique ULID and default settings. ```APIDOC ## CreateProject ### Description Creates a new project. The name must be alphanumeric and contain only whitespace. ### Parameters - **ctx** (context.Context) - Execution context - **name** (string) - Project name (alphanumeric and whitespace only) ### Returns - **Project** - The created project object - **error** - Returns ErrInvalidName if the name is invalid ``` -------------------------------- ### Implement Middleware Pattern Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/README.md Defines middleware function types and demonstrates how to register modifiers to the proxy. ```go type RequestModifyFunc func(*http.Request) type RequestModifyMiddleware func(RequestModifyFunc) RequestModifyFunc proxy.UseRequestModifier(svc1.Modifier) proxy.UseRequestModifier(svc2.Modifier) ``` -------------------------------- ### Open Project Mutation Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/api-reference.md Switches the active project context using a ULID. ```go func (r *mutationResolver) OpenProject(ctx context.Context, id ulid.ULID) (*Project, error) ``` -------------------------------- ### Open a BoltDB database Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/database.md Initializes a connection to the database file. Ensure the file path is accessible and handle the returned error appropriately. ```go db, err := bolt.OpenDatabase( "/home/user/.hetty/hetty.db", bbolt.DefaultOptions, ) if err != nil { log.Fatal(err) } defer db.Close() ``` -------------------------------- ### GetSettings(ctx, projectID) Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/project.md Retrieves the configuration settings for a specific project. ```APIDOC ## GetSettings(ctx, projectID) ### Description Retrieves settings for a specific project identified by its ULID. ### Signature `func (svc *Service) GetSettings(ctx context.Context, projectID ulid.ULID) (Settings, error)` ### Parameters - **ctx** (context.Context) - Required - Execution context - **projectID** (ulid.ULID) - Required - Project ID ### Returns - **Settings** - The project settings - **error** - Error object if retrieval fails ``` -------------------------------- ### Sender Configuration Struct Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/sender.md Defines the dependencies required to initialize the sender service. ```go type Config struct { Scope *scope.Scope Repository Repository ReqLogService *reqlog.Service HTTPClient *http.Client } ``` -------------------------------- ### Define Repository Interface Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/README.md Abstracts data access methods to allow for swappable storage implementations. ```go type Repository interface { FindRequestLogs(...) ([]RequestLog, error) StoreRequestLog(...) error // ... } ``` -------------------------------- ### Define Project Settings Structure Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/project.md Defines the configuration schema for request logging, interception, and scope management. ```go type Settings struct { // Request log settings ReqLogBypassOutOfScope bool ReqLogOnlyFindInScope bool ReqLogSearchExpr filter.Expression // Intercept settings InterceptRequests bool InterceptResponses bool InterceptRequestFilter filter.Expression InterceptResponseFilter filter.Expression // Sender settings SenderOnlyFindInScope bool SenderSearchExpr filter.Expression // Scope settings ScopeRules []scope.Rule } ``` -------------------------------- ### Configure Project Scope Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/project.md Updating project settings to include new scope rules. ```go active := projSvc.ActiveProject() settings := active.Settings // Add scope rule for specific domain settings.ScopeRules = append(settings.ScopeRules, scope.Rule{ URL: regexp.MustCompile(".*example\\.com.*"), }) projSvc.UpdateSettings(ctx, active.ID, settings) ``` -------------------------------- ### Define Config struct Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/types.md Configuration used for initializing the proxy. ```go type Config struct { CACert *x509.Certificate CAKey crypto.PrivateKey Logger log.Logger } ``` -------------------------------- ### OpenProject Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/project.md Switches the service to an active project and updates sub-services. ```APIDOC ## OpenProject ### Description Sets the service's active project, loads settings, and updates sub-services with the new project context. ### Parameters - **ctx** (context.Context) - Execution context - **projectID** (ulid.ULID) - Project ID to open ### Returns - **Project** - The opened project object - **error** - Returns ErrProjectNotFound if the project does not exist ``` -------------------------------- ### NewProxy(cfg Config) (*Proxy, error) Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/proxy.md Creates a new MITM proxy instance using the provided CA certificate and private key for HTTPS interception. ```APIDOC ## NewProxy ### Description Creates a new MITM proxy instance. This proxy is used to handle HTTP request/response interception and TLS certificate generation. ### Parameters - **cfg.CACert** (*x509.Certificate) - Required - Root CA certificate for signing intercepted HTTPS connections - **cfg.CAKey** (crypto.PrivateKey) - Required - Root CA private key - **cfg.Logger** (log.Logger) - Optional - Logger instance; uses noop logger if nil ### Returns - (*Proxy, error) - Configured proxy ready to serve HTTP requests or an error if cert config creation fails ``` -------------------------------- ### Customize Hetty file locations via CLI flags Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/configuration.md Use these flags to override default paths for certificates, keys, the database, and the listening address. ```bash hetty \ --cert /etc/hetty/ca.pem \ --key /etc/hetty/ca-key.pem \ --db /var/lib/hetty/data.db \ --addr 0.0.0.0:8080 ``` -------------------------------- ### Run Hetty with Docker Source: https://github.com/dstotijn/hetty/blob/main/README.md Execute the Hetty container with a mounted volume for persistent storage and port 8080 exposed. ```sh docker run -v $HOME/.hetty:/root/.hetty -p 8080:8080 \ ghcr.io/dstotijn/hetty:latest ``` -------------------------------- ### Define Project Structure Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/project.md Represents the core project data structure including ID, name, and configuration settings. ```go type Project struct { ID ulid.ULID // Unique project ID Name string // Project name Settings Settings // Project configuration isActive bool // Whether this is the active project (internal) } ``` -------------------------------- ### Proxy Configuration Structure Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/proxy.md The configuration struct required for initializing a new proxy instance. ```go type Config struct { CACert *x509.Certificate // Root CA certificate CAKey crypto.PrivateKey // Root CA private key Logger log.Logger // Optional logger } ``` -------------------------------- ### Persist Hetty data with Docker volumes Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/configuration.md Mount a local directory to the container to ensure certificates, keys, and the database persist across restarts. ```bash docker run -v $HOME/.hetty:/root/.hetty hetty ``` -------------------------------- ### Initialize Intercept Service Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/intercept.md Creates a new intercept service instance with specific configuration for logging and interception enablement. ```go interceptSvc := intercept.NewService(intercept.Config{ Logger: logger, RequestsEnabled: true, ResponsesEnabled: false, }) ``` -------------------------------- ### Retrieve Project Settings Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/project.md Retrieves settings for a specific project identified by its ULID. ```go func (svc *Service) GetSettings(ctx context.Context, projectID ulid.ULID) (Settings, error) ``` -------------------------------- ### Mutation.createProject Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/api-reference.md Creates a new project with a specified name. ```APIDOC ## Mutation.createProject ### Description Creates a new project. The name must be alphanumeric and may contain whitespace. ### Parameters - **name** (string) - Required - Project name (alphanumeric + whitespace) ### Response - **Project** (object) - The created project object - **error** (error) - Error if the name is invalid ``` -------------------------------- ### openProject Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/endpoints.md Switches to an active project using its ID. ```APIDOC ## mutation openProject ### Description Switch to an active project. ### Parameters - **id** (ID!) - Required - ULID of project to open ### Response - **Project** ``` -------------------------------- ### Create sender request from log in Go Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/sender.md Initializes a new sender request based on an existing request log entry. The resulting request can be modified and re-sent. ```go // User copies a logged request to sender senderReq, err := senderSvc.CreateFromRequestLog(ctx, logID) if err != nil { log.Printf("Failed to create sender request: %v", err) return } // Now can modify and re-send the request ``` -------------------------------- ### Initialize a Lexer Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/filter.md Creates a new lexer instance to scan a filter expression string. ```go func NewLexer(input string) *Lexer ``` ```go lexer := filter.NewLexer("method == GET AND status >= 400") ``` -------------------------------- ### createProject Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/endpoints.md Creates a new project with the specified name. ```APIDOC ## mutation createProject ### Description Creates a new project. Validates that the name contains only alphanumeric characters and whitespace. ### Parameters - **name** (String!) - Required - Project name (alphanumeric and whitespace only) ### Response - **Project** - Newly created project with default settings ### Errors - ErrInvalidName if name contains invalid characters ``` -------------------------------- ### Use Request Logging Context Keys Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/reqlog.md Demonstrates how to set a bypass flag and retrieve a ULID log ID from the context. ```go // Skip logging this request ctx = context.WithValue(ctx, LogBypassedKey, true) // Retrieve the log ID later logID, ok := ctx.Value(ReqLogIDKey).(ulid.ULID) ``` -------------------------------- ### Handle SendError with errors.As Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/sender.md Demonstrates how to unwrap and log the underlying error from a SendError. ```go _, err := svc.SendRequest(ctx, id) if err != nil { var sendErr *sender.SendError if errors.As(err, &sendErr) { log.Printf("Send error: %v", sendErr.Unwrap()) } } ``` -------------------------------- ### UpsertSettings Database Method Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/database.md Stores or updates project settings in the database. ```go func (db *Database) UpsertSettings( ctx context.Context, projectID ulid.ULID, settings proj.Settings, ) error ``` -------------------------------- ### Define Settings struct Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/types.md Configuration settings for project behavior, including interception and filtering. ```go type Settings struct { ReqLogBypassOutOfScope bool ReqLogOnlyFindInScope bool ReqLogSearchExpr filter.Expression InterceptRequests bool InterceptResponses bool InterceptRequestFilter filter.Expression InterceptResponseFilter filter.Expression SenderOnlyFindInScope bool SenderSearchExpr filter.Expression ScopeRules []scope.Rule } ``` -------------------------------- ### Define Config struct Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/intercept.md Configuration settings for initializing the intercept service, including filters and logging. ```go type Config struct { Logger log.Logger RequestsEnabled bool ResponsesEnabled bool RequestFilter filter.Expression ResponseFilter filter.Expression } ``` -------------------------------- ### Enable Verbose Logging Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/configuration.md Switch the log level from INFO to DEBUG for detailed troubleshooting output. ```bash hetty --verbose ``` -------------------------------- ### NewService Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/intercept.md Initializes a new interception service with the provided configuration. ```APIDOC ## func NewService(cfg Config) *Service ### Description Creates a new intercept service instance to manage request and response interception. ### Parameters - **cfg.Logger** (log.Logger) - Optional - Logger instance - **cfg.RequestsEnabled** (bool) - Optional - Enable request interception - **cfg.ResponsesEnabled** (bool) - Optional - Enable response interception - **cfg.RequestFilter** (filter.Expression) - Optional - Only intercept requests matching expression - **cfg.ResponseFilter** (filter.Expression) - Optional - Only intercept responses matching expression ### Returns - **Service** (*Service) - The initialized interception service. ``` -------------------------------- ### ServeHTTP(w http.ResponseWriter, r *http.Request) Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/proxy.md Implements the http.Handler interface to process proxied requests, including handling CONNECT requests for TLS tunneling. ```APIDOC ## ServeHTTP ### Description Implements http.Handler to serve proxied requests. For CONNECT requests, it hijacks the connection to establish a TLS tunnel; for other methods, it routes through a reverse proxy with modifiers. ### Parameters - **w** (http.ResponseWriter) - Required - The response writer - **r** (*http.Request) - Required - The incoming HTTP request ``` -------------------------------- ### Request Options Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/sender.md Functional options for configuring HTTP requests. ```go func WithMethod(method string) RequestOption ``` ```go func WithProto(proto string) RequestOption ``` ```go func WithHeaders(headers http.Header) RequestOption ``` ```go func WithBody(body []byte) RequestOption ``` -------------------------------- ### Initialize Parser Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/filter.md Creates a new parser instance for a given filter expression string. ```go func NewParser(input string) *Parser ``` ```go parser := filter.NewParser("method == POST AND status >= 400") expr, err := parser.Parse() ``` -------------------------------- ### Retrieve HTTP request logs Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/api-reference.md Fetches all HTTP request logs for the currently active project. ```go func (r *queryResolver) HTTPRequestLogs(ctx context.Context) ([]HTTPRequestLog, error) ``` -------------------------------- ### projects Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/endpoints.md Retrieve all projects. ```APIDOC ## Query projects ### Description Retrieve all projects. ### Response - **[Project!]!** ``` -------------------------------- ### Tokenize with NextToken Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/filter.md Scans the input string and returns the next token, skipping whitespace and identifying keywords, operators, and literals. ```go func (l *Lexer) NextToken() Token ``` ```go lexer := filter.NewLexer("status >= 400") for { tok := lexer.NextToken() if tok.Type == filter.TokEOF { break } fmt.Printf("%s: %s\n", tok.Type, tok.Literal) } ``` -------------------------------- ### Define Request Logging Configuration Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/reqlog.md Structure used to initialize the request logging service with project, scope, repository, and logger dependencies. ```go type Config struct { ActiveProjectID ulid.ULID Scope *scope.Scope Repository Repository Logger log.Logger } ``` -------------------------------- ### NewService Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/sender.md Creates a new sender service instance with the provided configuration. ```APIDOC ## func NewService(cfg Config) *Service ### Description Create a new sender service. ### Parameters - **cfg.Repository** (Repository) - Required - Database repository for persistence - **cfg.ReqLogService** (*reqlog.Service) - Required - Request log service for correlation - **cfg.Scope** (*scope.Scope) - Optional - Scope instance for filtering - **cfg.HTTPClient** (*http.Client) - Optional - Custom HTTP client; uses default if nil ### Returns - *Service ``` -------------------------------- ### Retrieve Active Project Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/project.md Fetches the currently active project. Returns an empty Project if no project is active. ```go func (svc *Service) ActiveProject() Project ``` ```go active := projSvc.ActiveProject() if active.ID == (ulid.ULID{}) { log.Println("No project is open") } else { log.Printf("Active project: %s\n", active.Name) } ``` -------------------------------- ### Open Project Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/endpoints.md Sets a specific project as the active project using its ULID. ```graphql mutation { openProject(id: "01ARZ3NDEKTSV4RRFFQ69G5FAV") { id name isActive } } ``` -------------------------------- ### Hetty Module Dependencies Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/README.md Visual representation of the internal package and command dependencies within the Hetty project. ```text cmd/hetty ├── proxy ├── api ├── reqlog ├── sender ├── proj ├── filter └── scope pkg/proxy ├── filter └── intercept pkg/reqlog ├── filter ├── scope └── proxy (for middleware interface) pkg/sender ├── filter ├── scope └── reqlog pkg/api ├── filter ├── proj ├── reqlog ├── sender ├── proxy └── intercept pkg/proj ├── filter ├── scope ├── reqlog ├── sender └── intercept ``` -------------------------------- ### Define Request Logging Context Keys Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/reqlog.md Constants used for storing and retrieving request-specific metadata in a context. ```go const LogBypassedKey contextKey = iota // Skip this request from logging const ReqLogIDKey contextKey // Request log ID for correlation ``` -------------------------------- ### ListProjects Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/project.md Retrieves all projects. ```APIDOC ## ListProjects ### Description Retrieves a list of all projects. ### Parameters - **ctx** (context.Context) - Execution context ### Returns - **[]Project** - A list of projects - **error** ``` -------------------------------- ### Define Repository Interface Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/project.md The interface required for project and settings persistence. ```go type Repository interface { UpsertProject(ctx context.Context, project Project) error FindProjectByID(ctx context.Context, projectID ulid.ULID) (Project, error) DeleteProject(ctx context.Context, projectID ulid.ULID) error Projects(ctx context.Context) ([]Project, error) GetSettings(ctx context.Context, projectID ulid.ULID) (Settings, error) UpsertSettings(ctx context.Context, projectID ulid.ULID, settings Settings) error } ``` -------------------------------- ### Update Project Settings Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/project.md Updates project settings and propagates changes to sub-services if the project is active. ```go func (svc *Service) UpdateSettings(ctx context.Context, projectID ulid.ULID, settings Settings) error ``` -------------------------------- ### Define HttpHeader struct Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/types.md Represents a single HTTP header. ```go type HttpHeader struct { Key string Value string } ``` -------------------------------- ### GetProject Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/project.md Retrieves a project by ID. ```APIDOC ## GetProject ### Description Retrieves a project by ID without switching the active project. ### Parameters - **ctx** (context.Context) - Execution context - **projectID** (ulid.ULID) - Project ID to retrieve ### Returns - **Project** - The requested project - **error** ``` -------------------------------- ### Define CertConfig struct Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/types.md Holds configuration for MITM certificate generation. ```go type CertConfig struct { ca *x509.Certificate caPriv crypto.PrivateKey priv *rsa.PrivateKey keyID []byte } ``` -------------------------------- ### Project Directory Structure Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/README.md Visual representation of the Hetty source code organization. ```text pkg/ ├── proxy/ → Proxy package │ └── intercept/ → Intercept package ├── api/ → GraphQL API package ├── reqlog/ → Request logging package ├── sender/ → HTTP sender package ├── filter/ → Filter expression package ├── scope/ → Scope rules package ├── proj/ → Project management package ├── db/ → Database package │ └── bolt/ ├── log/ → Logging package └── chrome/ → Chrome integration cmd/hetty/ → Command-line interface admin/ → Web UI (Next.js) ``` -------------------------------- ### Configure Server Address Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/configuration.md Define the TCP address and port for the HTTP server to listen on. ```bash hetty --addr localhost:8080 # IPv4 localhost only hetty --addr [::1]:8080 # IPv6 localhost only hetty --addr 0.0.0.0:8080 # All interfaces hetty --addr :8080 # All interfaces (shorthand) hetty --addr 192.168.1.100:443 # Specific IP and port ``` -------------------------------- ### Apply Regular Expressions Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/configuration.md Delimit regex patterns with slashes to match against URL, body, or header content. ```text url =~ /^https:\/\/api\.example\.com/ body =~ /\d{3}-\d{4}/ # Credit card patterns headers =~ /Authorization: Bearer .*/ ``` -------------------------------- ### Define Proxy struct Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/types.md Represents the main proxy handler configuration. ```go type Proxy struct { certConfig *CertConfig handler http.Handler logger log.Logger reqModifiers []RequestModifyMiddleware resModifiers []ResponseModifyMiddleware } ``` -------------------------------- ### Define Header struct Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/types.md Criteria for matching HTTP headers. ```go type Header struct { Key *regexp.Regexp Value *regexp.Regexp } ``` -------------------------------- ### WithHeaders Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/sender.md Sets the request headers. ```APIDOC ## func WithHeaders(headers http.Header) RequestOption ### Description Sets the request headers for the outgoing request. ### Parameters - **headers** (http.Header) - Required - The headers to apply. ``` -------------------------------- ### Mutation.openProject Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/api-reference.md Switches the active project to the one specified by the ID. ```APIDOC ## Mutation.openProject ### Description Switch to an active project. ### Parameters - **id** (ulid.ULID) - Required - Project ID to open ### Response - **Project** (object) - The opened project object ``` -------------------------------- ### Define Request struct in pkg/sender Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/types.md Represents a manually created or sent HTTP request with associated metadata and optional response logs. ```go type Request struct { ID ulid.ULID // Unique ID ProjectID ulid.ULID // Project ID SourceRequestLogID ulid.ULID // Source log ID URL *url.URL // Request URL Method string // HTTP method Proto string // Protocol Header http.Header // Headers Body []byte // Body Response *reqlog.ResponseLog // Optional response } ``` -------------------------------- ### Find a project by ID Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/database.md Retrieves a project by its ULID. Returns a zero value if the project is not found. ```go func (db *Database) FindProjectByID(ctx context.Context, projectID ulid.ULID) (proj.Project, error) ``` -------------------------------- ### Match a request against a rule Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/scope.md Evaluates an HTTP request and body against the defined rule criteria. ```go func (r Rule) Match(req *http.Request, body []byte) bool ``` -------------------------------- ### Set environment variables for proxy Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/configuration.md Define HTTP_PROXY and HTTPS_PROXY variables to route system-wide traffic through the proxy. ```bash export HTTP_PROXY=http://localhost:8080 export HTTPS_PROXY=http://localhost:8080 ``` -------------------------------- ### Rules() Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/scope.md Retrieves a snapshot of all current scope rules. ```APIDOC ## func (s *Scope) Rules() []Rule ### Description Returns a snapshot of all current scope rules. This operation is thread-safe using a read lock. ### Returns - **[]Rule** - A slice containing the current scope rules. ``` -------------------------------- ### Define RequestLog struct Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/types.md Represents a logged HTTP request. ```go type RequestLog struct { ID ulid.ULID // Unique ID ProjectID ulid.ULID // Project ID URL *url.URL // Request URL Method string // HTTP method Proto string // HTTP protocol Header http.Header // Headers Body []byte // Request body Response *ResponseLog // Optional response } ``` -------------------------------- ### NewService Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/reqlog.md Creates a new instance of the request logging service. ```APIDOC ## func NewService(cfg Config) *Service ### Description Creates a new request logging service instance with the provided configuration. ### Parameters - **cfg.ActiveProjectID** (ulid.ULID) - Optional - Current project ID. - **cfg.Scope** (*scope.Scope) - Required - Scope instance for filtering. - **cfg.Repository** (Repository) - Required - Database repository for persistence. - **cfg.Logger** (log.Logger) - Optional - Logger instance. ``` -------------------------------- ### Retrieve all sender requests Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/api-reference.md Fetches all sender requests associated with the active project. ```go func (r *queryResolver) SenderRequests(ctx context.Context) ([]SenderRequest, error) ``` -------------------------------- ### Register Proxy as Handler Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/proxy.md Use the proxy instance as a fallback handler within a router. ```go // Register proxy as the fallback handler router.PathPrefix("").Handler(proxy) ``` -------------------------------- ### Define Service Structure in Go Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/README.md Defines the service struct with dependency injection and internal state management. ```go type Service struct { // Dependencies repo Repository scope *scope.Scope logger log.Logger // State activeProjectID ulid.ULID filter FindRequestsFilter } ``` -------------------------------- ### WithProto Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/sender.md Sets the HTTP protocol version for the request. ```APIDOC ## func WithProto(proto string) RequestOption ### Description Sets the HTTP protocol version (e.g., "HTTP/1.1", "HTTP/2.0"). ### Parameters - **proto** (string) - Required - The protocol version string. ``` -------------------------------- ### OpenDatabase Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/database.md Opens or creates a BoltDB database file at the specified path. ```APIDOC ## OpenDatabase ### Description Opens or creates a BoltDB database file. Creates the file if it does not exist and returns a database instance. ### Signature `func OpenDatabase(path string, opts *bolt.Options) (*Database, error)` ### Parameters - **path** (string) - Required - File path to database. - **opts** (*bolt.Options) - Optional - BoltDB options (can be nil for defaults). ### Returns - `(*Database, error)` - A database instance or an error if the operation fails. ``` -------------------------------- ### Match HTTP Request Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/filter.md Evaluates an expression against an HTTP request, body, and method. ```go parser := filter.NewParser("method == POST") expr, _ := parser.Parse() matches, err := filter.MatchHTTPRequest(req, body, expr) if matches { log.Println("Request is a POST") } ``` -------------------------------- ### Match request against scope Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/scope.md Evaluates an HTTP request and body against defined rules, returning true on the first match. ```go func (s *Scope) Match(req *http.Request, body []byte) bool ``` ```go if scope.Match(req, body) { log.Println("Request is in scope") } ``` -------------------------------- ### WithBody Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/sender.md Sets the request body. ```APIDOC ## func WithBody(body []byte) RequestOption ### Description Sets the body content for the request. ### Parameters - **body** ([]byte) - Required - The raw byte content of the request body. ``` -------------------------------- ### Configure Database Path Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/configuration.md Set the file path for the BoltDB database used to store project data and logs. ```bash hetty --db /var/lib/hetty/hetty.db ``` -------------------------------- ### Retrieve active project scope rules Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/api-reference.md Fetches the scope rules defined for the active project. ```go func (r *queryResolver) Scope(ctx context.Context) ([]ScopeRule, error) ``` -------------------------------- ### LoadOrCreateCA Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/proxy.md Loads a CA certificate and key from disk, or generates new ones if the files do not exist. ```APIDOC ## LoadOrCreateCA ### Description Loads a CA certificate and key from disk, or generates new ones if files don't exist. If files are generated, they are saved to disk with 0600 permissions. ### Signature `func LoadOrCreateCA(caKeyFile, caCertFile string) (*x509.Certificate, *rsa.PrivateKey, error)` ### Parameters - **caKeyFile** (string) - Required - Path to CA private key file (PEM format) - **caCertFile** (string) - Required - Path to CA certificate file (PEM format) ### Returns - `(*x509.Certificate, *rsa.PrivateKey, error)` - The loaded or generated CA certificate, private key, and any potential error. ``` -------------------------------- ### DatabaseFromBoltDB Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/database.md Wraps an existing BoltDB instance into the Database interface. ```APIDOC ## DatabaseFromBoltDB ### Description Wraps an existing BoltDB instance. Useful for testing with in-memory databases or custom configurations. ### Signature `func DatabaseFromBoltDB(db *bolt.DB) (*Database, error)` ### Parameters - **db** (*bolt.DB) - Required - Existing BoltDB database instance. ### Returns - `(*Database, error)` - A database instance or an error if the wrapping fails. ``` -------------------------------- ### Create Sender Request from Log Mutation Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/api-reference.md Generates a new sender request by copying details from an existing HTTP request log. ```go func (r *mutationResolver) CreateSenderRequestFromHttpRequestLog( ctx context.Context, id ulid.ULID, ) (*SenderRequest, error) ``` -------------------------------- ### Upsert a project in the database Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/database.md Creates or updates a project using gob serialization within an atomic transaction. ```go func (db *Database) UpsertProject(ctx context.Context, project proj.Project) error ``` -------------------------------- ### Load or create CA certificate Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/proxy.md Function signature for loading or generating a CA certificate and private key. ```go func LoadOrCreateCA(caKeyFile, caCertFile string) (*x509.Certificate, *rsa.PrivateKey, error) ``` -------------------------------- ### Perform thread-safe scope operations in Go Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/scope.md Demonstrates concurrent rule updates and matching using thread-safe scope methods. ```go scope := &scope.Scope{} // Thread 1: Update rules go func() { scope.SetRules(newRules) }() // Thread 2: Check matches go func() { if scope.Match(req, body) { // ... } }() ``` -------------------------------- ### UpdateSettings(ctx, projectID, settings) Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/project.md Updates the configuration settings for a specific project. ```APIDOC ## UpdateSettings(ctx, projectID, settings) ### Description Updates project settings. If the project is active, this method also updates all sub-services, applies scope rules, and updates intercept settings. ### Signature `func (svc *Service) UpdateSettings(ctx context.Context, projectID ulid.ULID, settings Settings) error` ### Parameters - **ctx** (context.Context) - Required - Execution context - **projectID** (ulid.ULID) - Required - Project ID - **settings** (Settings) - Required - Updated settings object ### Returns - **error** - Error object if the update fails ``` -------------------------------- ### Match HTTP Headers Source: https://github.com/dstotijn/hetty/blob/main/_autodocs/filter.md Evaluates header matching expressions using equality or regex operators. ```go matched, _ := filter.MatchHTTPHeaders( filter.TokOpRe, filter.RegexpLiteral{Regexp: regexp.MustCompile("Authorization: Bearer.*")}, req.Header, ) ```