lmproxy reference
Complete command-line subcommands and flags, Proxy, Url, and Message host methods, standard lmcode_std_v3 REST and CLI interfaces, and exit codes for lmproxy v0.1.1.
Host and CLI subcommands
| Command or flag | Arguments | Description |
|---|---|---|
| --version | none | Print lmproxy 0.1.1 and exit 0. |
| --lmcode-schema | [--json] | Print human-readable signatures summary, or exact embedded host schema JSON bytes when --json is passed. |
| --lmcode-signatures | none | Print all canonical context, function, and method signatures (host + 226 standard library signatures). |
| --lmcode | <file.dslb>... | Load and execute compiled LMScript bytecode files against the embedded lmproxy schema. |
| parse-url | <URL>... | Parse one or more URLs with Squid 7 and print one JSON object per line ({valid,scheme,host,host_is_ip,userinfo,port,path,error}). |
| parse-request | <FILE | -> | Parse a raw HTTP/1.x request from FILE or stdin (-) and print JSON ({kind,complete,version,method,target,headers,error}). |
| parse-response | <FILE | -> | Parse a raw HTTP/1.x response from FILE or stdin (-) and print JSON ({kind,complete,version,status,reason,headers,error}). |
| forward | [--port P] [--bind ADDR] [proxy-flags] | Start the embedded Squid 7 forward proxy daemon (default port 3128, default bind 127.0.0.1). |
| intercept | [--port P] [--bind ADDR] [proxy-flags] | Start the embedded Squid 7 transparent interception proxy daemon (default port 3129, default bind 127.0.0.1). |
| run | --config <file.conf> [--debug N] | Run the embedded Squid 7 engine directly using a custom Squid configuration file. |
| certgen | [security_file_certgen-args] | Internal subcommand invoking the embedded Squid dynamic SSL certificate generator helper. |
| --port / -p | <port> | Listening TCP port for forward (default 3128) or intercept (default 3129). |
| --bind / -b | <address> | Bind IP address for forward or intercept (default 127.0.0.1). |
| --ssl-bump | none | Enable dynamic SSL-bump TLS decryption and on-the-fly host certificate generation. |
| --ca-cert / --ca-key | <path> | Custom PEM Root CA certificate and private key for --ssl-bump (auto-generated if omitted). |
| --tap | none | Print real-time intercepted HTTP/HTTPS request and response summaries to stderr. |
| --record | <file.jsonl> | Append structured JSONL traffic records ({timestamp,client,method,url,status,bytes,duration_ms}) to FILE. |
| --route | <PATTERN=HOST:PORT> | Transparently route requests matching domain or regex PATTERN to an alternate backend origin HOST:PORT. |
| --redirect | <PATTERN=URL> | Intercept requests matching PATTERN and respond with an HTTP 307 Temporary Redirect to URL. |
| --debug / -d | <level> | Set Squid debug logging verbosity level. |
Host context proxy: Proxy, Url, and Message methods
| Type / context | Method or function signature | Description |
|---|---|---|
| context proxy: Proxy | proxy.parse_url(string) -> Url | parse_url(string) -> Url | Parse a URL string using Squid 7 and return a Url handle (up to 65536 handles per run). |
| Proxy / function | proxy.parse_request(string) -> Message | parse_request(string) -> Message | Parse a raw HTTP/1.x request string using Squid 7 and return a Message handle. |
| Proxy / function | proxy.parse_response(string) -> Message | parse_response(string) -> Message | Parse a raw HTTP/1.x response string using Squid 7 and return a Message handle. |
| Proxy / function | proxy.percent_decode(string) -> string | percent_decode(string) -> string | Percent-decode an URL path or query component string. |
| Proxy / function | proxy.percent_encode(string) -> string | percent_encode(string) -> string | Percent-encode special characters in a string according to Squid URL rules. |
| function println | println(string) -> void | Write a line of text to host output. |
| Url | u.raw() -> string | u.valid() -> bool | u.error() -> string | Return the original unparsed input string, whether parsing succeeded, or the parser error message. |
| Url | u.scheme() | u.host() | u.userinfo() | u.path() -> string | Return the decomposed URL scheme, hostname or IP literal, userinfo prefix, or path+query string. |
| Url | u.host_is_ip() -> bool | u.port() -> int | u.has_port() -> bool | Check whether host is an IPv4/IPv6 literal, read the effective port number (0 if none), or check if an explicit port was specified. |
| Message | m.kind() -> string | m.complete() -> bool | m.error() -> string | Return "request" or "response", whether the HTTP header block parsed completely, or any parse error text. |
| Message | m.version() -> string | m.method() -> string | m.target() -> string | Return the HTTP version string (such as "HTTP/1.1"), request method, or request target URI. |
| Message | m.status() -> int | m.reason() -> string | Return the HTTP response status code (0 for requests) and reason phrase. |
| Message | m.header(string) -> string | m.header_count() -> int | m.header_names() -> StrList | Look up a header value case-insensitively ("" if missing), return distinct header count, or return an independent StrList of header names. |
Standard lmcode_std_v3 REST and CLI interfaces
| Interface or function | Signature / annotation | Description |
|---|---|---|
| RestGet .. RestOptions | @"/path/:param" fn h(x: RestExchange) -> void implements RestGet | Bind an HTTP GET, POST, PUT, DELETE, PATCH, HEAD, or OPTIONS route handler. |
| RestHandler | @"/path" fn h(x: RestExchange) -> void implements RestHandler | Bind a method-agnostic HTTP route handler. |
| CliCommand | @"cmd" fn h(x: RestExchange) -> void implements CliCommand | Bind a named CLI subcommand dispatched by rest_cli. |
| CliOption | @"--flag" fn h(x: RestExchange) -> void implements CliOption | Bind a CLI option flag (--flag=val or --flag val) evaluated before the command handler. |
| rest_config | rest_config(key: string, value: string) -> void | Configure server or CLI settings such as host, port, and session (ephemeral or global). |
| rest_route | rest_route(method: string, path: string, handler: string) -> void | Dynamically register an HTTP method and route pattern to a handler function name. |
| rest_serve / rest_stop | rest_serve() -> void | rest_stop() -> void | Start or stop the embedded standard HTTP server loop. |
| rest_cli | rest_cli(args: StrList) -> string | Dispatch CLI options, commands, or path requests in-process without opening a socket. |
| RestExchange | x.method() | x.path() | x.body() | x.param(string) | x.query(string) | x.header(string) -> string | Read request method, path, body, :param segment, query parameter, or header. |
| RestExchange | x.has_query(string) | x.has_header(string) -> bool | Check whether a query parameter or request header is present. |
| RestExchange | x.status(int) | x.set_header(string, string) | x.send(string) | x.json(string) -> void | Set response status code and headers, and emit plain text or application/json bodies. |
| RestExchange | x.get(string) -> string | x.set(string, string) -> void | x.increment(string) -> int | Read, write, or atomically increment session state keys across global or ephemeral exchanges. |
Exit codes
| Exit code | Category | Meaning |
|---|---|---|
| 0 | Success | CLI parser, proxy daemon execution, or _lmcode_ program completed and all assertions passed. |
| 2 | Usage error | Invalid command-line flag, malformed --route or --redirect argument, or invocation metadata error. |
| 3 | Host / load error | Unreadable input file in parse-request/parse-response, bytecode load failure, arena limit exceeded, or unhandled VM error. |
| 4 | Contract / output failure | An assertion (assert, assert_eq) or result schema contract failed, or stdout write failed. |