feat(executor): expose ctx.request.method to scripts (F4)
The request map exposed path/headers/body/params/query/rest but not the HTTP method, forcing one script per verb (the E2E app needed 7 scripts where ~3 would do). Add a `method` field to ExecRequest (populated from the HTTP method on the sync-execute bypass and the HTTP outbox payload; empty for non-HTTP triggers) and surface it as `ctx.request.method`, uppercased. A single script can now branch GET/POST on one route. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -485,6 +485,7 @@ fn build_ctx_map(req: &ExecRequest) -> Map {
|
||||
|
||||
let mut request = Map::new();
|
||||
request.insert("path".into(), req.path.clone().into());
|
||||
request.insert("method".into(), req.method.clone().into());
|
||||
|
||||
let mut headers = Map::new();
|
||||
for (k, v) in &req.headers {
|
||||
|
||||
@@ -171,6 +171,7 @@ fn invoke_blocking(
|
||||
script_name: resolved.name.clone(),
|
||||
invocation_type: InvocationType::Function,
|
||||
path: "/invoke".into(),
|
||||
method: String::new(),
|
||||
headers: BTreeMap::new(),
|
||||
body: args_json,
|
||||
params: BTreeMap::new(),
|
||||
|
||||
@@ -27,6 +27,15 @@ pub struct ExecRequest {
|
||||
pub script_name: String,
|
||||
pub invocation_type: InvocationType,
|
||||
pub path: String,
|
||||
|
||||
/// HTTP method of the originating request, uppercased (`GET`, `POST`,
|
||||
/// …). Exposed to scripts as `ctx.request.method` so a single script
|
||||
/// can branch on the verb instead of needing one script per method.
|
||||
/// Empty for non-HTTP trigger invocations (cron/kv/docs/…), matching
|
||||
/// how `path`/`rest` are empty there.
|
||||
#[serde(default)]
|
||||
pub method: String,
|
||||
|
||||
pub headers: BTreeMap<String, String>,
|
||||
pub body: serde_json::Value,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user