def decide

ezmcp@0.1.0.0 · src/web.bend:204

import ezmcp@0.1.0.0/src/web.bend as Web
import Base
import emerging-ezhttp@0.21.0.0/src/http.bend as Http
import ezmcp@0.1.0.0/src/server.bend as Server

204# what the transport does with one HTTP request to an endpoint at `path`,
205# which allows the browser origins listed
206def decide(
207  srv: Server.Server,
208  path: String,
209  origins: List<&2, String>,
210  req: Http.Request
211) -> Web:
212  match req:
213    case Http.Bad{why}:
214      text(400, why)
215    case Http.Request{+m, +target, +headers, body}:
216      route(srv, String.eq(path.of(target), path),
217        origin.ok(origins, Http.headers.find(headers, "Origin")),
218        String.eq(m, "POST"),
219        Http.headers.find(headers, "MCP-Protocol-Version"), body)

Uses (11)

Used by (4)