---
title: CGI
description: Common Gateway Interface implementation
icon: Settings
---
import { Step, Steps } from 'fumadocs-ui/components/steps';
## Overview
The CGI implementation acts as a **Driver Plugin** in the L7 Flow. It follows the standard CGI/1.1 specification (RFC 3875).
**Source**: `src/plugins/l7/cgi/executor.rs`
## Execution Process
<Steps>
<Step>
### Setup & Environment
The middleware collects metadata from the `Container` and injects it as Environment Variables (`SCRIPT_NAME`, `PATH_INFO`, `HTTP_*`).
<Mermaid
chart="
graph LR
Container[Container] -->|Extract| Meta[Metadata: Method, URI...]
Container -->|Resolve| Params[Plugin Params: cmd, args]
Meta -->|Inject| Env[ENV Vars: SCRIPT_NAME...]
Params -->|Configure| Process[Process Builder]
"
/>
</Step>
<Step>
### I/O Piping
Vane spawns the subprocess. It writes the Request Body to `stdin` and reads from `stdout` (and logs `stderr`).
> **Non-Blocking**: The Request Body is buffered before writing to prevent deadlocks with scripts that wait for EOF before responding.
<Mermaid
chart="
graph LR
ReqBody[Request Body] -->|Write| Stdin[Subprocess STDIN]
Subprocess -->|Exec| Script[CGI Script]
Script -->|Output| Stdout[Subprocess STDOUT]
Stdout -->|Read| Vane[Vane Parser]
"
/>
</Step>
<Step>
### Parsing & Response
The parser waits for the double newline (`\r\n\r\n`) to separate headers from the body. Headers are mapped to `Container` response headers, and the body is streamed.
<Mermaid
chart="
graph LR
Vane -->|Parse| HeaderBuffer[Header Buffer]
HeaderBuffer -->|Headers| ResHead[Response Headers]
HeaderBuffer -->|Remaining| ResBody[Response Body Stream]
ResHead --> Container
ResBody --> Container
"
/>
</Step>
</Steps>