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

method Site.has

Whether the site has the file path (without the leading /).

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.has("index.html")} {s.has("/index.html")}")
}
Вывод
true false
pub(api) fn has(path: str) -> bool

Сложность. O(1) on average.

С версии. 1.0.0-beta

Параметры

ИмяТип
pathstr

Возвращает

bool

Эффекты

не объявлены (чистая, пока тело не говорит иное)

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

См. также