OxL Справочник OxL
РусскийEnglish

data Site

A site held in memory.

Example:

oxl✓ проверяется в CI
use std.web { Site, CacheRule, cacheRule }
use std.http { Request, Reply }

// one file, index.html, gzip-compressed "hello" (comptime.embedDir builds such tuples: path, media type, ETag, gzip data, size)
fn site() -> Site {
  let gz = b"\x1f\x8b\x08\x00\x00\x00\x00\x00\x02\xff\xcb\x48\xcd\xc9\xc9\x07\x00\x86\xa6\x10\x36\x05\x00\x00\x00"
  Site.embedded([("index.html", "text/html", "\"v1\"", gz, 5)], [cacheRule("*.html", "no-cache")])
}

fn get(path: str) -> Request {
  Request{ method: "GET", target: path, path: path, rawQuery: "", version: "HTTP/1.1", headers: [], body: Utf8.encode(""), peer: "", params: [] }
}

fn main() io {
  let s = site()
  print("{s.count()} {s.has("index.html")} {s.has("other.html")}")
}
Вывод
1 true false
pub(api) data Site

Потокобезопасность. immutable once built; one `Site` serves any number of requests at once.

С версии. 1.0.0-beta

Поля

pub(api) defaultControl: str = "public, max-age=300"

Cache-Control when no rule matches.

Методы

embedded(files: List<(str, str, str, bytes, i64)>, rules: List<CacheRule>) -> Site
The site made of the files of comptime.embedDir(...); rules are tried in order.
count() -> usize
Number of files.
has(path: str) -> bool
Whether the site has the file path (without the leading /).
reply(req: Request) -> Reply
Answers a request of a browser.

Определено в: std/web/web.oxl:133

См. также