writeonce/docs/examples/porch/http/form.wo
shoney.arickathil ffd791d05b refactor(porch): name the web framework porch, fix the wo.toml identifier claim
- docs/examples/writeonce-serve -> docs/examples/porch (git mv, history kept);
  `[deps]` key and import are now `porch` / `porch/http` / `porch/router`
- name history preserved on the library README, not rewritten into dated
  records: writeonce-framework -> writeonce-serve (08-25) -> porch (08-26).
  Stories, specs, plans and the audit reports keep the older name by the
  repo's own convention; only live docs and every path link were rewritten
- left alone deliberately: `internal/serve.wo`, `pub fn serve`, `serve_conn`,
  `app.serve(...)` — those are functions, not the module name
- web-app/wo.toml comment corrected: it claimed hyphens are not identifier
  characters and named a key this file never used. lexer.ml's `is_ident_cont`
  DOES accept `-` (an internal dash is part of the identifier, which is why
  binary minus needs spaces), so a hyphenated key would be legal too
- site now teaches the name: package card, the two-deps chapter and the
  handlers-are-classes chapter say `porch`; site-accept asserted the old
  /packages/serve route and caught the rename, as a gate should
- gates: web-app 46/0, site 21/0, deps-accept 8/0, oop-e2e 116/0,
  linkcheck 0 broken / 0 anchors; porch typechecks entry-less as kind=library

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-26 19:36:34 +02:00

28 lines
1.3 KiB
Text

-- http/form.wo — the public body-inspection surface: what media type a
-- request carries, and form-encoded bodies as decoded pairs.
--
-- PUBLIC by design (iteration 17). It sits here rather than in
-- `internal/parse.wo` with the rest of the parsing code because these two
-- functions are exactly what a consuming app calls; the decoders they lean on
-- stay behind the privacy line. `use internal` is legal INSIDE the library —
-- the boundary is consumer-only.
use internal
-- The request's media type: the content-type header lowercased with any
-- parameters ("; charset=...") stripped; "" when the header is absent.
pub fn media_type(req: Req) -> Text {
let ct = req.headers["content-type"];
if ct == nil { return ""; }
let semi = index_of(ct, ";");
if semi >= 0 { return to_lower(trim(substr(ct, 0, semi))); }
return to_lower(trim("${ct}"));
}
-- Form-encoded body -> decoded pairs ('+' as space, %XX), the body-parsing
-- hook for application/x-www-form-urlencoded. nil when the content-type
-- says the body is something else — a JSON body is not silently misread
-- as one giant form key.
pub fn form_values(req: Req) -> ?map<Text, Text> {
if media_type(req) != "application/x-www-form-urlencoded" { return nil; }
return parse_query(req.body);
}