From c87d442aac69270be67811ff67a332b96e8e467e Mon Sep 17 00:00:00 2001 From: yhirose Date: Tue, 3 Mar 2026 23:58:03 -0500 Subject: [PATCH] Remove docs-gen --- docs-gen/Cargo.lock | 1992 ----------------- docs-gen/Cargo.toml | 22 - docs-gen/README.md | 254 --- docs-gen/defaults/config.toml | 20 - docs-gen/defaults/pages/en/index.md | 10 - docs-gen/defaults/pages/ja/index.md | 10 - docs-gen/defaults/static/css/main.css | 603 ----- docs-gen/defaults/static/favicon.svg | 4 - docs-gen/defaults/static/js/main.js | 297 --- docs-gen/defaults/templates/base.html | 88 - docs-gen/defaults/templates/page.html | 30 - docs-gen/defaults/templates/portal.html | 12 - docs-gen/src/builder.rs | 468 ---- docs-gen/src/config.rs | 97 - docs-gen/src/defaults.rs | 47 - docs-gen/src/main.rs | 99 - docs-gen/src/markdown.rs | 145 -- docs-gen/src/serve.rs | 340 --- docs-gen/src/utils.rs | 22 - docs-src/config.toml | 12 +- docs/css/main.css | 6 +- docs/en/cookbook/index.html | 10 +- docs/en/index.html | 10 +- docs/en/tour/01-getting-started/index.html | 78 +- docs/en/tour/02-basic-client/index.html | 316 +-- docs/en/tour/03-basic-server/index.html | 238 +- docs/en/tour/04-static-file-server/index.html | 134 +- docs/en/tour/05-tls-setup/index.html | 72 +- docs/en/tour/06-https-client/index.html | 118 +- docs/en/tour/07-https-server/index.html | 106 +- docs/en/tour/08-websocket/index.html | 166 +- docs/en/tour/09-whats-next/index.html | 250 ++- docs/en/tour/index.html | 10 +- docs/ja/cookbook/index.html | 10 +- docs/ja/index.html | 10 +- docs/ja/tour/01-getting-started/index.html | 78 +- docs/ja/tour/02-basic-client/index.html | 316 +-- docs/ja/tour/03-basic-server/index.html | 238 +- docs/ja/tour/04-static-file-server/index.html | 134 +- docs/ja/tour/05-tls-setup/index.html | 72 +- docs/ja/tour/06-https-client/index.html | 118 +- docs/ja/tour/07-https-server/index.html | 106 +- docs/ja/tour/08-websocket/index.html | 166 +- docs/ja/tour/09-whats-next/index.html | 250 ++- docs/ja/tour/index.html | 10 +- 45 files changed, 1540 insertions(+), 6054 deletions(-) delete mode 100644 docs-gen/Cargo.lock delete mode 100644 docs-gen/Cargo.toml delete mode 100644 docs-gen/README.md delete mode 100644 docs-gen/defaults/config.toml delete mode 100644 docs-gen/defaults/pages/en/index.md delete mode 100644 docs-gen/defaults/pages/ja/index.md delete mode 100644 docs-gen/defaults/static/css/main.css delete mode 100644 docs-gen/defaults/static/favicon.svg delete mode 100644 docs-gen/defaults/static/js/main.js delete mode 100644 docs-gen/defaults/templates/base.html delete mode 100644 docs-gen/defaults/templates/page.html delete mode 100644 docs-gen/defaults/templates/portal.html delete mode 100644 docs-gen/src/builder.rs delete mode 100644 docs-gen/src/config.rs delete mode 100644 docs-gen/src/defaults.rs delete mode 100644 docs-gen/src/main.rs delete mode 100644 docs-gen/src/markdown.rs delete mode 100644 docs-gen/src/serve.rs delete mode 100644 docs-gen/src/utils.rs diff --git a/docs-gen/Cargo.lock b/docs-gen/Cargo.lock deleted file mode 100644 index 4791b9b..0000000 --- a/docs-gen/Cargo.lock +++ /dev/null @@ -1,1992 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 4 - -[[package]] -name = "adler2" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" - -[[package]] -name = "aho-corasick" -version = "1.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" -dependencies = [ - "memchr", -] - -[[package]] -name = "android_system_properties" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" -dependencies = [ - "libc", -] - -[[package]] -name = "anstream" -version = "0.6.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a" -dependencies = [ - "anstyle", - "anstyle-parse", - "anstyle-query", - "anstyle-wincon", - "colorchoice", - "is_terminal_polyfill", - "utf8parse", -] - -[[package]] -name = "anstyle" -version = "1.0.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78" - -[[package]] -name = "anstyle-parse" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" -dependencies = [ - "utf8parse", -] - -[[package]] -name = "anstyle-query" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" -dependencies = [ - "windows-sys 0.61.2", -] - -[[package]] -name = "anstyle-wincon" -version = "3.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" -dependencies = [ - "anstyle", - "once_cell_polyfill", - "windows-sys 0.61.2", -] - -[[package]] -name = "anyhow" -version = "1.0.102" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" - -[[package]] -name = "ascii" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d92bec98840b8f03a5ff5413de5293bfcd8bf96467cf5452609f939ec6f5de16" - -[[package]] -name = "autocfg" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" - -[[package]] -name = "base64" -version = "0.22.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" - -[[package]] -name = "bincode" -version = "1.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" -dependencies = [ - "serde", -] - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "bitflags" -version = "2.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" - -[[package]] -name = "block-buffer" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" -dependencies = [ - "generic-array", -] - -[[package]] -name = "bstr" -version = "1.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63044e1ae8e69f3b5a92c736ca6269b8d12fa7efe39bf34ddb06d102cf0e2cab" -dependencies = [ - "memchr", - "serde", -] - -[[package]] -name = "bumpalo" -version = "3.20.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb" - -[[package]] -name = "byteorder" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" - -[[package]] -name = "bytes" -version = "1.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" - -[[package]] -name = "cc" -version = "1.2.56" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aebf35691d1bfb0ac386a69bac2fde4dd276fb618cf8bf4f5318fe285e821bb2" -dependencies = [ - "find-msvc-tools", - "shlex", -] - -[[package]] -name = "cfg-if" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" - -[[package]] -name = "chrono" -version = "0.4.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c673075a2e0e5f4a1dde27ce9dee1ea4558c7ffe648f576438a20ca1d2acc4b0" -dependencies = [ - "iana-time-zone", - "num-traits", - "windows-link", -] - -[[package]] -name = "chrono-tz" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93698b29de5e97ad0ae26447b344c482a7284c737d9ddc5f9e52b74a336671bb" -dependencies = [ - "chrono", - "chrono-tz-build", - "phf", -] - -[[package]] -name = "chrono-tz-build" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c088aee841df9c3041febbb73934cfc39708749bf96dc827e3359cd39ef11b1" -dependencies = [ - "parse-zoneinfo", - "phf", - "phf_codegen", -] - -[[package]] -name = "chunked_transfer" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e4de3bc4ea267985becf712dc6d9eed8b04c953b3fcfb339ebc87acd9804901" - -[[package]] -name = "clap" -version = "4.5.60" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2797f34da339ce31042b27d23607e051786132987f595b02ba4f6a6dffb7030a" -dependencies = [ - "clap_builder", - "clap_derive", -] - -[[package]] -name = "clap_builder" -version = "4.5.60" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24a241312cea5059b13574bb9b3861cabf758b879c15190b37b6d6fd63ab6876" -dependencies = [ - "anstream", - "anstyle", - "clap_lex", - "strsim", -] - -[[package]] -name = "clap_derive" -version = "4.5.55" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a92793da1a46a5f2a02a6f4c46c6496b28c43638adea8306fcb0caa1634f24e5" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "clap_lex" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a822ea5bc7590f9d40f1ba12c0dc3c2760f3482c6984db1573ad11031420831" - -[[package]] -name = "colorchoice" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - -[[package]] -name = "cpufeatures" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" -dependencies = [ - "libc", -] - -[[package]] -name = "crc32fast" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9481c1c90cbf2ac953f07c8d4a58aa3945c425b7185c9154d67a65e4230da511" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "crossbeam-deque" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" -dependencies = [ - "crossbeam-epoch", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.9.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" -dependencies = [ - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-utils" -version = "0.8.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" - -[[package]] -name = "crypto-common" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" -dependencies = [ - "generic-array", - "typenum", -] - -[[package]] -name = "data-encoding" -version = "2.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7a1e2f27636f116493b8b860f5546edb47c8d8f8ea73e1d2a20be88e28d1fea" - -[[package]] -name = "deranged" -version = "0.5.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c" -dependencies = [ - "powerfmt", -] - -[[package]] -name = "deunicode" -version = "1.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abd57806937c9cc163efc8ea3910e00a62e2aeb0b8119f1793a978088f8f6b04" - -[[package]] -name = "digest" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" -dependencies = [ - "block-buffer", - "crypto-common", -] - -[[package]] -name = "docs-gen" -version = "0.1.0" -dependencies = [ - "anyhow", - "clap", - "notify", - "open", - "pulldown-cmark", - "serde", - "serde_json", - "serde_yaml", - "socket2", - "syntect", - "tempfile", - "tera", - "tiny_http", - "toml", - "tungstenite", - "walkdir", -] - -[[package]] -name = "equivalent" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" - -[[package]] -name = "errno" -version = "0.3.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" -dependencies = [ - "libc", - "windows-sys 0.61.2", -] - -[[package]] -name = "fastrand" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" - -[[package]] -name = "filetime" -version = "0.2.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f98844151eee8917efc50bd9e8318cb963ae8b297431495d3f758616ea5c57db" -dependencies = [ - "cfg-if", - "libc", - "libredox", -] - -[[package]] -name = "find-msvc-tools" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" - -[[package]] -name = "flate2" -version = "1.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "843fba2746e448b37e26a819579957415c8cef339bf08564fe8b7ddbd959573c" -dependencies = [ - "crc32fast", - "miniz_oxide", -] - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "foldhash" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" - -[[package]] -name = "fsevent-sys" -version = "4.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76ee7a02da4d231650c7cea31349b889be2f45ddb3ef3032d2ec8185f6313fd2" -dependencies = [ - "libc", -] - -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", -] - -[[package]] -name = "getopts" -version = "0.2.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfe4fbac503b8d1f88e6676011885f34b7174f46e59956bba534ba83abded4df" -dependencies = [ - "unicode-width", -] - -[[package]] -name = "getrandom" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "getrandom" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "139ef39800118c7683f2fd3c98c1b23c09ae076556b435f8e9064ae108aaeeec" -dependencies = [ - "cfg-if", - "libc", - "r-efi", - "wasip2", - "wasip3", -] - -[[package]] -name = "globset" -version = "0.4.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52dfc19153a48bde0cbd630453615c8151bce3a5adfac7a0aebfbf0a1e1f57e3" -dependencies = [ - "aho-corasick", - "bstr", - "log", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "globwalk" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bf760ebf69878d9fd8f110c89703d90ce35095324d1f1edcb595c63945ee757" -dependencies = [ - "bitflags 2.11.0", - "ignore", - "walkdir", -] - -[[package]] -name = "hashbrown" -version = "0.15.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" -dependencies = [ - "foldhash", -] - -[[package]] -name = "hashbrown" -version = "0.16.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" - -[[package]] -name = "heck" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" - -[[package]] -name = "http" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3ba2a386d7f85a81f119ad7498ebe444d2e22c2af0b86b069416ace48b3311a" -dependencies = [ - "bytes", - "itoa", -] - -[[package]] -name = "httparse" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" - -[[package]] -name = "httpdate" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" - -[[package]] -name = "humansize" -version = "2.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6cb51c9a029ddc91b07a787f1d86b53ccfa49b0e86688c946ebe8d3555685dd7" -dependencies = [ - "libm", -] - -[[package]] -name = "iana-time-zone" -version = "0.1.65" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470" -dependencies = [ - "android_system_properties", - "core-foundation-sys", - "iana-time-zone-haiku", - "js-sys", - "log", - "wasm-bindgen", - "windows-core", -] - -[[package]] -name = "iana-time-zone-haiku" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" -dependencies = [ - "cc", -] - -[[package]] -name = "id-arena" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" - -[[package]] -name = "ignore" -version = "0.4.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3d782a365a015e0f5c04902246139249abf769125006fbe7649e2ee88169b4a" -dependencies = [ - "crossbeam-deque", - "globset", - "log", - "memchr", - "regex-automata", - "same-file", - "walkdir", - "winapi-util", -] - -[[package]] -name = "indexmap" -version = "2.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" -dependencies = [ - "equivalent", - "hashbrown 0.16.1", - "serde", - "serde_core", -] - -[[package]] -name = "inotify" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdd168d97690d0b8c412d6b6c10360277f4d7ee495c5d0d5d5fe0854923255cc" -dependencies = [ - "bitflags 1.3.2", - "inotify-sys", - "libc", -] - -[[package]] -name = "inotify-sys" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e05c02b5e89bff3b946cedeca278abc628fe811e604f027c45a8aa3cf793d0eb" -dependencies = [ - "libc", -] - -[[package]] -name = "instant" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "is-docker" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "928bae27f42bc99b60d9ac7334e3a21d10ad8f1835a4e12ec3ec0464765ed1b3" -dependencies = [ - "once_cell", -] - -[[package]] -name = "is-wsl" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "173609498df190136aa7dea1a91db051746d339e18476eed5ca40521f02d7aa5" -dependencies = [ - "is-docker", - "once_cell", -] - -[[package]] -name = "is_terminal_polyfill" -version = "1.70.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" - -[[package]] -name = "itoa" -version = "1.0.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" - -[[package]] -name = "js-sys" -version = "0.3.91" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b49715b7073f385ba4bc528e5747d02e66cb39c6146efb66b781f131f0fb399c" -dependencies = [ - "once_cell", - "wasm-bindgen", -] - -[[package]] -name = "kqueue" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac30106d7dce88daf4a3fcb4879ea939476d5074a9b7ddd0fb97fa4bed5596a" -dependencies = [ - "kqueue-sys", - "libc", -] - -[[package]] -name = "kqueue-sys" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed9625ffda8729b85e45cf04090035ac368927b8cebc34898e7c120f52e4838b" -dependencies = [ - "bitflags 1.3.2", - "libc", -] - -[[package]] -name = "lazy_static" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" - -[[package]] -name = "leb128fmt" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" - -[[package]] -name = "libc" -version = "0.2.182" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6800badb6cb2082ffd7b6a67e6125bb39f18782f793520caee8cb8846be06112" - -[[package]] -name = "libm" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981" - -[[package]] -name = "libredox" -version = "0.1.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1744e39d1d6a9948f4f388969627434e31128196de472883b39f148769bfe30a" -dependencies = [ - "bitflags 2.11.0", - "libc", - "plain", - "redox_syscall", -] - -[[package]] -name = "linked-hash-map" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" - -[[package]] -name = "linux-raw-sys" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" - -[[package]] -name = "log" -version = "0.4.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" - -[[package]] -name = "memchr" -version = "2.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" - -[[package]] -name = "miniz_oxide" -version = "0.8.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" -dependencies = [ - "adler2", - "simd-adler32", -] - -[[package]] -name = "mio" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a69bcab0ad47271a0234d9422b131806bf3968021e5dc9328caf2d4cd58557fc" -dependencies = [ - "libc", - "log", - "wasi", - "windows-sys 0.61.2", -] - -[[package]] -name = "notify" -version = "7.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c533b4c39709f9ba5005d8002048266593c1cfaf3c5f0739d5b8ab0c6c504009" -dependencies = [ - "bitflags 2.11.0", - "filetime", - "fsevent-sys", - "inotify", - "kqueue", - "libc", - "log", - "mio", - "notify-types", - "walkdir", - "windows-sys 0.52.0", -] - -[[package]] -name = "notify-types" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "585d3cb5e12e01aed9e8a1f70d5c6b5e86fe2a6e48fc8cd0b3e0b8df6f6eb174" -dependencies = [ - "instant", -] - -[[package]] -name = "num-conv" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf97ec579c3c42f953ef76dbf8d55ac91fb219dde70e49aa4a6b7d74e9919050" - -[[package]] -name = "num-traits" -version = "0.2.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" -dependencies = [ - "autocfg", -] - -[[package]] -name = "once_cell" -version = "1.21.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" - -[[package]] -name = "once_cell_polyfill" -version = "1.70.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" - -[[package]] -name = "onig" -version = "6.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "336b9c63443aceef14bea841b899035ae3abe89b7c486aaf4c5bd8aafedac3f0" -dependencies = [ - "bitflags 2.11.0", - "libc", - "once_cell", - "onig_sys", -] - -[[package]] -name = "onig_sys" -version = "69.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7f86c6eef3d6df15f23bcfb6af487cbd2fed4e5581d58d5bf1f5f8b7f6727dc" -dependencies = [ - "cc", - "pkg-config", -] - -[[package]] -name = "open" -version = "5.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43bb73a7fa3799b198970490a51174027ba0d4ec504b03cd08caf513d40024bc" -dependencies = [ - "is-wsl", - "libc", - "pathdiff", -] - -[[package]] -name = "parse-zoneinfo" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f2a05b18d44e2957b88f96ba460715e295bc1d7510468a2f3d3b44535d26c24" -dependencies = [ - "regex", -] - -[[package]] -name = "pathdiff" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3" - -[[package]] -name = "percent-encoding" -version = "2.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" - -[[package]] -name = "pest" -version = "2.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0848c601009d37dfa3430c4666e147e49cdcf1b92ecd3e63657d8a5f19da662" -dependencies = [ - "memchr", - "ucd-trie", -] - -[[package]] -name = "pest_derive" -version = "2.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11f486f1ea21e6c10ed15d5a7c77165d0ee443402f0780849d1768e7d9d6fe77" -dependencies = [ - "pest", - "pest_generator", -] - -[[package]] -name = "pest_generator" -version = "2.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8040c4647b13b210a963c1ed407c1ff4fdfa01c31d6d2a098218702e6664f94f" -dependencies = [ - "pest", - "pest_meta", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "pest_meta" -version = "2.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89815c69d36021a140146f26659a81d6c2afa33d216d736dd4be5381a7362220" -dependencies = [ - "pest", - "sha2", -] - -[[package]] -name = "phf" -version = "0.11.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd6780a80ae0c52cc120a26a1a42c1ae51b247a253e4e06113d23d2c2edd078" -dependencies = [ - "phf_shared", -] - -[[package]] -name = "phf_codegen" -version = "0.11.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aef8048c789fa5e851558d709946d6d79a8ff88c0440c587967f8e94bfb1216a" -dependencies = [ - "phf_generator", - "phf_shared", -] - -[[package]] -name = "phf_generator" -version = "0.11.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c80231409c20246a13fddb31776fb942c38553c51e871f8cbd687a4cfb5843d" -dependencies = [ - "phf_shared", - "rand", -] - -[[package]] -name = "phf_shared" -version = "0.11.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67eabc2ef2a60eb7faa00097bd1ffdb5bd28e62bf39990626a582201b7a754e5" -dependencies = [ - "siphasher", -] - -[[package]] -name = "pkg-config" -version = "0.3.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" - -[[package]] -name = "plain" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" - -[[package]] -name = "plist" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "740ebea15c5d1428f910cd1a5f52cebf8d25006245ed8ade92702f4943d91e07" -dependencies = [ - "base64", - "indexmap", - "quick-xml", - "serde", - "time", -] - -[[package]] -name = "powerfmt" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" - -[[package]] -name = "ppv-lite86" -version = "0.2.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" -dependencies = [ - "zerocopy", -] - -[[package]] -name = "prettyplease" -version = "0.2.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" -dependencies = [ - "proc-macro2", - "syn", -] - -[[package]] -name = "proc-macro2" -version = "1.0.106" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "pulldown-cmark" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f86ba2052aebccc42cbbb3ed234b8b13ce76f75c3551a303cb2bcffcff12bb14" -dependencies = [ - "bitflags 2.11.0", - "getopts", - "memchr", - "pulldown-cmark-escape", - "unicase", -] - -[[package]] -name = "pulldown-cmark-escape" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "007d8adb5ddab6f8e3f491ac63566a7d5002cc7ed73901f72057943fa71ae1ae" - -[[package]] -name = "quick-xml" -version = "0.38.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b66c2058c55a409d601666cffe35f04333cf1013010882cec174a7467cd4e21c" -dependencies = [ - "memchr", -] - -[[package]] -name = "quote" -version = "1.0.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "r-efi" -version = "5.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" - -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom 0.2.17", -] - -[[package]] -name = "redox_syscall" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ce70a74e890531977d37e532c34d45e9055d2409ed08ddba14529471ed0be16" -dependencies = [ - "bitflags 2.11.0", -] - -[[package]] -name = "regex" -version = "1.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.8.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a" - -[[package]] -name = "rustix" -version = "1.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" -dependencies = [ - "bitflags 2.11.0", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.61.2", -] - -[[package]] -name = "rustversion" -version = "1.0.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" - -[[package]] -name = "ryu" -version = "1.0.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" - -[[package]] -name = "same-file" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" -dependencies = [ - "winapi-util", -] - -[[package]] -name = "semver" -version = "1.0.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2" - -[[package]] -name = "serde" -version = "1.0.228" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" -dependencies = [ - "serde_core", - "serde_derive", -] - -[[package]] -name = "serde_core" -version = "1.0.228" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.228" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde_json" -version = "1.0.149" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" -dependencies = [ - "itoa", - "memchr", - "serde", - "serde_core", - "zmij", -] - -[[package]] -name = "serde_spanned" -version = "0.6.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf41e0cfaf7226dca15e8197172c295a782857fcb97fad1808a166870dee75a3" -dependencies = [ - "serde", -] - -[[package]] -name = "serde_yaml" -version = "0.9.34+deprecated" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" -dependencies = [ - "indexmap", - "itoa", - "ryu", - "serde", - "unsafe-libyaml", -] - -[[package]] -name = "sha1" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "sha2" -version = "0.10.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "shlex" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" - -[[package]] -name = "simd-adler32" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e320a6c5ad31d271ad523dcf3ad13e2767ad8b1cb8f047f75a8aeaf8da139da2" - -[[package]] -name = "siphasher" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2aa850e253778c88a04c3d7323b043aeda9d3e30d5971937c1855769763678e" - -[[package]] -name = "slug" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "882a80f72ee45de3cc9a5afeb2da0331d58df69e4e7d8eeb5d3c7784ae67e724" -dependencies = [ - "deunicode", - "wasm-bindgen", -] - -[[package]] -name = "socket2" -version = "0.5.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e22376abed350d73dd1cd119b57ffccad95b4e585a7cda43e286245ce23c0678" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "strsim" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" - -[[package]] -name = "syn" -version = "2.0.117" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syntect" -version = "5.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "656b45c05d95a5704399aeef6bd0ddec7b2b3531b7c9e900abbf7c4d2190c925" -dependencies = [ - "bincode", - "flate2", - "fnv", - "once_cell", - "onig", - "plist", - "regex-syntax", - "serde", - "serde_derive", - "serde_json", - "thiserror 2.0.18", - "walkdir", - "yaml-rust", -] - -[[package]] -name = "tempfile" -version = "3.26.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82a72c767771b47409d2345987fda8628641887d5466101319899796367354a0" -dependencies = [ - "fastrand", - "getrandom 0.4.1", - "once_cell", - "rustix", - "windows-sys 0.61.2", -] - -[[package]] -name = "tera" -version = "1.20.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8004bca281f2d32df3bacd59bc67b312cb4c70cea46cbd79dbe8ac5ed206722" -dependencies = [ - "chrono", - "chrono-tz", - "globwalk", - "humansize", - "lazy_static", - "percent-encoding", - "pest", - "pest_derive", - "rand", - "regex", - "serde", - "serde_json", - "slug", - "unicode-segmentation", -] - -[[package]] -name = "thiserror" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" -dependencies = [ - "thiserror-impl 1.0.69", -] - -[[package]] -name = "thiserror" -version = "2.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" -dependencies = [ - "thiserror-impl 2.0.18", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "thiserror-impl" -version = "2.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "time" -version = "0.3.47" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "743bd48c283afc0388f9b8827b976905fb217ad9e647fae3a379a9283c4def2c" -dependencies = [ - "deranged", - "itoa", - "num-conv", - "powerfmt", - "serde_core", - "time-core", - "time-macros", -] - -[[package]] -name = "time-core" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7694e1cfe791f8d31026952abf09c69ca6f6fa4e1a1229e18988f06a04a12dca" - -[[package]] -name = "time-macros" -version = "0.2.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e70e4c5a0e0a8a4823ad65dfe1a6930e4f4d756dcd9dd7939022b5e8c501215" -dependencies = [ - "num-conv", - "time-core", -] - -[[package]] -name = "tiny_http" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "389915df6413a2e74fb181895f933386023c71110878cd0825588928e64cdc82" -dependencies = [ - "ascii", - "chunked_transfer", - "httpdate", - "log", -] - -[[package]] -name = "toml" -version = "0.8.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362" -dependencies = [ - "serde", - "serde_spanned", - "toml_datetime", - "toml_edit", -] - -[[package]] -name = "toml_datetime" -version = "0.6.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c" -dependencies = [ - "serde", -] - -[[package]] -name = "toml_edit" -version = "0.22.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" -dependencies = [ - "indexmap", - "serde", - "serde_spanned", - "toml_datetime", - "toml_write", - "winnow", -] - -[[package]] -name = "toml_write" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801" - -[[package]] -name = "tungstenite" -version = "0.24.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18e5b8366ee7a95b16d32197d0b2604b43a0be89dc5fac9f8e96ccafbaedda8a" -dependencies = [ - "byteorder", - "bytes", - "data-encoding", - "http", - "httparse", - "log", - "rand", - "sha1", - "thiserror 1.0.69", - "utf-8", -] - -[[package]] -name = "typenum" -version = "1.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" - -[[package]] -name = "ucd-trie" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971" - -[[package]] -name = "unicase" -version = "2.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbc4bc3a9f746d862c45cb89d705aa10f187bb96c76001afab07a0d35ce60142" - -[[package]] -name = "unicode-ident" -version = "1.0.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" - -[[package]] -name = "unicode-segmentation" -version = "1.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" - -[[package]] -name = "unicode-width" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254" - -[[package]] -name = "unicode-xid" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" - -[[package]] -name = "unsafe-libyaml" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" - -[[package]] -name = "utf-8" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" - -[[package]] -name = "utf8parse" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" - -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - -[[package]] -name = "walkdir" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" -dependencies = [ - "same-file", - "winapi-util", -] - -[[package]] -name = "wasi" -version = "0.11.1+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" - -[[package]] -name = "wasip2" -version = "1.0.2+wasi-0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9517f9239f02c069db75e65f174b3da828fe5f5b945c4dd26bd25d89c03ebcf5" -dependencies = [ - "wit-bindgen", -] - -[[package]] -name = "wasip3" -version = "0.4.0+wasi-0.3.0-rc-2026-01-06" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5" -dependencies = [ - "wit-bindgen", -] - -[[package]] -name = "wasm-bindgen" -version = "0.2.114" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6532f9a5c1ece3798cb1c2cfdba640b9b3ba884f5db45973a6f442510a87d38e" -dependencies = [ - "cfg-if", - "once_cell", - "rustversion", - "wasm-bindgen-macro", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.114" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18a2d50fcf105fb33bb15f00e7a77b772945a2ee45dcf454961fd843e74c18e6" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.114" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03ce4caeaac547cdf713d280eda22a730824dd11e6b8c3ca9e42247b25c631e3" -dependencies = [ - "bumpalo", - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.114" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75a326b8c223ee17883a4251907455a2431acc2791c98c26279376490c378c16" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "wasm-encoder" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319" -dependencies = [ - "leb128fmt", - "wasmparser", -] - -[[package]] -name = "wasm-metadata" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909" -dependencies = [ - "anyhow", - "indexmap", - "wasm-encoder", - "wasmparser", -] - -[[package]] -name = "wasmparser" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" -dependencies = [ - "bitflags 2.11.0", - "hashbrown 0.15.5", - "indexmap", - "semver", -] - -[[package]] -name = "winapi-util" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" -dependencies = [ - "windows-sys 0.61.2", -] - -[[package]] -name = "windows-core" -version = "0.62.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" -dependencies = [ - "windows-implement", - "windows-interface", - "windows-link", - "windows-result", - "windows-strings", -] - -[[package]] -name = "windows-implement" -version = "0.60.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "windows-interface" -version = "0.59.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "windows-link" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" - -[[package]] -name = "windows-result" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" -dependencies = [ - "windows-link", -] - -[[package]] -name = "windows-strings" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" -dependencies = [ - "windows-link", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-sys" -version = "0.61.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" -dependencies = [ - "windows-link", -] - -[[package]] -name = "windows-targets" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" - -[[package]] -name = "winnow" -version = "0.7.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a5364e9d77fcdeeaa6062ced926ee3381faa2ee02d3eb83a5c27a8825540829" -dependencies = [ - "memchr", -] - -[[package]] -name = "wit-bindgen" -version = "0.51.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" -dependencies = [ - "wit-bindgen-rust-macro", -] - -[[package]] -name = "wit-bindgen-core" -version = "0.51.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc" -dependencies = [ - "anyhow", - "heck", - "wit-parser", -] - -[[package]] -name = "wit-bindgen-rust" -version = "0.51.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21" -dependencies = [ - "anyhow", - "heck", - "indexmap", - "prettyplease", - "syn", - "wasm-metadata", - "wit-bindgen-core", - "wit-component", -] - -[[package]] -name = "wit-bindgen-rust-macro" -version = "0.51.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a" -dependencies = [ - "anyhow", - "prettyplease", - "proc-macro2", - "quote", - "syn", - "wit-bindgen-core", - "wit-bindgen-rust", -] - -[[package]] -name = "wit-component" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" -dependencies = [ - "anyhow", - "bitflags 2.11.0", - "indexmap", - "log", - "serde", - "serde_derive", - "serde_json", - "wasm-encoder", - "wasm-metadata", - "wasmparser", - "wit-parser", -] - -[[package]] -name = "wit-parser" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736" -dependencies = [ - "anyhow", - "id-arena", - "indexmap", - "log", - "semver", - "serde", - "serde_derive", - "serde_json", - "unicode-xid", - "wasmparser", -] - -[[package]] -name = "yaml-rust" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" -dependencies = [ - "linked-hash-map", -] - -[[package]] -name = "zerocopy" -version = "0.8.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a789c6e490b576db9f7e6b6d661bcc9799f7c0ac8352f56ea20193b2681532e5" -dependencies = [ - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.8.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f65c489a7071a749c849713807783f70672b28094011623e200cb86dcb835953" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "zmij" -version = "1.0.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" diff --git a/docs-gen/Cargo.toml b/docs-gen/Cargo.toml deleted file mode 100644 index 36d6fba..0000000 --- a/docs-gen/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -name = "docs-gen" -version = "0.1.0" -edition = "2021" - -[dependencies] -pulldown-cmark = "0.12" -tera = "1" -walkdir = "2" -serde = { version = "1", features = ["derive"] } -serde_json = "1" -serde_yaml = "0.9" -toml = "0.8" -syntect = "5" -anyhow = "1" -clap = { version = "4", features = ["derive"] } -notify = "7" -tiny_http = "0.12" -tungstenite = "0.24" -open = "5" -tempfile = "3" -socket2 = { version = "0.5", features = ["all"] } diff --git a/docs-gen/README.md b/docs-gen/README.md deleted file mode 100644 index 9a0e67a..0000000 --- a/docs-gen/README.md +++ /dev/null @@ -1,254 +0,0 @@ -# docs-gen - -A static site generator for multi-language documentation. Markdown content, Tera templates, and syntax highlighting — all in a single binary. - -## Quick Start - -```bash -# 1. Scaffold a new project -docs-gen init my-docs - -# 2. Start the local dev server with live-reload -docs-gen serve my-docs --open - -# 3. Build for production -docs-gen build my-docs --out docs -``` - ---- - -## Commands - -### `init [DIR]` - -Creates a new project scaffold in `DIR` (default: `.`). - -Generated files: - -``` -config.toml -pages/ - en/index.md - ja/index.md -templates/ - base.html - page.html - portal.html -static/ - css/main.css - js/main.js -``` - -Existing files are never overwritten. - ---- - -### `serve [SRC] [--port PORT] [--open]` - -Builds the site into a temporary directory and serves it locally. Watches for changes and live-reloads the browser automatically. - -| Option | Default | Description | -|--------|---------|-------------| -| `SRC` | `.` | Source directory | -| `--port` | `8080` | HTTP server port | -| `--open` | — | Open browser on startup | - ---- - -### `build [SRC] [--out OUT]` - -Generates the static site from source. - -| Option | Default | Description | -|--------|---------|-------------| -| `SRC` | `.` | Source directory | -| `--out` | `docs` | Output directory | - ---- - -## Source Directory Structure - -Only `config.toml` and `pages/` are required. `templates/` and `static/` are optional — when absent, built-in defaults are used automatically. - -``` -my-docs/ -├── config.toml # Site configuration (required) -├── pages/ # Markdown content (required) -│ ├── en/ -│ │ ├── index.md # Portal page (homepage, no sidebar) -│ │ └── guide/ -│ │ ├── index.md # Section index -│ │ ├── 01-intro.md -│ │ └── 02-usage.md -│ └── ja/ -│ └── ... -├── templates/ # Override built-in HTML templates (optional) -│ ├── base.html -│ ├── page.html -│ └── portal.html -└── static/ # Override built-in CSS/JS/assets (optional) - ├── css/main.css - └── js/main.js -``` - ---- - -## config.toml - -```toml -[site] -title = "My Project" -version = "1.0.0" # Optional. Shown in header. -hostname = "https://example.github.io" # Optional. Combined with base_path for full URLs. -base_path = "/my-project" # URL prefix. Use "" for local-only. - -[[nav]] -label = "Guide" -path = "guide/" # Internal section path (resolved per language) -icon_svg = '...' # Optional inline SVG icon - -[[nav]] -label = "GitHub" -url = "https://github.com/your/repo" # External URL -icon_svg = '...' - -[i18n] -langs = ["en", "ja"] # First entry is the default language - -[highlight] -dark_theme = "base16-eighties.dark" # Dark mode theme -light_theme = "InspiredGitHub" # Light mode theme (optional) -``` - -### `[site]` - -| Key | Required | Description | -|-----|----------|-------------| -| `title` | yes | Site title displayed in the header | -| `version` | no | Version string displayed in the header | -| `hostname` | no | Base hostname (e.g. `"https://user.github.io"`). Combined with `base_path` to form `site.base_url` in templates. | -| `base_path` | no | URL path prefix. Use `"/repo-name"` for GitHub Pages, `""` for local development. | - -### `[[nav]]` — Toolbar Buttons - -Defines buttons in the site header. Each entry supports: - -| Key | Required | Description | -|-----|----------|-------------| -| `label` | yes | Button label text | -| `path` | no | Internal section path relative to `/` (e.g. `"guide/"`). Resolved using the current language. | -| `url` | no | Absolute external URL. Takes precedence over `path` if both are set. | -| `icon_svg` | no | Inline SVG markup displayed as an icon | - -### `[i18n]` - -| Key | Required | Description | -|-----|----------|-------------| -| `langs` | yes | List of language codes. At least one is required. The first entry is used as the default language. | - -### `[highlight]` - -| Key | Default | Description | -|-----|---------|-------------| -| `dark_theme` | `base16-ocean.dark` | Theme for dark mode | -| `light_theme` | _(none)_ | Theme for light mode. When set, both dark and light code blocks are emitted and toggled via CSS. | - -Available themes: `base16-ocean.dark`, `base16-ocean.light`, `base16-eighties.dark`, `base16-mocha.dark`, `InspiredGitHub`, `Solarized (dark)`, `Solarized (light)`. - ---- - -## Writing Pages - -### Frontmatter - -Every `.md` file must begin with YAML frontmatter: - -```yaml ---- -title: "Getting Started" -order: 1 ---- - -Page content goes here... -``` - -| Field | Required | Description | -|-------|----------|-------------| -| `title` | yes | Page title shown in the heading and browser tab | -| `order` | no | Sort order within the section (default: `0`) | -| `status` | no | Set to `"draft"` to display a DRAFT banner | - -### URL Routing - -Files are mapped to URLs as follows: - -| File | URL | -|------|-----| -| `en/index.md` | `/en/` | -| `en/guide/index.md` | `/en/guide/` | -| `en/guide/01-intro.md` | `/en/guide/01-intro/` | - -The root `index.html` is generated automatically and redirects to the default language, respecting the user's `localStorage` language preference. - -### Sidebar Navigation - -Sidebar navigation is generated automatically: - -- Each subdirectory under a language becomes a **section** -- The section's `index.md` title is used as the section heading -- Pages within a section are sorted by `order`, then by filename -- `index.md` at the language root uses `portal.html` (no sidebar) -- All other pages use `page.html` (with sidebar) - ---- - -## Customizing Templates and Assets - -When `templates/` or `static/` directories exist in the source, files there override the built-in defaults. Use `docs-gen init` to generate the defaults as a starting point. - -Three templates are available: - -| Template | Used for | -|----------|----------| -| `base.html` | Shared layout: ``, header, footer, scripts | -| `page.html` | Content pages with sidebar | -| `portal.html` | Homepage (`index.md` at language root), no sidebar | - ---- - -## Template Variables - -Templates use [Tera](https://keats.github.io/tera/) syntax. Available variables: - -### All templates - -| Variable | Type | Description | -|----------|------|-------------| -| `page.title` | string | Page title from frontmatter | -| `page.url` | string | Page URL path | -| `page.status` | string? | `"draft"` or null | -| `content` | string | Rendered HTML (use `{{ content \| safe }}`) | -| `lang` | string | Current language code | -| `site.title` | string | Site title | -| `site.version` | string? | Site version | -| `site.base_url` | string | Full base URL (`hostname` + `base_path`) | -| `site.base_path` | string | URL path prefix | -| `site.langs` | list | All language codes | -| `site.nav` | list | Toolbar button entries | -| `site.nav[].label` | string | Button label | -| `site.nav[].url` | string? | External URL (if set) | -| `site.nav[].path` | string? | Internal section path (if set) | -| `site.nav[].icon_svg` | string? | Inline SVG icon (if set) | - -### `page.html` only - -| Variable | Type | Description | -|----------|------|-------------| -| `nav` | list | Sidebar sections | -| `nav[].title` | string | Section title | -| `nav[].url` | string | Section index URL | -| `nav[].active` | bool | True if this section contains the current page | -| `nav[].children` | list | Pages within this section | -| `nav[].children[].title` | string | Page title | -| `nav[].children[].url` | string | Page URL | -| `nav[].children[].active` | bool | True if this is the current page | diff --git a/docs-gen/defaults/config.toml b/docs-gen/defaults/config.toml deleted file mode 100644 index fc5fccf..0000000 --- a/docs-gen/defaults/config.toml +++ /dev/null @@ -1,20 +0,0 @@ -[site] -title = "My Docs" -hostname = "https://example.github.io" -base_path = "/my-project" - -# [[nav]] -# label = "Guide" -# path = "guide/" -# -# [[nav]] -# label = "GitHub" -# url = "https://github.com/your/repo" -# icon_svg = '' - -[i18n] -langs = ["en"] - -[highlight] -dark_theme = "base16-ocean.dark" -light_theme = "InspiredGitHub" diff --git a/docs-gen/defaults/pages/en/index.md b/docs-gen/defaults/pages/en/index.md deleted file mode 100644 index 858230b..0000000 --- a/docs-gen/defaults/pages/en/index.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: Welcome -order: 0 ---- - -## Welcome - -This is the home page of your documentation site. - -Edit this file at `pages/en/index.md` to get started. diff --git a/docs-gen/defaults/pages/ja/index.md b/docs-gen/defaults/pages/ja/index.md deleted file mode 100644 index 3c792c0..0000000 --- a/docs-gen/defaults/pages/ja/index.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: ようこそ -order: 0 ---- - -## ようこそ - -ドキュメントサイトのトップページです。 - -`pages/ja/index.md` を編集して始めましょう。 diff --git a/docs-gen/defaults/static/css/main.css b/docs-gen/defaults/static/css/main.css deleted file mode 100644 index 91ecdc9..0000000 --- a/docs-gen/defaults/static/css/main.css +++ /dev/null @@ -1,603 +0,0 @@ -:root { - --bg: #333; - --bg-secondary: #3c3c3c; - --bg-code: #2a2a2a; - --text: #ccc; - --text-bright: white; - --text-muted: #999; - --text-code: #b0b0b0; - --text-inline-code: plum; - --border: #555; - --border-code: #3a3a3a; - --link: palegoldenrod; - --heading: lightskyblue; - --heading-link: #f0c090; - --header-nav-link: pink; - --emphasis: pink; - --nav-section: #bbb; - --nav-section-active: #ddd; - --content-width: 900px; - --sidebar-width: 280px; - --header-height: 48px; - --line-height: 1.6; -} - -* { - margin: 0; - padding: 0; - box-sizing: border-box; -} - -body { - background-color: var(--bg); - color: var(--text); - font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; - line-height: var(--line-height); -} - -a { - color: var(--link); - text-decoration: none; -} - -a:hover { - text-decoration: underline; -} - -/* Header */ -.header { - position: fixed; - top: 0; - left: 0; - right: 0; - height: var(--header-height); - background-color: var(--bg-secondary); - border-bottom: 1px solid var(--border); - z-index: 100; -} - -.header-inner { - height: 100%; - display: flex; - align-items: center; - padding: 0 16px; - gap: 24px; -} - -.header-title { - color: var(--text); - font-weight: bold; - font-size: 1.1rem; - white-space: nowrap; -} - -.header-title:hover { - text-decoration: none; - color: var(--text-bright); -} - -.header-spacer { - flex: 1; -} - -.header-nav { - display: flex; - gap: 16px; -} - -.header-nav a { - display: flex; - align-items: center; - gap: 4px; - color: var(--header-nav-link); - font-size: 0.9rem; -} - -.header-nav a svg { - flex-shrink: 0; - opacity: 0.85; -} - -.header-tools { - display: flex; - align-items: center; - gap: 2px; -} - -.lang-selector { - position: relative; -} - -.lang-btn { - display: flex; - align-items: center; - gap: 5px; - background: none; - border: none; - color: var(--text); - padding: 4px 6px; - border-radius: 4px; - cursor: pointer; - font-size: 0.85rem; - opacity: 0.8; -} - -.lang-btn:hover { - opacity: 1; -} - -.lang-popup { - display: none; - position: absolute; - right: 0; - top: 100%; - margin-top: 4px; - background: var(--bg-secondary); - border: 1px solid var(--border); - border-radius: 4px; - list-style: none; - min-width: 60px; - z-index: 200; -} - -.lang-popup.open { - display: block; -} - -.lang-popup li a { - display: block; - padding: 6px 12px; - color: var(--text); - font-size: 0.85rem; -} - -.lang-popup li a:hover { - background: var(--bg); - text-decoration: none; -} - -.sidebar-toggle { - display: none; - background: none; - border: none; - color: var(--text); - font-size: 1.2rem; - cursor: pointer; - padding: 4px 8px; -} - -/* Draft banner */ -.draft-banner { - position: fixed; - top: var(--header-height); - right: 0; - background: #c44; - color: white; - padding: 4px 16px; - font-size: 0.75rem; - font-weight: bold; - letter-spacing: 0.1em; - z-index: 99; -} - -/* Layout */ -.layout { - margin-top: var(--header-height); - display: grid; - grid-template-columns: var(--sidebar-width) minmax(0, 1fr); - min-height: calc(100vh - var(--header-height)); -} - -.layout.no-sidebar { - grid-template-columns: 1fr; -} - -/* Sidebar */ -.sidebar { - width: var(--sidebar-width); - flex-shrink: 0; - padding: 24px 16px; - border-right: 1px solid var(--bg-secondary); - position: sticky; - top: var(--header-height); - height: calc(100vh - var(--header-height)); - overflow-y: auto; -} - -.nav-section { - margin-bottom: 16px; -} - -.nav-section-title { - color: var(--nav-section); - font-weight: bold; - font-size: 1.0rem; - display: block; - margin-bottom: 8px; -} - -.nav-section-title.active { - color: var(--nav-section-active); -} - -.nav-list { - list-style: none; - padding-left: 8px; -} - -.nav-list li { - margin-bottom: 4px; -} - -.nav-list li a { - color: var(--text-muted); - font-size: 0.85rem; -} - -.nav-list li a:hover { - color: var(--text); -} - -.nav-list li a.active { - color: var(--emphasis); - font-weight: bold; -} - -/* Content */ -.content { - min-width: 0; - max-width: var(--content-width); - padding: 32px 24px; - overflow-wrap: break-word; -} - -.content.portal { - max-width: var(--content-width); - padding: 48px 24px; - margin: 0 auto; -} - -.content article h1 { - font-size: 1.8rem; - margin-bottom: 24px; - color: var(--heading); -} - -.content article h2 { - font-size: 1.4rem; - margin-top: 32px; - margin-bottom: 16px; - color: var(--heading-link); -} - -.content article h3 { - font-size: 1.1rem; - margin-top: 24px; - margin-bottom: 12px; - color: var(--text); -} - -.content article p { - margin-bottom: 12px; -} - -.content article ul, -.content article ol { - margin-bottom: 12px; - padding-left: 24px; -} - -.content article li { - margin-bottom: 4px; -} - -.content article strong { - color: var(--emphasis); -} - -.content article code { - background: var(--bg-code); - color: var(--text-inline-code); - padding: 2px 6px; - border-radius: 3px; - font-size: 0.9em; -} - -.content article pre { - background: var(--bg-code); - color: var(--text-code); - padding: 16px; - border-radius: 4px; - overflow-x: auto; - margin-bottom: 16px; - border: 1px solid var(--border-code); -} - -.content article pre code { - background: none; - padding: 0; -} - -.content article table { - width: 100%; - border-collapse: collapse; - margin-bottom: 16px; -} - -.content article th, -.content article td { - border: 1px solid var(--bg-secondary); - padding: 8px 12px; - text-align: left; -} - -.content article th { - background: var(--bg-secondary); -} - -.content article blockquote { - border-left: 3px solid var(--text-muted); - padding-left: 16px; - margin-bottom: 12px; - color: var(--text-muted); -} - -/* Code block theme switching: show dark by default, swap on light mode */ -.code-block-wrapper > [data-code-theme="light"] { - display: none; -} - -html[data-theme="light"] .code-block-wrapper > [data-code-theme="dark"] { - display: none; -} - -html[data-theme="light"] .code-block-wrapper > [data-code-theme="light"] { - display: block; -} - -/* Footer */ -.footer { - padding: 12px 16px; - text-align: center; - color: var(--text-muted); - font-size: 0.8rem; - border-top: 1px solid var(--bg-secondary); -} - -/* Responsive */ -@media (max-width: 768px) { - .layout { - grid-template-columns: minmax(0, 1fr); - } - - .sidebar { - position: fixed; - left: calc(-1 * var(--sidebar-width)); - width: var(--sidebar-width); - top: var(--header-height); - height: calc(100vh - var(--header-height)); - background: var(--bg); - z-index: 50; - transition: left 0.2s ease; - border-right: 1px solid var(--border); - } - - .sidebar.open { - left: 0; - } - - .sidebar-toggle { - display: block; - } - - .content { - padding: 24px 16px; - } -} - -@media (max-width: 480px) { - :root { - --header-height: 44px; - } - - .header-inner { - padding: 0 12px; - gap: 12px; - } - - .header-nav a { - font-size: 0.8rem; - } - - .content article h1 { - font-size: 1.4rem; - } - - .content article h2 { - font-size: 1.2rem; - } -} - -/* Light mode */ -[data-theme="light"] { - --bg: #f5f5f5; - --bg-secondary: #e8e8e8; - --bg-code: #eee; - --text: #333; - --text-bright: #000; - --text-muted: #666; - --text-code: #333; - --text-inline-code: #8b5ca0; - --border: #ccc; - --border-code: #ddd; - --link: #b8860b; - --heading: #2a6496; - --heading-link: #c06020; - --header-nav-link: #c04060; - --emphasis: #c04060; - --nav-section: #666; - --nav-section-active: #333; -} - -/* Theme toggle */ -.theme-toggle { - display: flex; - align-items: center; - justify-content: center; - background: none; - border: none; - color: var(--text); - padding: 5px 6px; - border-radius: 4px; - cursor: pointer; - opacity: 0.8; -} - -.theme-toggle:hover { - opacity: 1; -} - -/* Search button */ -.search-btn { - display: flex; - align-items: center; - justify-content: center; - background: none; - border: none; - color: var(--text); - padding: 5px 6px; - border-radius: 4px; - cursor: pointer; - opacity: 0.8; -} - -.search-btn:hover { - opacity: 1; -} - -/* Search overlay & modal */ -.search-overlay { - display: none; - position: fixed; - inset: 0; - background: rgba(0, 0, 0, 0.5); - z-index: 300; - justify-content: center; - align-items: flex-start; - padding-top: 12vh; -} - -.search-overlay.open { - display: flex; -} - -.search-modal { - background: var(--bg-secondary); - border: 1px solid var(--border); - border-radius: 8px; - width: 90%; - max-width: 560px; - box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4); - overflow: hidden; -} - -.search-input-wrap { - display: flex; - align-items: center; - gap: 8px; - padding: 12px 16px; - border-bottom: 1px solid var(--border); -} - -.search-input-wrap svg { - flex-shrink: 0; - opacity: 0.5; -} - -#search-input { - flex: 1; - background: none; - border: none; - outline: none; - color: var(--text-bright); - font-size: 1rem; - font-family: inherit; -} - -#search-input::placeholder { - color: var(--text-muted); -} - -.search-esc { - background: var(--bg); - color: var(--text-muted); - padding: 2px 6px; - border-radius: 3px; - font-size: 0.7rem; - border: 1px solid var(--border); -} - -.search-results { - list-style: none; - max-height: 50vh; - overflow-y: auto; - padding: 0; - margin: 0; -} - -.search-results:empty::after { - content: ""; - display: none; -} - -.search-results li { - padding: 10px 16px; - cursor: pointer; - border-bottom: 1px solid var(--border); -} - -.search-results li:last-child { - border-bottom: none; -} - -.search-results li:hover, -.search-results li.active { - background: var(--bg); -} - -.search-results li .search-result-title { - color: var(--text-bright); - font-weight: 600; - font-size: 0.9rem; - margin-bottom: 2px; -} - -.search-results li .search-result-snippet { - color: var(--text-muted); - font-size: 0.8rem; - line-height: 1.4; - overflow: hidden; - text-overflow: ellipsis; - display: -webkit-box; - -webkit-line-clamp: 2; - -webkit-box-orient: vertical; -} - -.search-results li .search-result-snippet mark { - background: rgba(255, 215, 0, 0.3); - color: var(--text-bright); - border-radius: 2px; - padding: 0 1px; -} - -[data-theme="light"] .search-results li .search-result-snippet mark { - background: rgba(255, 200, 0, 0.4); - color: var(--text); -} - -.search-no-results { - padding: 24px 16px; - text-align: center; - color: var(--text-muted); - font-size: 0.9rem; -} diff --git a/docs-gen/defaults/static/favicon.svg b/docs-gen/defaults/static/favicon.svg deleted file mode 100644 index 9e824c2..0000000 --- a/docs-gen/defaults/static/favicon.svg +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/docs-gen/defaults/static/js/main.js b/docs-gen/defaults/static/js/main.js deleted file mode 100644 index 0f2a89f..0000000 --- a/docs-gen/defaults/static/js/main.js +++ /dev/null @@ -1,297 +0,0 @@ -// Language selector -(function () { - var btn = document.querySelector('.lang-btn'); - var popup = document.querySelector('.lang-popup'); - if (!btn || !popup) return; - - btn.addEventListener('click', function (e) { - e.stopPropagation(); - popup.classList.toggle('open'); - }); - - document.addEventListener('click', function () { - popup.classList.remove('open'); - }); - - popup.addEventListener('click', function (e) { - var link = e.target.closest('[data-lang]'); - if (!link) return; - e.preventDefault(); - var lang = link.getAttribute('data-lang'); - localStorage.setItem('preferred-lang', lang); - var basePath = document.documentElement.getAttribute('data-base-path') || ''; - var path = window.location.pathname; - // Strip base path prefix, replace lang, then re-add base path - var pathWithoutBase = path.slice(basePath.length); - var newPath = basePath + pathWithoutBase.replace(/^\/[a-z]{2}\//, '/' + lang + '/'); - window.location.href = newPath; - }); -})(); - -// Theme toggle -(function () { - var btn = document.querySelector('.theme-toggle'); - if (!btn) return; - - // Feather Icons: sun (light mode) and moon (dark mode) - var sunSVG = ''; - var moonSVG = ''; - - function getTheme() { - var stored = localStorage.getItem('preferred-theme'); - if (stored) return stored; - return window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark'; - } - - function applyTheme(theme) { - if (theme === 'light') { - document.documentElement.setAttribute('data-theme', 'light'); - } else { - document.documentElement.removeAttribute('data-theme'); - } - btn.innerHTML = theme === 'light' ? sunSVG : moonSVG; - } - - applyTheme(getTheme()); - - btn.addEventListener('click', function () { - var current = getTheme(); - var next = current === 'dark' ? 'light' : 'dark'; - localStorage.setItem('preferred-theme', next); - applyTheme(next); - }); -})(); - -// Mobile sidebar toggle -(function () { - var toggle = document.querySelector('.sidebar-toggle'); - var sidebar = document.querySelector('.sidebar'); - if (!toggle || !sidebar) return; - - toggle.addEventListener('click', function () { - sidebar.classList.toggle('open'); - }); - - document.addEventListener('click', function (e) { - if (!sidebar.contains(e.target) && e.target !== toggle) { - sidebar.classList.remove('open'); - } - }); -})(); - -// Site search (⌘K / Ctrl+K) -(function () { - var overlay = document.getElementById('search-overlay'); - var input = document.getElementById('search-input'); - var resultsList = document.getElementById('search-results'); - if (!overlay || !input || !resultsList) return; - - var searchBtn = document.querySelector('.search-btn'); - var pagesData = null; // cached pages-data.json - var activeIndex = -1; - - function getCurrentLang() { - return document.documentElement.getAttribute('lang') || 'en'; - } - - function getBasePath() { - return document.documentElement.getAttribute('data-base-path') || ''; - } - - function openSearch() { - overlay.classList.add('open'); - input.value = ''; - resultsList.innerHTML = ''; - activeIndex = -1; - input.focus(); - loadPagesData(); - } - - function closeSearch() { - overlay.classList.remove('open'); - input.value = ''; - resultsList.innerHTML = ''; - activeIndex = -1; - } - - function loadPagesData() { - if (pagesData) return; - var basePath = getBasePath(); - fetch(basePath + '/pages-data.json') - .then(function (res) { return res.json(); }) - .then(function (data) { pagesData = data; }) - .catch(function () { pagesData = []; }); - } - - function escapeRegExp(s) { - return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); - } - - function highlightText(text, query) { - if (!query) return text; - var escaped = escapeRegExp(query); - var re = new RegExp('(' + escaped + ')', 'gi'); - return text.replace(re, '$1'); - } - - function buildSnippet(body, query) { - if (!query || !body) return ''; - var lower = body.toLowerCase(); - var idx = lower.indexOf(query.toLowerCase()); - var start, end, snippet; - if (idx === -1) { - snippet = body.substring(0, 120); - } else { - start = Math.max(0, idx - 40); - end = Math.min(body.length, idx + query.length + 80); - snippet = (start > 0 ? '...' : '') + body.substring(start, end) + (end < body.length ? '...' : ''); - } - return highlightText(snippet, query); - } - - function search(query) { - if (!pagesData || !query) { - resultsList.innerHTML = ''; - activeIndex = -1; - return; - } - - var lang = getCurrentLang(); - var q = query.toLowerCase(); - - // Score and filter - var scored = []; - for (var i = 0; i < pagesData.length; i++) { - var page = pagesData[i]; - if (page.lang !== lang) continue; - - var score = 0; - var titleLower = page.title.toLowerCase(); - var bodyLower = (page.body || '').toLowerCase(); - - if (titleLower.indexOf(q) !== -1) { - score += 10; - // Bonus for exact title match - if (titleLower === q) score += 5; - } - if (bodyLower.indexOf(q) !== -1) { - score += 3; - } - if (page.section.toLowerCase().indexOf(q) !== -1) { - score += 1; - } - - if (score > 0) { - scored.push({ page: page, score: score }); - } - } - - // Sort by score descending - scored.sort(function (a, b) { return b.score - a.score; }); - - // Limit results - var results = scored.slice(0, 20); - - if (results.length === 0) { - resultsList.innerHTML = '
  • No results found.
  • '; - activeIndex = -1; - return; - } - - var html = ''; - for (var j = 0; j < results.length; j++) { - var r = results[j]; - var snippet = buildSnippet(r.page.body, query); - html += '
  • ' - + '
    ' + highlightText(r.page.title, query) + '
    ' - + (snippet ? '
    ' + snippet + '
    ' : '') - + '
  • '; - } - resultsList.innerHTML = html; - activeIndex = -1; - } - - function setActive(index) { - var items = resultsList.querySelectorAll('li[data-url]'); - if (items.length === 0) return; - // Remove previous active - for (var i = 0; i < items.length; i++) { - items[i].classList.remove('active'); - } - if (index < 0) index = items.length - 1; - if (index >= items.length) index = 0; - activeIndex = index; - items[activeIndex].classList.add('active'); - items[activeIndex].scrollIntoView({ block: 'nearest' }); - } - - function navigateToActive() { - var items = resultsList.querySelectorAll('li[data-url]'); - if (activeIndex >= 0 && activeIndex < items.length) { - var url = items[activeIndex].getAttribute('data-url'); - if (url) { - closeSearch(); - window.location.href = url; - } - } - } - - // Event: search button - if (searchBtn) { - searchBtn.addEventListener('click', function (e) { - e.stopPropagation(); - openSearch(); - }); - } - - // Use capture phase to intercept keys before browser default behavior - // (e.g. ESC clearing input text in some browsers) - document.addEventListener('keydown', function (e) { - if ((e.metaKey || e.ctrlKey) && e.key === 'k') { - e.preventDefault(); - overlay.classList.contains('open') ? closeSearch() : openSearch(); - return; - } - if (!overlay.classList.contains('open')) return; - if (e.key === 'Escape') { - e.preventDefault(); - closeSearch(); - } else if (e.key === 'ArrowDown') { - e.preventDefault(); - setActive(activeIndex + 1); - } else if (e.key === 'ArrowUp') { - e.preventDefault(); - setActive(activeIndex - 1); - } else if (e.key === 'Enter') { - e.preventDefault(); - navigateToActive(); - } - }, true); // capture phase - - // Event: click overlay background to close - overlay.addEventListener('click', function (e) { - if (e.target === overlay) { - closeSearch(); - } - }); - - // Event: click result item - resultsList.addEventListener('click', function (e) { - var li = e.target.closest('li[data-url]'); - if (!li) return; - var url = li.getAttribute('data-url'); - if (url) { - closeSearch(); - window.location.href = url; - } - }); - - // Event: input for live search - var debounceTimer = null; - input.addEventListener('input', function () { - clearTimeout(debounceTimer); - debounceTimer = setTimeout(function () { - search(input.value.trim()); - }, 150); - }); -})(); diff --git a/docs-gen/defaults/templates/base.html b/docs-gen/defaults/templates/base.html deleted file mode 100644 index 0445013..0000000 --- a/docs-gen/defaults/templates/base.html +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - {{ page.title }} - {{ site.title }} - - - - - -
    -
    - {{ site.title }}{% if site.version %} v{{ site.version }}{% endif %} -
    - -
    - - -
    - - -
    -
    - {% block sidebar_toggle %}{% endblock %} -
    -
    - - {% if page.status == "draft" %} -
    DRAFT
    - {% endif %} - -
    - {% block body %}{% endblock %} -
    - -
    - © 2026 yhirose. All rights reserved. -
    - - -
    -
    -
    - - - ESC -
    -
      -
      -
      - - - - diff --git a/docs-gen/defaults/templates/page.html b/docs-gen/defaults/templates/page.html deleted file mode 100644 index 089bd73..0000000 --- a/docs-gen/defaults/templates/page.html +++ /dev/null @@ -1,30 +0,0 @@ -{% extends "base.html" %} - -{% block layout_class %}has-sidebar{% endblock %} - -{% block sidebar_toggle %}{% endblock %} - -{% block body %} - -
      -
      -

      {{ page.title }}

      - {{ content | safe }} -
      -
      -{% endblock %} diff --git a/docs-gen/defaults/templates/portal.html b/docs-gen/defaults/templates/portal.html deleted file mode 100644 index cadbd06..0000000 --- a/docs-gen/defaults/templates/portal.html +++ /dev/null @@ -1,12 +0,0 @@ -{% extends "base.html" %} - -{% block layout_class %}no-sidebar{% endblock %} - -{% block body %} -
      -
      -

      {{ page.title }}

      - {{ content | safe }} -
      -
      -{% endblock %} diff --git a/docs-gen/src/builder.rs b/docs-gen/src/builder.rs deleted file mode 100644 index 03f3015..0000000 --- a/docs-gen/src/builder.rs +++ /dev/null @@ -1,468 +0,0 @@ -use crate::config::{NavLink, SiteConfig}; -use crate::defaults; -use crate::markdown::{Frontmatter, MarkdownRenderer}; -use crate::utils::copy_dir_recursive; -use anyhow::{Context, Result}; -use serde::Serialize; -use std::fs; -use std::path::{Path, PathBuf}; -use tera::Tera; -use walkdir::WalkDir; - -#[derive(Debug, Serialize)] -struct PageContext { - title: String, - url: String, - status: Option, -} - -/// Entry for pages-data.json used by client-side search. -#[derive(Debug, Serialize)] -struct PageDataEntry { - title: String, - url: String, - lang: String, - section: String, - /// Plain-text body with HTML tags stripped (truncated to ~500 chars). - body: String, -} - -#[derive(Debug, Serialize, Clone)] -struct NavItem { - title: String, - url: String, - children: Vec, - active: bool, -} - -#[derive(Debug, Serialize)] -struct SiteContext { - title: String, - version: Option, - base_url: String, - base_path: String, - langs: Vec, - nav: Vec, -} - -struct Page { - frontmatter: Frontmatter, - html_content: String, - url: String, - out_path: PathBuf, - rel_path: String, - section: String, -} - -pub fn build(src: &Path, out: &Path) -> Result<()> { - let config = SiteConfig::load(src)?; - let renderer = MarkdownRenderer::new( - config.highlight_dark_theme(), - config.highlight_light_theme(), - ); - - // Build Tera: start with embedded defaults, then override with user templates - let tera = build_tera(src)?; - - // Clean output directory - if out.exists() { - fs::remove_dir_all(out).context("Failed to clean output directory")?; - } - fs::create_dir_all(out)?; - - // Copy static files: embedded defaults first, then user overrides on top - copy_default_static(out)?; - let static_dir = src.join("static"); - if static_dir.exists() { - copy_dir_recursive(&static_dir, out)?; - } - - // Collect page data entries for pages-data.json across all languages - let mut page_data_entries: Vec = Vec::new(); - - // Build each language - for lang in &config.i18n.langs { - let pages_dir = src.join("pages").join(lang); - if !pages_dir.exists() { - eprintln!("Warning: pages directory not found for lang '{}', skipping", lang); - continue; - } - - let pages = collect_pages(&pages_dir, lang, out, &renderer, &config.site.base_path)?; - let nav = build_nav(&pages); - - for page in &pages { - // Collect search data for pages-data.json - let plain_body = strip_html_tags(&remove_light_theme_blocks(&page.html_content)); - let truncated_body: String = plain_body.chars().take(500).collect(); - page_data_entries.push(PageDataEntry { - title: page.frontmatter.title.clone(), - url: page.url.clone(), - lang: lang.clone(), - section: page.section.clone(), - body: truncated_body, - }); - - let template_name = if page.section.is_empty() { - "portal.html" - } else { - "page.html" - }; - - // Filter nav to only the current section - let section_nav: Vec<&NavItem> = nav - .iter() - .filter(|item| { - let item_section = extract_section(&item.url, &config.site.base_path); - item_section == page.section - }) - .collect(); - - let mut ctx = tera::Context::new(); - ctx.insert("page", &PageContext { - title: page.frontmatter.title.clone(), - url: page.url.clone(), - status: page.frontmatter.status.clone(), - }); - ctx.insert("content", &page.html_content); - ctx.insert("lang", lang); - ctx.insert("site", &SiteContext { - title: config.site.title.clone(), - version: config.site.version.clone(), - base_url: config.site.base_url(), - base_path: config.site.base_path.clone(), - langs: config.i18n.langs.clone(), - nav: config.nav.clone(), - }); - - // Set active state and pass nav - let mut nav_with_active: Vec = section_nav - .into_iter() - .cloned() - .map(|mut item| { - set_active(&mut item, &page.url); - item - }) - .collect(); - - // If we're on a section index page, expand its children - if let Some(item) = nav_with_active.first_mut() { - if item.url == page.url { - item.active = true; - } - } - - ctx.insert("nav", &nav_with_active); - - let html = tera - .render(template_name, &ctx) - .with_context(|| format!("Failed to render template for {}", page.url))?; - - if let Some(parent) = page.out_path.parent() { - fs::create_dir_all(parent)?; - } - fs::write(&page.out_path, html)?; - } - } - - // Generate pages-data.json for client-side search - let pages_json = serde_json::to_string(&page_data_entries) - .context("Failed to serialize pages-data.json")?; - fs::write(out.join("pages-data.json"), pages_json)?; - - // Generate root redirect - generate_root_redirect(out, &config)?; - - println!( - "Site generated: {} languages, output at {}", - config.i18n.langs.len(), - out.display() - ); - - Ok(()) -} - -fn collect_pages( - pages_dir: &Path, - lang: &str, - out: &Path, - renderer: &MarkdownRenderer, - base_path: &str, -) -> Result> { - let mut pages = Vec::new(); - - for entry in WalkDir::new(pages_dir) - .into_iter() - .filter_map(|e| e.ok()) - .filter(|e| { - e.path().extension().map_or(false, |ext| ext == "md") - }) - { - let path = entry.path(); - let content = fs::read_to_string(path) - .with_context(|| format!("Failed to read {}", path.display()))?; - - let (frontmatter, body) = MarkdownRenderer::parse_frontmatter(&content) - .with_context(|| format!("Failed to parse frontmatter in {}", path.display()))?; - - let html_content = renderer.render(body); - - let rel = path.strip_prefix(pages_dir)?; - let rel_str = rel.to_string_lossy().to_string(); - - // Compute URL and output path - let (url, out_path) = if rel.file_name().map_or(false, |f| f == "index.md") { - // index.md -> //dir/ - let parent = rel.parent().unwrap_or(Path::new("")); - if parent.as_os_str().is_empty() { - // Root index.md - ( - format!("{}/{}/", base_path, lang), - out.join(lang).join("index.html"), - ) - } else { - ( - format!("{}/{}/{}/", base_path, lang, parent.display()), - out.join(lang).join(parent).join("index.html"), - ) - } - } else { - // foo.md -> //foo/ - let stem = rel.with_extension(""); - ( - format!("{}/{}/{}/", base_path, lang, stem.display()), - out.join(lang).join(&stem).join("index.html"), - ) - }; - - let section = extract_section(&url, base_path); - - pages.push(Page { - frontmatter, - html_content, - url, - out_path, - rel_path: rel_str, - section, - }); - } - - Ok(pages) -} - -fn extract_section(url: &str, base_path: &str) -> String { - // Strip base_path prefix before parsing - let stripped = url.strip_prefix(base_path).unwrap_or(url); - // URL format: // or //section/... - let parts: Vec<&str> = stripped.trim_matches('/').split('/').collect(); - if parts.len() >= 2 { - parts[1].to_string() - } else { - String::new() - } -} - -fn build_nav(pages: &[Page]) -> Vec { - // Group pages by section (top-level directory) - let mut sections: std::collections::BTreeMap> = - std::collections::BTreeMap::new(); - - for page in pages { - if page.section.is_empty() { - continue; // Skip root index (portal) - } - sections - .entry(page.section.clone()) - .or_default() - .push(page); - } - - let mut nav = Vec::new(); - - for (section, mut section_pages) in sections { - // Sort by order, then by filename - section_pages.sort_by(|a, b| { - a.frontmatter - .order - .cmp(&b.frontmatter.order) - .then_with(|| a.rel_path.cmp(&b.rel_path)) - }); - - // Find the section index page - let index_page = section_pages - .iter() - .find(|p| p.rel_path.ends_with("index.md") && p.section == section); - - let section_title = index_page - .map(|p| p.frontmatter.title.clone()) - .unwrap_or_else(|| section.clone()); - let section_url = index_page - .map(|p| p.url.clone()) - .unwrap_or_default(); - - let children: Vec = section_pages - .iter() - .filter(|p| !p.rel_path.ends_with("index.md") || p.section != section) - .map(|p| NavItem { - title: p.frontmatter.title.clone(), - url: p.url.clone(), - children: Vec::new(), - active: false, - }) - .collect(); - - nav.push(NavItem { - title: section_title, - url: section_url, - children, - active: false, - }); - } - - // Sort nav sections by order of their index pages - nav -} - -fn set_active(item: &mut NavItem, current_url: &str) { - if item.url == current_url { - item.active = true; - } - for child in &mut item.children { - set_active(child, current_url); - if child.active { - item.active = true; - } - } -} - -fn generate_root_redirect(out: &Path, config: &SiteConfig) -> Result<()> { - let base_path = &config.site.base_path; - let html = format!( - r#" - - - - - -Redirecting... - - -

      Redirecting to {base_path}/{default_lang}/...

      - -"#, - default_lang = config.i18n.default_lang(), - base_path = base_path, - ); - - fs::write(out.join("index.html"), html)?; - Ok(()) -} - -/// Build Tera with embedded default templates, then override with any files -/// found in `/templates/`. -fn build_tera(src: &Path) -> Result { - let mut tera = Tera::default(); - - // Register embedded defaults - for (name, source) in defaults::default_templates() { - tera.add_raw_template(name, source) - .with_context(|| format!("Failed to add default template '{}'", name))?; - } - - // Override with user-provided templates (if any) - let templates_dir = src.join("templates"); - if templates_dir.exists() { - for entry in WalkDir::new(&templates_dir) - .into_iter() - .filter_map(|e| e.ok()) - .filter(|e| e.path().extension().map_or(false, |ext| ext == "html")) - { - let path = entry.path(); - let rel = path.strip_prefix(&templates_dir)?; - let name = rel.to_string_lossy().replace('\\', "/"); - let source = fs::read_to_string(path) - .with_context(|| format!("Failed to read template {}", path.display()))?; - tera.add_raw_template(&name, &source) - .with_context(|| format!("Failed to register template '{}'", name))?; - } - } - - Ok(tera) -} - -/// Write embedded default static files (css/js) to the output directory. -fn copy_default_static(out: &Path) -> Result<()> { - for (rel_path, content) in defaults::default_static_files() { - let target = out.join(rel_path); - if let Some(parent) = target.parent() { - fs::create_dir_all(parent)?; - } - // Only write if not already present (user file takes precedence via - // the subsequent copy_dir_recursive call, but write defaults first) - fs::write(&target, content)?; - } - Ok(()) -} - -/// Strip HTML tags from a string and collapse whitespace into a single space, -/// producing a plain-text representation suitable for search indexing. -fn strip_html_tags(html: &str) -> String { - let mut result = String::with_capacity(html.len()); - let mut in_tag = false; - - for ch in html.chars() { - match ch { - '<' => in_tag = true, - '>' => { - in_tag = false; - // Insert a space to avoid words being glued across tags - result.push(' '); - } - _ if !in_tag => result.push(ch), - _ => {} - } - } - - // Collapse whitespace - let collapsed: String = result.split_whitespace().collect::>().join(" "); - collapsed -} - -/// Remove `
      ...
      ` blocks so that -/// dual-theme code snippets are only indexed once. -fn remove_light_theme_blocks(html: &str) -> String { - const MARKER: &str = "
      ") { - depth -= 1; - i += 6; - if depth == 0 { - break; - } - } else { - i += remaining[i..].chars().next().map_or(1, |c| c.len_utf8()); - } - } - remaining = &remaining[i..]; - } - - result.push_str(remaining); - result -} diff --git a/docs-gen/src/config.rs b/docs-gen/src/config.rs deleted file mode 100644 index 9b38d4c..0000000 --- a/docs-gen/src/config.rs +++ /dev/null @@ -1,97 +0,0 @@ -use anyhow::{Context, Result}; -use serde::{Deserialize, Serialize}; -use std::path::Path; - -#[derive(Debug, Deserialize)] -pub struct SiteConfig { - pub site: Site, - pub i18n: I18n, - pub highlight: Option, - #[serde(default)] - pub nav: Vec, -} - -/// A navigation link entry defined in config.toml under [[nav]]. -#[derive(Debug, Deserialize, Serialize, Clone)] -pub struct NavLink { - pub label: String, - /// Absolute or external URL (e.g. GitHub link). - pub url: Option, - /// Path relative to /// (e.g. "tour/"). - pub path: Option, - /// Optional inline SVG string to display as an icon. - pub icon_svg: Option, -} - -#[derive(Debug, Deserialize)] -pub struct Site { - pub title: String, - pub version: Option, - /// Optional hostname (e.g. "https://example.github.io"). Combined with - /// base_path to form the full base URL. - pub hostname: Option, - #[serde(default)] - pub base_path: String, -} - -impl Site { - /// Returns the full base URL derived from hostname + base_path. - /// Falls back to base_path alone if hostname is not set. - pub fn base_url(&self) -> String { - match &self.hostname { - Some(h) => format!("{}{}", h.trim_end_matches('/'), self.base_path), - None => self.base_path.clone(), - } - } -} - -#[derive(Debug, Deserialize)] -pub struct I18n { - pub langs: Vec, -} - -impl I18n { - /// Returns the default language, which is the first entry in langs. - pub fn default_lang(&self) -> &str { - self.langs.first().map(|s| s.as_str()).unwrap_or("en") - } -} - -#[derive(Debug, Deserialize)] -pub struct Highlight { - pub dark_theme: Option, - pub light_theme: Option, -} - -impl SiteConfig { - pub fn load(src_dir: &Path) -> Result { - let path = src_dir.join("config.toml"); - let content = - std::fs::read_to_string(&path).with_context(|| format!("Failed to read {}", path.display()))?; - let mut config: SiteConfig = - toml::from_str(&content).with_context(|| format!("Failed to parse {}", path.display()))?; - - // Validate required fields - if config.i18n.langs.is_empty() { - anyhow::bail!("[i18n] langs must not be empty. Please specify at least one language."); - } - - // Normalize base_path: strip trailing slash (but keep empty for root) - let bp = config.site.base_path.trim_end_matches('/').to_string(); - config.site.base_path = bp; - Ok(config) - } - - pub fn highlight_dark_theme(&self) -> &str { - self.highlight - .as_ref() - .and_then(|h| h.dark_theme.as_deref()) - .unwrap_or("base16-ocean.dark") - } - - pub fn highlight_light_theme(&self) -> Option<&str> { - self.highlight - .as_ref() - .and_then(|h| h.light_theme.as_deref()) - } -} diff --git a/docs-gen/src/defaults.rs b/docs-gen/src/defaults.rs deleted file mode 100644 index 6c27194..0000000 --- a/docs-gen/src/defaults.rs +++ /dev/null @@ -1,47 +0,0 @@ -// Default embedded theme files. Users can override any of these by placing -// a file with the same name under their /templates/ or /static/. - -pub const TEMPLATE_BASE: &str = include_str!("../defaults/templates/base.html"); -pub const TEMPLATE_PAGE: &str = include_str!("../defaults/templates/page.html"); -pub const TEMPLATE_PORTAL: &str = include_str!("../defaults/templates/portal.html"); - -pub const STATIC_CSS_MAIN: &str = include_str!("../defaults/static/css/main.css"); -pub const STATIC_JS_MAIN: &str = include_str!("../defaults/static/js/main.js"); -pub const STATIC_FAVICON_SVG: &str = include_str!("../defaults/static/favicon.svg"); - -// Init command templates -pub const INIT_CONFIG_TOML: &str = include_str!("../defaults/config.toml"); -pub const INIT_PAGE_EN_INDEX: &str = include_str!("../defaults/pages/en/index.md"); -pub const INIT_PAGE_JA_INDEX: &str = include_str!("../defaults/pages/ja/index.md"); - -/// Returns all default templates as (name, source) pairs for Tera registration. -pub fn default_templates() -> Vec<(&'static str, &'static str)> { - vec![ - ("base.html", TEMPLATE_BASE), - ("page.html", TEMPLATE_PAGE), - ("portal.html", TEMPLATE_PORTAL), - ] -} - -/// Returns all default static files as (relative_path, content) pairs. -pub fn default_static_files() -> Vec<(&'static str, &'static str)> { - vec![ - ("css/main.css", STATIC_CSS_MAIN), - ("js/main.js", STATIC_JS_MAIN), - ("favicon.svg", STATIC_FAVICON_SVG), - ] -} - -/// Returns all init scaffold files as (relative_path, content) pairs. -pub fn init_files() -> Vec<(&'static str, &'static str)> { - vec![ - ("config.toml", INIT_CONFIG_TOML), - ("templates/base.html", TEMPLATE_BASE), - ("templates/page.html", TEMPLATE_PAGE), - ("templates/portal.html", TEMPLATE_PORTAL), - ("static/css/main.css", STATIC_CSS_MAIN), - ("static/js/main.js", STATIC_JS_MAIN), - ("pages/en/index.md", INIT_PAGE_EN_INDEX), - ("pages/ja/index.md", INIT_PAGE_JA_INDEX), - ] -} diff --git a/docs-gen/src/main.rs b/docs-gen/src/main.rs deleted file mode 100644 index 2855b84..0000000 --- a/docs-gen/src/main.rs +++ /dev/null @@ -1,99 +0,0 @@ -mod builder; -mod config; -mod defaults; -mod markdown; -mod serve; -mod utils; - -use anyhow::Result; -use clap::{Parser, Subcommand, CommandFactory}; -use std::fs; -use std::path::{Path, PathBuf}; - -#[derive(Parser)] -#[command(version, about = "A simple static site generator")] -struct Cli { - #[command(subcommand)] - command: Option, - - /// Source directory containing config.toml (used when no subcommand given) - #[arg(default_value = ".")] - src: PathBuf, - - /// Output directory (used when no subcommand given) - #[arg(long, default_value = "docs")] - out: PathBuf, -} - -#[derive(Subcommand)] -enum Command { - /// Build the documentation site - Build { - /// Source directory containing config.toml - #[arg(default_value = ".")] - src: PathBuf, - - /// Output directory - #[arg(long, default_value = "docs")] - out: PathBuf, - }, - /// Initialize a new docs project with default scaffold files - Init { - /// Target directory to initialize (default: current directory) - #[arg(default_value = ".")] - src: PathBuf, - }, - /// Start a local development server with live-reload - Serve { - /// Source directory containing config.toml - #[arg(default_value = ".")] - src: PathBuf, - - /// Port number for the HTTP server - #[arg(long, default_value = "8080")] - port: u16, - - /// Open browser automatically - #[arg(long)] - open: bool, - }, -} - -fn main() -> Result<()> { - let cli = Cli::parse(); - - match cli.command { - Some(Command::Build { src, out }) => builder::build(&src, &out), - Some(Command::Init { src }) => cmd_init(&src), - Some(Command::Serve { src, port, open }) => serve::serve(&src, port, open), - None => { - Cli::command().print_help()?; - println!(); - Ok(()) - } - } -} - -fn cmd_init(target: &Path) -> Result<()> { - let mut skipped = 0usize; - let mut created = 0usize; - - for (rel_path, content) in defaults::init_files() { - let dest = target.join(rel_path); - if dest.exists() { - eprintln!("Skipping (already exists): {}", dest.display()); - skipped += 1; - continue; - } - if let Some(parent) = dest.parent() { - fs::create_dir_all(parent)?; - } - fs::write(&dest, content)?; - println!("Created: {}", dest.display()); - created += 1; - } - - println!("\nInit complete: {} file(s) created, {} skipped.", created, skipped); - Ok(()) -} - diff --git a/docs-gen/src/markdown.rs b/docs-gen/src/markdown.rs deleted file mode 100644 index 56ff1f7..0000000 --- a/docs-gen/src/markdown.rs +++ /dev/null @@ -1,145 +0,0 @@ -use anyhow::{Context, Result}; -use pulldown_cmark::{CodeBlockKind, Event, Options, Parser, Tag, TagEnd}; -use serde::Deserialize; -use syntect::highlighting::ThemeSet; -use syntect::html::highlighted_html_for_string; -use syntect::parsing::SyntaxSet; - -#[derive(Debug, Deserialize)] -pub struct Frontmatter { - pub title: String, - #[serde(default)] - pub order: i32, - pub status: Option, -} - -pub struct MarkdownRenderer { - syntax_set: SyntaxSet, - theme_set: ThemeSet, - dark_theme: String, - light_theme: Option, -} - -impl MarkdownRenderer { - pub fn new(dark_theme: &str, light_theme: Option<&str>) -> Self { - Self { - syntax_set: SyntaxSet::load_defaults_newlines(), - theme_set: ThemeSet::load_defaults(), - dark_theme: dark_theme.to_string(), - light_theme: light_theme.map(|s| s.to_string()), - } - } - - pub fn parse_frontmatter(content: &str) -> Result<(Frontmatter, &str)> { - let content = content.trim_start(); - if !content.starts_with("---") { - anyhow::bail!("Missing frontmatter delimiter"); - } - let after_first = &content[3..]; - let end = after_first - .find("\n---") - .context("Missing closing frontmatter delimiter")?; - let yaml = &after_first[..end]; - let body = &after_first[end + 4..]; - let fm: Frontmatter = - serde_yaml::from_str(yaml).context("Failed to parse frontmatter YAML")?; - Ok((fm, body)) - } - - pub fn render(&self, markdown: &str) -> String { - let options = Options::ENABLE_TABLES - | Options::ENABLE_STRIKETHROUGH - | Options::ENABLE_TASKLISTS; - - let parser = Parser::new_ext(markdown, options); - - let mut in_code_block = false; - let mut code_lang = String::new(); - let mut code_buf = String::new(); - let mut events: Vec = Vec::new(); - - for event in parser { - match event { - Event::Start(Tag::CodeBlock(kind)) => { - in_code_block = true; - code_buf.clear(); - code_lang = match kind { - CodeBlockKind::Fenced(lang) => lang.to_string(), - CodeBlockKind::Indented => String::new(), - }; - } - Event::End(TagEnd::CodeBlock) => { - in_code_block = false; - let html = self.highlight_code(&code_buf, &code_lang); - events.push(Event::Html(html.into())); - } - Event::Text(text) if in_code_block => { - code_buf.push_str(&text); - } - other => events.push(other), - } - } - - let mut html_output = String::new(); - pulldown_cmark::html::push_html(&mut html_output, events.into_iter()); - html_output - } - - fn highlight_code(&self, code: &str, lang: &str) -> String { - let syntax = if lang.is_empty() { - self.syntax_set.find_syntax_plain_text() - } else { - self.syntax_set - .find_syntax_by_token(lang) - .unwrap_or_else(|| self.syntax_set.find_syntax_plain_text()) - }; - - let dark_html = self.highlight_with_theme(code, syntax, &self.dark_theme); - - match &self.light_theme { - Some(light) => { - let light_html = self.highlight_with_theme(code, syntax, light); - format!( - concat!( - "
      ", - "
      {}
      ", - "
      {}
      ", - "
      ", - ), - dark_html, light_html - ) - } - None => dark_html, - } - } - - fn highlight_with_theme( - &self, - code: &str, - syntax: &syntect::parsing::SyntaxReference, - theme_name: &str, - ) -> String { - let theme = self - .theme_set - .themes - .get(theme_name) - .unwrap_or_else(|| { - self.theme_set - .themes - .values() - .next() - .expect("No themes available") - }); - - match highlighted_html_for_string(code, &self.syntax_set, syntax, theme) { - Ok(html) => html, - Err(_) => format!("
      {}
      ", escape_html(code)), - } - } -} - -fn escape_html(s: &str) -> String { - s.replace('&', "&") - .replace('<', "<") - .replace('>', ">") -} diff --git a/docs-gen/src/serve.rs b/docs-gen/src/serve.rs deleted file mode 100644 index 10b23f0..0000000 --- a/docs-gen/src/serve.rs +++ /dev/null @@ -1,340 +0,0 @@ -use crate::builder; -use crate::config::SiteConfig; -use crate::utils::copy_dir_recursive; -use anyhow::{Context, Result}; -use notify::{Event, RecursiveMode, Watcher}; -use socket2::{Domain, Protocol, Socket, Type}; -use std::fs; -use std::io::Write; -use std::net::{TcpListener, TcpStream}; -use std::path::Path; -use std::sync::mpsc; -use std::sync::{Arc, Mutex}; -use std::thread; -use std::time::Duration; -use walkdir::WalkDir; - -/// Live-reload WebSocket script injected into every HTML page during serve. -const LIVE_RELOAD_SCRIPT: &str = r#""#; - -/// Run the serve command: build, start HTTP + WebSocket servers, watch for changes. -pub fn serve(src: &Path, port: u16, open_browser: bool) -> Result<()> { - let config = SiteConfig::load(src)?; - let base_path = config.site.base_path.clone(); - let ws_port = port + 1; - - // Create temp directory for serving - let tmp_dir = tempfile::tempdir().context("Failed to create temp directory")?; - let serve_root = tmp_dir.path().to_path_buf(); - - println!("Serving from temp directory: {}", serve_root.display()); - - // Initial build - build_and_copy(src, &serve_root, &base_path, ws_port)?; - - // Track connected WebSocket clients - let clients: Arc>> = Arc::new(Mutex::new(Vec::new())); - - // Create HTTP and WebSocket listeners upfront with SO_REUSEADDR - // so that rapid restarts (after Ctrl+C) don't hit "address in use". - let http_listener = create_reuse_listener(port) - .with_context(|| format!("Failed to bind HTTP server to port {}", port))?; - let ws_listener = create_reuse_listener(ws_port) - .with_context(|| format!("Failed to bind WebSocket server to port {}", ws_port))?; - - // Start WebSocket server for live-reload notifications - let ws_clients = clients.clone(); - thread::spawn(move || { - if let Err(e) = run_ws_server(ws_listener, ws_clients) { - eprintln!("WebSocket server error: {}", e); - } - }); - - // Start HTTP server - let http_root = serve_root.clone(); - thread::spawn(move || { - if let Err(e) = run_http_server(http_listener, &http_root) { - eprintln!("HTTP server error: {}", e); - } - }); - - let url = if base_path.is_empty() { - format!("http://localhost:{}/", port) - } else { - format!("http://localhost:{}{}/", port, base_path) - }; - - println!("\n Local: {}", url); - println!(" Press Ctrl+C to stop.\n"); - - if open_browser { - let _ = open::that(&url); - } - - // File watcher - let (tx, rx) = mpsc::channel(); - - let mut watcher = notify::recommended_watcher(move |res: Result| { - if let Ok(event) = res { - if event.kind.is_modify() || event.kind.is_create() || event.kind.is_remove() { - let _ = tx.send(()); - } - } - })?; - - let src_abs = fs::canonicalize(src)?; - watcher.watch(&src_abs, RecursiveMode::Recursive)?; - - println!("Watching for changes in {}...", src_abs.display()); - - // Debounce: wait for changes, then rebuild - loop { - // Block until a change notification arrives - if rx.recv().is_err() { - break; - } - // Drain any additional events within a short debounce window - thread::sleep(Duration::from_millis(200)); - while rx.try_recv().is_ok() {} - - println!("Change detected, rebuilding..."); - match build_and_copy(src, &serve_root, &base_path, ws_port) { - Ok(()) => { - println!("Rebuild complete. Notifying browser..."); - notify_clients(&clients); - } - Err(e) => { - eprintln!("Rebuild failed: {}", e); - } - } - } - - Ok(()) -} - -/// Build site into a temp build dir, then copy to serve_root// -/// with live-reload script injected. -fn build_and_copy(src: &Path, serve_root: &Path, base_path: &str, ws_port: u16) -> Result<()> { - // Build into a temporary output directory - let build_tmp = tempfile::tempdir().context("Failed to create build temp dir")?; - let build_out = build_tmp.path(); - - builder::build(src, build_out)?; - - // Determine the target directory under serve_root - let target = if base_path.is_empty() { - serve_root.to_path_buf() - } else { - let bp = base_path.trim_start_matches('/'); - serve_root.join(bp) - }; - - // Clean target and copy - if target.exists() { - fs::remove_dir_all(&target).ok(); - } - copy_dir_recursive(build_out, &target)?; - - // Inject live-reload script into all HTML files - inject_live_reload(&target, ws_port)?; - - Ok(()) -} - -/// Inject live-reload WebSocket script into all HTML files under dir. -fn inject_live_reload(dir: &Path, ws_port: u16) -> Result<()> { - let script = LIVE_RELOAD_SCRIPT.replace("{{WS_PORT}}", &ws_port.to_string()); - - for entry in WalkDir::new(dir) - .into_iter() - .filter_map(|e| e.ok()) - .filter(|e| { - e.path() - .extension() - .map_or(false, |ext| ext == "html") - }) - { - let path = entry.path(); - let content = fs::read_to_string(path)?; - if let Some(pos) = content.rfind("") { - let injected = format!("{}{}{}", &content[..pos], script, &content[pos..]); - fs::write(path, injected)?; - } - } - - Ok(()) -} - -/// Simple HTTP static file server using tiny_http. -fn run_http_server(listener: TcpListener, root: &Path) -> Result<()> { - let server = tiny_http::Server::from_listener(listener, None) - .map_err(|e| anyhow::anyhow!("HTTP server: {}", e))?; - - for request in server.incoming_requests() { - let url_path = percent_decode(request.url()); - let rel = url_path.trim_start_matches('/'); - - let file_path = if rel.is_empty() { - root.join("index.html") - } else { - let candidate = root.join(rel); - if candidate.is_dir() { - candidate.join("index.html") - } else { - candidate - } - }; - - if file_path.exists() && file_path.is_file() { - let content = fs::read(&file_path).unwrap_or_default(); - let mime = guess_mime(&file_path); - let response = tiny_http::Response::from_data(content) - .with_header( - tiny_http::Header::from_bytes(&b"Content-Type"[..], mime.as_bytes()).unwrap(), - ); - let _ = request.respond(response); - } else { - let response = tiny_http::Response::from_string("404 Not Found") - .with_status_code(404); - let _ = request.respond(response); - } - } - - Ok(()) -} - -/// WebSocket server that accepts connections and stores them for later notification. -fn run_ws_server(listener: TcpListener, clients: Arc>>) -> Result<()> { - - for stream in listener.incoming().flatten() { - let clients = clients.clone(); - thread::spawn(move || { - if let Ok(ws) = tungstenite::accept(stream.try_clone().unwrap()) { - // Store the underlying TCP stream for later notification - if let Ok(mut list) = clients.lock() { - list.push(stream); - } - // Keep the WebSocket connection alive - read until closed - let mut ws = ws; - loop { - match ws.read() { - Ok(msg) => { - if msg.is_close() { - break; - } - } - Err(_) => break, - } - } - } - }); - } - - Ok(()) -} - -/// Send "reload" to all connected WebSocket clients. -fn notify_clients(clients: &Arc>>) { - if let Ok(mut list) = clients.lock() { - let mut alive = Vec::new(); - for stream in list.drain(..) { - if stream.try_clone().is_ok() { - // Re-wrap as WebSocket and send reload message - // Since we can't easily re-wrap existing TCP streams, - // we'll use a simpler approach: raw WebSocket frame - if send_ws_text_frame(&stream, "reload").is_ok() { - alive.push(stream); - } - } - } - *list = alive; - } -} - -/// Send a WebSocket text frame directly on a TCP stream. -fn send_ws_text_frame(mut stream: &TcpStream, msg: &str) -> Result<()> { - let payload = msg.as_bytes(); - let len = payload.len(); - - // WebSocket text frame: opcode 0x81 - let mut frame = Vec::new(); - frame.push(0x81); - if len < 126 { - frame.push(len as u8); - } else if len < 65536 { - frame.push(126); - frame.push((len >> 8) as u8); - frame.push((len & 0xFF) as u8); - } - frame.extend_from_slice(payload); - - stream.write_all(&frame)?; - stream.flush()?; - Ok(()) -} - -fn guess_mime(path: &Path) -> String { - match path.extension().and_then(|e| e.to_str()) { - Some("html") => "text/html; charset=utf-8".to_string(), - Some("css") => "text/css; charset=utf-8".to_string(), - Some("js") => "application/javascript; charset=utf-8".to_string(), - Some("json") => "application/json; charset=utf-8".to_string(), - Some("svg") => "image/svg+xml".to_string(), - Some("png") => "image/png".to_string(), - Some("jpg") | Some("jpeg") => "image/jpeg".to_string(), - Some("gif") => "image/gif".to_string(), - Some("ico") => "image/x-icon".to_string(), - Some("wasm") => "application/wasm".to_string(), - Some("woff") => "font/woff".to_string(), - Some("woff2") => "font/woff2".to_string(), - Some("ttf") => "font/ttf".to_string(), - _ => "application/octet-stream".to_string(), - } -} - -fn percent_decode(input: &str) -> String { - let mut result = String::with_capacity(input.len()); - let mut chars = input.bytes(); - while let Some(b) = chars.next() { - if b == b'%' { - let hi = chars.next().and_then(|c| hex_val(c)); - let lo = chars.next().and_then(|c| hex_val(c)); - if let (Some(h), Some(l)) = (hi, lo) { - result.push((h << 4 | l) as char); - } - } else { - result.push(b as char); - } - } - result -} - -fn hex_val(b: u8) -> Option { - match b { - b'0'..=b'9' => Some(b - b'0'), - b'a'..=b'f' => Some(b - b'a' + 10), - b'A'..=b'F' => Some(b - b'A' + 10), - _ => None, - } -} - -/// Create a TCP listener with SO_REUSEADDR (and SO_REUSEPORT on Unix) set, -/// so that rapid restarts after Ctrl+C don't fail with "address in use". -fn create_reuse_listener(port: u16) -> Result { - let socket = Socket::new(Domain::IPV4, Type::STREAM, Some(Protocol::TCP))?; - socket.set_reuse_address(true)?; - #[cfg(unix)] - socket.set_reuse_port(true)?; - let addr: std::net::SocketAddr = format!("0.0.0.0:{}", port).parse()?; - socket.bind(&addr.into())?; - socket.listen(128)?; - Ok(socket.into()) -} diff --git a/docs-gen/src/utils.rs b/docs-gen/src/utils.rs deleted file mode 100644 index 0beca64..0000000 --- a/docs-gen/src/utils.rs +++ /dev/null @@ -1,22 +0,0 @@ -use anyhow::Result; -use std::fs; -use std::path::Path; -use walkdir::WalkDir; - -pub fn copy_dir_recursive(src: &Path, dst: &Path) -> Result<()> { - for entry in WalkDir::new(src).into_iter().filter_map(|e| e.ok()) { - let path = entry.path(); - let rel = path.strip_prefix(src)?; - let target = dst.join(rel); - - if path.is_dir() { - fs::create_dir_all(&target)?; - } else { - if let Some(parent) = target.parent() { - fs::create_dir_all(parent)?; - } - fs::copy(path, &target)?; - } - } - Ok(()) -} diff --git a/docs-src/config.toml b/docs-src/config.toml index 662effd..a38c106 100644 --- a/docs-src/config.toml +++ b/docs-src/config.toml @@ -1,8 +1,13 @@ +[system] +theme = "default" +langs = ["en", "ja"] + [site] title = "cpp-httplib" version = "0.36.0" hostname = "https://yhirose.github.io" base_path = "/cpp-httplib" +footer_message = "© 2026 Yuji Hirose. All rights reserved." [[nav]] label = "Tour" @@ -13,10 +18,3 @@ icon_svg = ' [data-code-theme="light"] { /* Footer */ .footer { - padding: 12px 16px; + padding: 8px 16px; text-align: center; color: var(--text-muted); font-size: 0.8rem; @@ -433,7 +433,7 @@ html[data-theme="light"] .code-block-wrapper > [data-code-theme="light"] { --link: #b8860b; --heading: #2a6496; --heading-link: #c06020; - --header-nav-link: #c04060; + --header-nav-link: #282828; --emphasis: #c04060; --nav-section: #666; --nav-section-active: #333; diff --git a/docs/en/cookbook/index.html b/docs/en/cookbook/index.html index d6ba668..837c389 100644 --- a/docs/en/cookbook/index.html +++ b/docs/en/cookbook/index.html @@ -17,16 +17,16 @@
      - cpp-httplib v0.36.0 + cpp-httplib v0.36.0
      @@ -89,7 +91,7 @@
      - © 2026 yhirose. All rights reserved. + © 2026 Yuji Hirose. All rights reserved.
      diff --git a/docs/en/index.html b/docs/en/index.html index 6bc45bc..e8f2947 100644 --- a/docs/en/index.html +++ b/docs/en/index.html @@ -17,16 +17,16 @@
      - cpp-httplib v0.36.0 + cpp-httplib v0.36.0
      @@ -88,7 +90,7 @@
      - © 2026 yhirose. All rights reserved. + © 2026 Yuji Hirose. All rights reserved.
      diff --git a/docs/en/tour/01-getting-started/index.html b/docs/en/tour/01-getting-started/index.html index 9588bd7..f261f90 100644 --- a/docs/en/tour/01-getting-started/index.html +++ b/docs/en/tour/01-getting-started/index.html @@ -17,16 +17,16 @@
      - cpp-httplib v0.36.0 + cpp-httplib v0.36.0
      @@ -105,8 +107,8 @@

      All you need to get started with cpp-httplib is httplib.h and a C++ compiler. Let's download the file and get a Hello World server running.

      Getting httplib.h

      You can download it directly from GitHub. Always use the latest version.

      -
      -curl -LO https://github.com/yhirose/cpp-httplib/raw/refs/tags/latest/httplib.h
      +
      +curl -LO https://github.com/yhirose/cpp-httplib/raw/refs/tags/latest/httplib.h
       
       curl -LO https://github.com/yhirose/cpp-httplib/raw/refs/tags/latest/httplib.h
      @@ -121,18 +123,18 @@
       
       

      Hello World Server

      Save the following code as server.cpp.

      -
      -#include "httplib.h"
      -
      -int main() {
      -    httplib::Server svr;
      -
      -    svr.Get("/", [](const httplib::Request&, httplib::Response& res) {
      -        res.set_content("Hello, World!", "text/plain");
      -    });
      -
      -    svr.listen("0.0.0.0", 8080);
      -}
      +
      +#include "httplib.h"
      +
      +int main() {
      +    httplib::Server svr;
      +
      +    svr.Get("/", [](const httplib::Request&, httplib::Response& res) {
      +        res.set_content("Hello, World!", "text/plain");
      +    });
      +
      +    svr.listen("0.0.0.0", 8080);
      +}
       
       #include "httplib.h"
      @@ -151,17 +153,17 @@
       

      In just a few lines, you have a server that responds to HTTP requests.

      Compiling and Running

      The sample code in this tutorial is written in C++17 for cleaner, more concise code. cpp-httplib itself can compile with C++11 as well.

      -
      -# macOS
      -clang++ -std=c++17 -o server server.cpp
      -
      -# Linux
      -# `-pthread`: cpp-httplib uses threads internally
      -clang++ -std=c++17 -pthread -o server server.cpp
      -
      -# Windows (Developer Command Prompt)
      -# `/EHsc`: Enable C++ exception handling
      -cl /EHsc /std:c++17 server.cpp
      +
      +# macOS
      +clang++ -std=c++17 -o server server.cpp
      +
      +# Linux
      +# `-pthread`: cpp-httplib uses threads internally
      +clang++ -std=c++17 -pthread -o server server.cpp
      +
      +# Windows (Developer Command Prompt)
      +# `/EHsc`: Enable C++ exception handling
      +cl /EHsc /std:c++17 server.cpp
       
       # macOS
      @@ -177,12 +179,12 @@
       

      Once it compiles, run it.

      -
      -# macOS / Linux
      -./server
      -
      -# Windows
      -server.exe
      +
      +# macOS / Linux
      +./server
      +
      +# Windows
      +server.exe
       
       # macOS / Linux
      @@ -194,9 +196,9 @@
       

      Open http://localhost:8080 in your browser. If you see "Hello, World!", you're all set.

      You can also verify with curl.

      -
      -curl http://localhost:8080/
      -# Hello, World!
      +
      +curl http://localhost:8080/
      +# Hello, World!
       
       curl http://localhost:8080/
      @@ -214,7 +216,7 @@
         
      - © 2026 yhirose. All rights reserved. + © 2026 Yuji Hirose. All rights reserved.
      diff --git a/docs/en/tour/02-basic-client/index.html b/docs/en/tour/02-basic-client/index.html index a461643..48cab82 100644 --- a/docs/en/tour/02-basic-client/index.html +++ b/docs/en/tour/02-basic-client/index.html @@ -17,16 +17,16 @@
      - cpp-httplib v0.36.0 + cpp-httplib v0.36.0
      @@ -105,53 +107,53 @@

      cpp-httplib isn't just for servers -- it also comes with a full HTTP client. Let's use httplib::Client to send GET and POST requests.

      Preparing a Test Server

      To try out the client, you need a server that accepts requests. Save the following code, then compile and run it the same way you did in the previous chapter. We'll cover the server details in the next chapter.

      -
      -#include "httplib.h"
      -#include <iostream>
      -
      -int main() {
      -    httplib::Server svr;
      -
      -    svr.Get("/hi", [](const auto &, auto &res) {
      -        res.set_content("Hello!", "text/plain");
      -    });
      -
      -    svr.Get("/search", [](const auto &req, auto &res) {
      -        auto q = req.get_param_value("q");
      -        res.set_content("Query: " + q, "text/plain");
      -    });
      -
      -    svr.Post("/post", [](const auto &req, auto &res) {
      -        res.set_content(req.body, "text/plain");
      -    });
      -
      -    svr.Post("/submit", [](const auto &req, auto &res) {
      -        std::string result;
      -        for (auto &[key, val] : req.params) {
      -            result += key + " = " + val + "\n";
      -        }
      -        res.set_content(result, "text/plain");
      -    });
      -
      -    svr.Post("/upload", [](const auto &req, auto &res) {
      -        auto f = req.form.get_file("file");
      -        auto content = f.filename + " (" + std::to_string(f.content.size()) + " bytes)";
      -        res.set_content(content, "text/plain");
      -    });
      -
      -    svr.Get("/users/:id", [](const auto &req, auto &res) {
      -        auto id = req.path_params.at("id");
      -        res.set_content("User ID: " + id, "text/plain");
      -    });
      -
      -    svr.Get(R"(/files/(\d+))", [](const auto &req, auto &res) {
      -        auto id = req.matches[1];
      -        res.set_content("File ID: " + std::string(id), "text/plain");
      -    });
      -
      -    std::cout << "Listening on port 8080..." << std::endl;
      -    svr.listen("0.0.0.0", 8080);
      -}
      +
      +#include "httplib.h"
      +#include <iostream>
      +
      +int main() {
      +    httplib::Server svr;
      +
      +    svr.Get("/hi", [](const auto &, auto &res) {
      +        res.set_content("Hello!", "text/plain");
      +    });
      +
      +    svr.Get("/search", [](const auto &req, auto &res) {
      +        auto q = req.get_param_value("q");
      +        res.set_content("Query: " + q, "text/plain");
      +    });
      +
      +    svr.Post("/post", [](const auto &req, auto &res) {
      +        res.set_content(req.body, "text/plain");
      +    });
      +
      +    svr.Post("/submit", [](const auto &req, auto &res) {
      +        std::string result;
      +        for (auto &[key, val] : req.params) {
      +            result += key + " = " + val + "\n";
      +        }
      +        res.set_content(result, "text/plain");
      +    });
      +
      +    svr.Post("/upload", [](const auto &req, auto &res) {
      +        auto f = req.form.get_file("file");
      +        auto content = f.filename + " (" + std::to_string(f.content.size()) + " bytes)";
      +        res.set_content(content, "text/plain");
      +    });
      +
      +    svr.Get("/users/:id", [](const auto &req, auto &res) {
      +        auto id = req.path_params.at("id");
      +        res.set_content("User ID: " + id, "text/plain");
      +    });
      +
      +    svr.Get(R"(/files/(\d+))", [](const auto &req, auto &res) {
      +        auto id = req.matches[1];
      +        res.set_content("File ID: " + std::string(id), "text/plain");
      +    });
      +
      +    std::cout << "Listening on port 8080..." << std::endl;
      +    svr.listen("0.0.0.0", 8080);
      +}
       
       #include "httplib.h"
      @@ -204,19 +206,19 @@
       

      GET Request

      Once the server is running, open a separate terminal and give it a try. Let's start with the simplest GET request.

      -
      -#include "httplib.h"
      -#include <iostream>
      -
      -int main() {
      -    httplib::Client cli("http://localhost:8080");
      -
      -    auto res = cli.Get("/hi");
      -    if (res) {
      -        std::cout << res->status << std::endl;  // 200
      -        std::cout << res->body << std::endl;    // Hello!
      -    }
      -}
      +
      +#include "httplib.h"
      +#include <iostream>
      +
      +int main() {
      +    httplib::Client cli("http://localhost:8080");
      +
      +    auto res = cli.Get("/hi");
      +    if (res) {
      +        std::cout << res->status << std::endl;  // 200
      +        std::cout << res->body << std::endl;    // Hello!
      +    }
      +}
       
       #include "httplib.h"
      @@ -235,9 +237,9 @@
       

      Pass the server address to the httplib::Client constructor, then call Get() to send a request. You can retrieve the status code and body from the returned res.

      Here's the equivalent curl command.

      -
      -curl http://localhost:8080/hi
      -# Hello!
      +
      +curl http://localhost:8080/hi
      +# Hello!
       
       curl http://localhost:8080/hi
      @@ -246,18 +248,18 @@
       

      Checking the Response

      A response contains header information in addition to the status code and body.

      -
      -auto res = cli.Get("/hi");
      -if (res) {
      -    // Status code
      -    std::cout << res->status << std::endl;  // 200
      -
      -    // Body
      -    std::cout << res->body << std::endl;  // Hello!
      -
      -    // Headers
      -    std::cout << res->get_header_value("Content-Type") << std::endl;  // text/plain
      -}
      +
      +auto res = cli.Get("/hi");
      +if (res) {
      +    // Status code
      +    std::cout << res->status << std::endl;  // 200
      +
      +    // Body
      +    std::cout << res->body << std::endl;  // Hello!
      +
      +    // Headers
      +    std::cout << res->get_header_value("Content-Type") << std::endl;  // text/plain
      +}
       
       auto res = cli.Get("/hi");
      @@ -276,11 +278,11 @@
       

      res->body is a std::string, so if you want to parse a JSON response, you can pass it directly to a JSON library like nlohmann/json.

      Query Parameters

      To add query parameters to a GET request, you can either write them directly in the URL or use httplib::Params.

      -
      -auto res = cli.Get("/search", httplib::Params{{"q", "cpp-httplib"}});
      -if (res) {
      -    std::cout << res->body << std::endl;  // Query: cpp-httplib
      -}
      +
      +auto res = cli.Get("/search", httplib::Params{{"q", "cpp-httplib"}});
      +if (res) {
      +    std::cout << res->body << std::endl;  // Query: cpp-httplib
      +}
       
       auto res = cli.Get("/search", httplib::Params{{"q", "cpp-httplib"}});
      @@ -290,9 +292,9 @@
       

      httplib::Params automatically URL-encodes special characters for you.

      -
      -curl "http://localhost:8080/search?q=cpp-httplib"
      -# Query: cpp-httplib
      +
      +curl "http://localhost:8080/search?q=cpp-httplib"
      +# Query: cpp-httplib
       
       curl "http://localhost:8080/search?q=cpp-httplib"
      @@ -301,11 +303,11 @@
       

      Path Parameters

      When values are embedded directly in the URL path, no special client API is needed. Just pass the path to Get() as-is.

      -
      -auto res = cli.Get("/users/42");
      -if (res) {
      -    std::cout << res->body << std::endl;  // User ID: 42
      -}
      +
      +auto res = cli.Get("/users/42");
      +if (res) {
      +    std::cout << res->body << std::endl;  // User ID: 42
      +}
       
       auto res = cli.Get("/users/42");
      @@ -313,9 +315,9 @@
           std::cout << res->body << std::endl;  // User ID: 42
       }
       
      -
      -curl http://localhost:8080/users/42
      -# User ID: 42
      +
      +curl http://localhost:8080/users/42
      +# User ID: 42
       
       curl http://localhost:8080/users/42
      @@ -323,11 +325,11 @@
       

      The test server also has a /files/(\d+) route that uses a regex to accept numeric IDs only.

      -
      -auto res = cli.Get("/files/42");
      -if (res) {
      -    std::cout << res->body << std::endl;  // File ID: 42
      -}
      +
      +auto res = cli.Get("/files/42");
      +if (res) {
      +    std::cout << res->body << std::endl;  // File ID: 42
      +}
       
       auto res = cli.Get("/files/42");
      @@ -335,9 +337,9 @@
           std::cout << res->body << std::endl;  // File ID: 42
       }
       
      -
      -curl http://localhost:8080/files/42
      -# File ID: 42
      +
      +curl http://localhost:8080/files/42
      +# File ID: 42
       
       curl http://localhost:8080/files/42
      @@ -347,18 +349,18 @@
       

      Pass a non-numeric ID like /files/abc and you'll get a 404. We'll cover how that works in the next chapter.

      Request Headers

      To add custom HTTP headers, pass an httplib::Headers object. This works with both Get() and Post().

      -
      -auto res = cli.Get("/hi", httplib::Headers{
      -    {"Authorization", "Bearer my-token"}
      -});
      +
      +auto res = cli.Get("/hi", httplib::Headers{
      +    {"Authorization", "Bearer my-token"}
      +});
       
       auto res = cli.Get("/hi", httplib::Headers{
           {"Authorization", "Bearer my-token"}
       });
       
      -
      -curl -H "Authorization: Bearer my-token" http://localhost:8080/hi
      +
      +curl -H "Authorization: Bearer my-token" http://localhost:8080/hi
       
       curl -H "Authorization: Bearer my-token" http://localhost:8080/hi
      @@ -366,12 +368,12 @@
       

      POST Request

      Let's POST some text data. Pass the body as the second argument to Post() and the Content-Type as the third.

      -
      -auto res = cli.Post("/post", "Hello, Server!", "text/plain");
      -if (res) {
      -    std::cout << res->status << std::endl;  // 200
      -    std::cout << res->body << std::endl;    // Hello, Server!
      -}
      +
      +auto res = cli.Post("/post", "Hello, Server!", "text/plain");
      +if (res) {
      +    std::cout << res->status << std::endl;  // 200
      +    std::cout << res->body << std::endl;    // Hello, Server!
      +}
       
       auto res = cli.Post("/post", "Hello, Server!", "text/plain");
      @@ -382,9 +384,9 @@
       

      The test server's /post endpoint echoes the body back, so you get the same string you sent.

      -
      -curl -X POST -H "Content-Type: text/plain" -d "Hello, Server!" http://localhost:8080/post
      -# Hello, Server!
      +
      +curl -X POST -H "Content-Type: text/plain" -d "Hello, Server!" http://localhost:8080/post
      +# Hello, Server!
       
       curl -X POST -H "Content-Type: text/plain" -d "Hello, Server!" http://localhost:8080/post
      @@ -393,16 +395,16 @@
       

      Sending Form Data

      You can send key-value pairs just like an HTML form. Use httplib::Params for this.

      -
      -auto res = cli.Post("/submit", httplib::Params{
      -    {"name", "Alice"},
      -    {"age", "30"}
      -});
      -if (res) {
      -    std::cout << res->body << std::endl;
      -    // age = 30
      -    // name = Alice
      -}
      +
      +auto res = cli.Post("/submit", httplib::Params{
      +    {"name", "Alice"},
      +    {"age", "30"}
      +});
      +if (res) {
      +    std::cout << res->body << std::endl;
      +    // age = 30
      +    // name = Alice
      +}
       
       auto res = cli.Post("/submit", httplib::Params{
      @@ -417,8 +419,8 @@
       

      This sends the data in application/x-www-form-urlencoded format.

      -
      -curl -X POST -d "name=Alice&age=30" http://localhost:8080/submit
      +
      +curl -X POST -d "name=Alice&age=30" http://localhost:8080/submit
       
       curl -X POST -d "name=Alice&age=30" http://localhost:8080/submit
      @@ -426,13 +428,13 @@
       

      POSTing a File

      To upload a file, use httplib::UploadFormDataItems to send it as multipart form data.

      -
      -auto res = cli.Post("/upload", httplib::UploadFormDataItems{
      -    {"file", "Hello, File!", "hello.txt", "text/plain"}
      -});
      -if (res) {
      -    std::cout << res->body << std::endl;  // hello.txt (12 bytes)
      -}
      +
      +auto res = cli.Post("/upload", httplib::UploadFormDataItems{
      +    {"file", "Hello, File!", "hello.txt", "text/plain"}
      +});
      +if (res) {
      +    std::cout << res->body << std::endl;  // hello.txt (12 bytes)
      +}
       
       auto res = cli.Post("/upload", httplib::UploadFormDataItems{
      @@ -444,8 +446,8 @@
       

      Each element in UploadFormDataItems has four fields: {name, content, filename, content_type}.

      -
      -curl -F "file=Hello, File!;filename=hello.txt;type=text/plain" http://localhost:8080/upload
      +
      +curl -F "file=Hello, File!;filename=hello.txt;type=text/plain" http://localhost:8080/upload
       
       curl -F "file=Hello, File!;filename=hello.txt;type=text/plain" http://localhost:8080/upload
      @@ -453,24 +455,24 @@
       

      Error Handling

      Network communication can fail -- the server might not be reachable. Always check whether res is valid.

      -
      -httplib::Client cli("http://localhost:9999");  // Non-existent port
      -auto res = cli.Get("/hi");
      -
      -if (!res) {
      -    // Connection error
      -    std::cout << "Error: " << httplib::to_string(res.error()) << std::endl;
      -    // Error: Connection
      -    return 1;
      -}
      -
      -// If we reach here, we have a response
      -if (res->status != 200) {
      -    std::cout << "HTTP Error: " << res->status << std::endl;
      -    return 1;
      -}
      -
      -std::cout << res->body << std::endl;
      +
      +httplib::Client cli("http://localhost:9999");  // Non-existent port
      +auto res = cli.Get("/hi");
      +
      +if (!res) {
      +    // Connection error
      +    std::cout << "Error: " << httplib::to_string(res.error()) << std::endl;
      +    // Error: Connection
      +    return 1;
      +}
      +
      +// If we reach here, we have a response
      +if (res->status != 200) {
      +    std::cout << "HTTP Error: " << res->status << std::endl;
      +    return 1;
      +}
      +
      +std::cout << res->body << std::endl;
       
       httplib::Client cli("http://localhost:9999");  // Non-existent port
      @@ -507,7 +509,7 @@
         
      - © 2026 yhirose. All rights reserved. + © 2026 Yuji Hirose. All rights reserved.
      diff --git a/docs/en/tour/03-basic-server/index.html b/docs/en/tour/03-basic-server/index.html index f40e292..27bacff 100644 --- a/docs/en/tour/03-basic-server/index.html +++ b/docs/en/tour/03-basic-server/index.html @@ -17,16 +17,16 @@
      - cpp-httplib v0.36.0 + cpp-httplib v0.36.0
      @@ -105,8 +107,8 @@

      In the previous chapter, you sent requests from a client to a test server. Now let's walk through how that server actually works.

      Starting the Server

      Once you've registered your routes, call svr.listen() to start the server.

      -
      -svr.listen("0.0.0.0", 8080);
      +
      +svr.listen("0.0.0.0", 8080);
       
       svr.listen("0.0.0.0", 8080);
      @@ -116,12 +118,12 @@
       

      listen() is a blocking call. It won't return until the server stops. The server keeps running until you press Ctrl+C in your terminal or call svr.stop() from another thread.

      Routing

      Routing is the heart of any server. It's how you tell cpp-httplib: when a request comes in for this URL with this HTTP method, run this code.

      -
      -httplib::Server svr;
      -
      -svr.Get("/hi", [](const httplib::Request &req, httplib::Response &res) {
      -    res.set_content("Hello!", "text/plain");
      -});
      +
      +httplib::Server svr;
      +
      +svr.Get("/hi", [](const httplib::Request &req, httplib::Response &res) {
      +    res.set_content("Hello!", "text/plain");
      +});
       
       httplib::Server svr;
      @@ -133,11 +135,11 @@
       

      svr.Get() registers a handler for GET requests. The first argument is the path, the second is the handler function. When a GET request arrives at /hi, your lambda runs.

      There's a method for each HTTP verb.

      -
      -svr.Get("/path",    handler);  // GET
      -svr.Post("/path",   handler);  // POST
      -svr.Put("/path",    handler);  // PUT
      -svr.Delete("/path", handler);  // DELETE
      +
      +svr.Get("/path",    handler);  // GET
      +svr.Post("/path",   handler);  // POST
      +svr.Put("/path",    handler);  // PUT
      +svr.Delete("/path", handler);  // DELETE
       
       svr.Get("/path",    handler);  // GET
      @@ -147,10 +149,10 @@
       

      The handler signature is (const httplib::Request &req, httplib::Response &res). You can use auto to keep it short.

      -
      -svr.Get("/hi", [](const auto &req, auto &res) {
      -    res.set_content("Hello!", "text/plain");
      -});
      +
      +svr.Get("/hi", [](const auto &req, auto &res) {
      +    res.set_content("Hello!", "text/plain");
      +});
       
       svr.Get("/hi", [](const auto &req, auto &res) {
      @@ -163,11 +165,11 @@
       

      The first parameter req gives you everything the client sent.

      Body

      req.body holds the request body as a std::string.

      -
      -svr.Post("/post", [](const auto &req, auto &res) {
      -    // Echo the body back to the client
      -    res.set_content(req.body, "text/plain");
      -});
      +
      +svr.Post("/post", [](const auto &req, auto &res) {
      +    // Echo the body back to the client
      +    res.set_content(req.body, "text/plain");
      +});
       
       svr.Post("/post", [](const auto &req, auto &res) {
      @@ -178,11 +180,11 @@
       

      Headers

      Use req.get_header_value() to read a request header.

      -
      -svr.Get("/check", [](const auto &req, auto &res) {
      -    auto auth = req.get_header_value("Authorization");
      -    res.set_content("Auth: " + auth, "text/plain");
      -});
      +
      +svr.Get("/check", [](const auto &req, auto &res) {
      +    auto auth = req.get_header_value("Authorization");
      +    res.set_content("Auth: " + auth, "text/plain");
      +});
       
       svr.Get("/check", [](const auto &req, auto &res) {
      @@ -193,11 +195,11 @@
       

      Query Parameters and Form Data

      req.get_param_value() retrieves a parameter by name. It works for both GET query parameters and POST form data.

      -
      -svr.Get("/search", [](const auto &req, auto &res) {
      -    auto q = req.get_param_value("q");
      -    res.set_content("Query: " + q, "text/plain");
      -});
      +
      +svr.Get("/search", [](const auto &req, auto &res) {
      +    auto q = req.get_param_value("q");
      +    res.set_content("Query: " + q, "text/plain");
      +});
       
       svr.Get("/search", [](const auto &req, auto &res) {
      @@ -208,14 +210,14 @@
       

      A request to /search?q=cpp-httplib gives you "cpp-httplib" for q.

      To loop over all parameters, use req.params.

      -
      -svr.Post("/submit", [](const auto &req, auto &res) {
      -    std::string result;
      -    for (auto &[key, val] : req.params) {
      -        result += key + " = " + val + "\n";
      -    }
      -    res.set_content(result, "text/plain");
      -});
      +
      +svr.Post("/submit", [](const auto &req, auto &res) {
      +    std::string result;
      +    for (auto &[key, val] : req.params) {
      +        result += key + " = " + val + "\n";
      +    }
      +    res.set_content(result, "text/plain");
      +});
       
       svr.Post("/submit", [](const auto &req, auto &res) {
      @@ -229,12 +231,12 @@
       

      File Uploads

      Files uploaded via multipart form data are available through req.form.get_file().

      -
      -svr.Post("/upload", [](const auto &req, auto &res) {
      -    auto f = req.form.get_file("file");
      -    auto content = f.filename + " (" + std::to_string(f.content.size()) + " bytes)";
      -    res.set_content(content, "text/plain");
      -});
      +
      +svr.Post("/upload", [](const auto &req, auto &res) {
      +    auto f = req.form.get_file("file");
      +    auto content = f.filename + " (" + std::to_string(f.content.size()) + " bytes)";
      +    res.set_content(content, "text/plain");
      +});
       
       svr.Post("/upload", [](const auto &req, auto &res) {
      @@ -247,11 +249,11 @@
       

      f.filename gives you the filename, and f.content gives you the file data.

      Path Parameters

      Sometimes you want to capture part of the URL as a variable -- for example, the 42 in /users/42. Use the :param syntax to do that.

      -
      -svr.Get("/users/:id", [](const auto &req, auto &res) {
      -    auto id = req.path_params.at("id");
      -    res.set_content("User ID: " + id, "text/plain");
      -});
      +
      +svr.Get("/users/:id", [](const auto &req, auto &res) {
      +    auto id = req.path_params.at("id");
      +    res.set_content("User ID: " + id, "text/plain");
      +});
       
       svr.Get("/users/:id", [](const auto &req, auto &res) {
      @@ -262,12 +264,12 @@
       

      A request to /users/42 gives you "42" from req.path_params.at("id"). /users/100 gives you "100".

      You can capture multiple segments at once.

      -
      -svr.Get("/users/:user_id/posts/:post_id", [](const auto &req, auto &res) {
      -    auto user_id = req.path_params.at("user_id");
      -    auto post_id = req.path_params.at("post_id");
      -    res.set_content("User: " + user_id + ", Post: " + post_id, "text/plain");
      -});
      +
      +svr.Get("/users/:user_id/posts/:post_id", [](const auto &req, auto &res) {
      +    auto user_id = req.path_params.at("user_id");
      +    auto post_id = req.path_params.at("post_id");
      +    res.set_content("User: " + user_id + ", Post: " + post_id, "text/plain");
      +});
       
       svr.Get("/users/:user_id/posts/:post_id", [](const auto &req, auto &res) {
      @@ -279,12 +281,12 @@
       

      Regex Patterns

      You can also write a regular expression directly in the path instead of :param. Capture group values are available via req.matches, which is a std::smatch.

      -
      -// Only accept numeric IDs
      -svr.Get(R"(/files/(\d+))", [](const auto &req, auto &res) {
      -    auto id = req.matches[1];  // First capture group
      -    res.set_content("File ID: " + std::string(id), "text/plain");
      -});
      +
      +// Only accept numeric IDs
      +svr.Get(R"(/files/(\d+))", [](const auto &req, auto &res) {
      +    auto id = req.matches[1];  // First capture group
      +    res.set_content("File ID: " + std::string(id), "text/plain");
      +});
       
       // Only accept numeric IDs
      @@ -299,10 +301,10 @@
       

      The second parameter res is how you send data back to the client.

      Body and Content-Type

      res.set_content() sets the body and Content-Type. That's all you need for a 200 response.

      -
      -svr.Get("/hi", [](const auto &req, auto &res) {
      -    res.set_content("Hello!", "text/plain");
      -});
      +
      +svr.Get("/hi", [](const auto &req, auto &res) {
      +    res.set_content("Hello!", "text/plain");
      +});
       
       svr.Get("/hi", [](const auto &req, auto &res) {
      @@ -312,11 +314,11 @@
       

      Status Code

      To return a different status code, assign to res.status.

      -
      -svr.Get("/not-found", [](const auto &req, auto &res) {
      -    res.status = 404;
      -    res.set_content("Not found", "text/plain");
      -});
      +
      +svr.Get("/not-found", [](const auto &req, auto &res) {
      +    res.status = 404;
      +    res.set_content("Not found", "text/plain");
      +});
       
       svr.Get("/not-found", [](const auto &req, auto &res) {
      @@ -327,11 +329,11 @@
       

      Response Headers

      Add response headers with res.set_header().

      -
      -svr.Get("/with-header", [](const auto &req, auto &res) {
      -    res.set_header("X-Custom", "my-value");
      -    res.set_content("Hello!", "text/plain");
      -});
      +
      +svr.Get("/with-header", [](const auto &req, auto &res) {
      +    res.set_header("X-Custom", "my-value");
      +    res.set_content("Hello!", "text/plain");
      +});
       
       svr.Get("/with-header", [](const auto &req, auto &res) {
      @@ -343,10 +345,10 @@
       

      Walking Through the Test Server

      Now let's use what we've learned to read through the test server from the previous chapter.

      GET /hi

      -
      -svr.Get("/hi", [](const auto &, auto &res) {
      -    res.set_content("Hello!", "text/plain");
      -});
      +
      +svr.Get("/hi", [](const auto &, auto &res) {
      +    res.set_content("Hello!", "text/plain");
      +});
       
       svr.Get("/hi", [](const auto &, auto &res) {
      @@ -356,11 +358,11 @@
       

      The simplest possible handler. We don't need any information from the request, so the req parameter is left unnamed. It just returns "Hello!".

      GET /search

      -
      -svr.Get("/search", [](const auto &req, auto &res) {
      -    auto q = req.get_param_value("q");
      -    res.set_content("Query: " + q, "text/plain");
      -});
      +
      +svr.Get("/search", [](const auto &req, auto &res) {
      +    auto q = req.get_param_value("q");
      +    res.set_content("Query: " + q, "text/plain");
      +});
       
       svr.Get("/search", [](const auto &req, auto &res) {
      @@ -371,10 +373,10 @@
       

      req.get_param_value("q") pulls out the query parameter q. A request to /search?q=cpp-httplib returns "Query: cpp-httplib".

      POST /post

      -
      -svr.Post("/post", [](const auto &req, auto &res) {
      -    res.set_content(req.body, "text/plain");
      -});
      +
      +svr.Post("/post", [](const auto &req, auto &res) {
      +    res.set_content(req.body, "text/plain");
      +});
       
       svr.Post("/post", [](const auto &req, auto &res) {
      @@ -384,14 +386,14 @@
       

      An echo server. Whatever body the client sends, req.body holds it, and we send it straight back.

      POST /submit

      -
      -svr.Post("/submit", [](const auto &req, auto &res) {
      -    std::string result;
      -    for (auto &[key, val] : req.params) {
      -        result += key + " = " + val + "\n";
      -    }
      -    res.set_content(result, "text/plain");
      -});
      +
      +svr.Post("/submit", [](const auto &req, auto &res) {
      +    std::string result;
      +    for (auto &[key, val] : req.params) {
      +        result += key + " = " + val + "\n";
      +    }
      +    res.set_content(result, "text/plain");
      +});
       
       svr.Post("/submit", [](const auto &req, auto &res) {
      @@ -405,12 +407,12 @@
       

      Loops over the form data in req.params using structured bindings (auto &[key, val]) to unpack each key-value pair.

      POST /upload

      -
      -svr.Post("/upload", [](const auto &req, auto &res) {
      -    auto f = req.form.get_file("file");
      -    auto content = f.filename + " (" + std::to_string(f.content.size()) + " bytes)";
      -    res.set_content(content, "text/plain");
      -});
      +
      +svr.Post("/upload", [](const auto &req, auto &res) {
      +    auto f = req.form.get_file("file");
      +    auto content = f.filename + " (" + std::to_string(f.content.size()) + " bytes)";
      +    res.set_content(content, "text/plain");
      +});
       
       svr.Post("/upload", [](const auto &req, auto &res) {
      @@ -422,11 +424,11 @@
       

      Receives a file uploaded via multipart form data. req.form.get_file("file") fetches the field named "file", and we respond with the filename and size.

      GET /users/:id

      -
      -svr.Get("/users/:id", [](const auto &req, auto &res) {
      -    auto id = req.path_params.at("id");
      -    res.set_content("User ID: " + id, "text/plain");
      -});
      +
      +svr.Get("/users/:id", [](const auto &req, auto &res) {
      +    auto id = req.path_params.at("id");
      +    res.set_content("User ID: " + id, "text/plain");
      +});
       
       svr.Get("/users/:id", [](const auto &req, auto &res) {
      @@ -437,11 +439,11 @@
       

      :id is the path parameter. req.path_params.at("id") retrieves its value. /users/42 gives you "42", /users/alice gives you "alice".

      GET /files/(\d+)

      -
      -svr.Get(R"(/files/(\d+))", [](const auto &req, auto &res) {
      -    auto id = req.matches[1];
      -    res.set_content("File ID: " + std::string(id), "text/plain");
      -});
      +
      +svr.Get(R"(/files/(\d+))", [](const auto &req, auto &res) {
      +    auto id = req.matches[1];
      +    res.set_content("File ID: " + std::string(id), "text/plain");
      +});
       
       svr.Get(R"(/files/(\d+))", [](const auto &req, auto &res) {
      @@ -462,7 +464,7 @@
         
      - © 2026 yhirose. All rights reserved. + © 2026 Yuji Hirose. All rights reserved.
      diff --git a/docs/en/tour/04-static-file-server/index.html b/docs/en/tour/04-static-file-server/index.html index b4f0589..d6a0bbd 100644 --- a/docs/en/tour/04-static-file-server/index.html +++ b/docs/en/tour/04-static-file-server/index.html @@ -17,16 +17,16 @@
      - cpp-httplib v0.36.0 + cpp-httplib v0.36.0
      @@ -105,18 +107,18 @@

      cpp-httplib can serve static files too — HTML, CSS, images, you name it. No complicated configuration required. One call to set_mount_point() is all it takes.

      The basics of set_mount_point

      Let's jump right in. set_mount_point() maps a URL path to a local directory.

      -
      -#include "httplib.h"
      -#include <iostream>
      -
      -int main() {
      -    httplib::Server svr;
      -
      -    svr.set_mount_point("/", "./html");
      -
      -    std::cout << "Listening on port 8080..." << std::endl;
      -    svr.listen("0.0.0.0", 8080);
      -}
      +
      +#include "httplib.h"
      +#include <iostream>
      +
      +int main() {
      +    httplib::Server svr;
      +
      +    svr.set_mount_point("/", "./html");
      +
      +    std::cout << "Listening on port 8080..." << std::endl;
      +    svr.listen("0.0.0.0", 8080);
      +}
       
       #include "httplib.h"
      @@ -134,21 +136,21 @@
       

      The first argument is the URL mount point. The second is the local directory path. In this example, requests to / are served from the ./html directory.

      Let's try it out. First, create an html directory and add an index.html file.

      -
      -mkdir html
      +
      +mkdir html
       
       mkdir html
       
      -
      -<!DOCTYPE html>
      -<html>
      -<head><title>My Page</title></head>
      -<body>
      -    <h1>Hello from cpp-httplib!</h1>
      -    <p>This is a static file.</p>
      -</body>
      -</html>
      +
      +<!DOCTYPE html>
      +<html>
      +<head><title>My Page</title></head>
      +<body>
      +    <h1>Hello from cpp-httplib!</h1>
      +    <p>This is a static file.</p>
      +</body>
      +</html>
       
       <!DOCTYPE html>
      @@ -162,9 +164,9 @@
       

      Compile and start the server.

      -
      -g++ -std=c++17 -o server server.cpp -pthread
      -./server
      +
      +g++ -std=c++17 -o server server.cpp -pthread
      +./server
       
       g++ -std=c++17 -o server server.cpp -pthread
      @@ -173,12 +175,12 @@
       

      Open http://localhost:8080 in your browser. You should see the contents of html/index.html. Visiting http://localhost:8080/index.html returns the same page.

      You can also access it with the client code from the previous chapter, or with curl.

      -
      -httplib::Client cli("http://localhost:8080");
      -auto res = cli.Get("/");
      -if (res) {
      -    std::cout << res->body << std::endl;  // HTML is displayed
      -}
      +
      +httplib::Client cli("http://localhost:8080");
      +auto res = cli.Get("/");
      +if (res) {
      +    std::cout << res->body << std::endl;  // HTML is displayed
      +}
       
       httplib::Client cli("http://localhost:8080");
      @@ -187,8 +189,8 @@
           std::cout << res->body << std::endl;  // HTML is displayed
       }
       
      -
      -curl http://localhost:8080
      +
      +curl http://localhost:8080
       
       curl http://localhost:8080
      @@ -196,10 +198,10 @@
       

      Multiple mount points

      You can call set_mount_point() as many times as you like. Each URL path gets its own directory.

      -
      -svr.set_mount_point("/", "./public");
      -svr.set_mount_point("/assets", "./static/assets");
      -svr.set_mount_point("/docs", "./documentation");
      +
      +svr.set_mount_point("/", "./public");
      +svr.set_mount_point("/assets", "./static/assets");
      +svr.set_mount_point("/docs", "./documentation");
       
       svr.set_mount_point("/", "./public");
      @@ -210,18 +212,18 @@
       

      A request to /assets/style.css serves ./static/assets/style.css. A request to /docs/guide.html serves ./documentation/guide.html.

      Combining with handlers

      Static file serving and routing handlers — the kind you learned about in the previous chapter — work side by side.

      -
      -httplib::Server svr;
      -
      -// API endpoint
      -svr.Get("/api/hello", [](const auto &, auto &res) {
      -    res.set_content(R"({"message":"Hello!"})", "application/json");
      -});
      -
      -// Static file serving
      -svr.set_mount_point("/", "./public");
      -
      -svr.listen("0.0.0.0", 8080);
      +
      +httplib::Server svr;
      +
      +// API endpoint
      +svr.Get("/api/hello", [](const auto &, auto &res) {
      +    res.set_content(R"({"message":"Hello!"})", "application/json");
      +});
      +
      +// Static file serving
      +svr.set_mount_point("/", "./public");
      +
      +svr.listen("0.0.0.0", 8080);
       
       httplib::Server svr;
      @@ -240,10 +242,10 @@
       

      Handlers take priority. The handler responds to /api/hello. For every other path, the server looks for a file in ./public.

      Adding response headers

      Pass headers as the third argument to set_mount_point() and they get attached to every static file response. This is great for cache control.

      -
      -svr.set_mount_point("/", "./public", {
      -    {"Cache-Control", "max-age=3600"}
      -});
      +
      +svr.set_mount_point("/", "./public", {
      +    {"Cache-Control", "max-age=3600"}
      +});
       
       svr.set_mount_point("/", "./public", {
      @@ -254,14 +256,14 @@
       

      With this in place, the browser caches served files for one hour.

      A Dockerfile for your static file server

      The cpp-httplib repository includes a Dockerfile built for static file serving. We also publish a pre-built image on Docker Hub, so you can get up and running with a single command.

      -
      -> docker run -p 8080:80 -v ./my-site:/html yhirose4dockerhub/cpp-httplib-server
      -Serving HTTP on 0.0.0.0:80
      -Mount point: / -> ./html
      -Press Ctrl+C to shutdown gracefully...
      -192.168.65.1 - - [22/Feb/2026:12:00:00 +0000] "GET / HTTP/1.1" 200 256 "-" "Mozilla/5.0 ..."
      -192.168.65.1 - - [22/Feb/2026:12:00:00 +0000] "GET /style.css HTTP/1.1" 200 1024 "-" "Mozilla/5.0 ..."
      -192.168.65.1 - - [22/Feb/2026:12:00:01 +0000] "GET /favicon.ico HTTP/1.1" 404 152 "-" "Mozilla/5.0 ..."
      +
      +> docker run -p 8080:80 -v ./my-site:/html yhirose4dockerhub/cpp-httplib-server
      +Serving HTTP on 0.0.0.0:80
      +Mount point: / -> ./html
      +Press Ctrl+C to shutdown gracefully...
      +192.168.65.1 - - [22/Feb/2026:12:00:00 +0000] "GET / HTTP/1.1" 200 256 "-" "Mozilla/5.0 ..."
      +192.168.65.1 - - [22/Feb/2026:12:00:00 +0000] "GET /style.css HTTP/1.1" 200 1024 "-" "Mozilla/5.0 ..."
      +192.168.65.1 - - [22/Feb/2026:12:00:01 +0000] "GET /favicon.ico HTTP/1.1" 404 152 "-" "Mozilla/5.0 ..."
       
       > docker run -p 8080:80 -v ./my-site:/html yhirose4dockerhub/cpp-httplib-server
      @@ -285,7 +287,7 @@
         
      - © 2026 yhirose. All rights reserved. + © 2026 Yuji Hirose. All rights reserved.
      diff --git a/docs/en/tour/05-tls-setup/index.html b/docs/en/tour/05-tls-setup/index.html index b03c123..1819f56 100644 --- a/docs/en/tour/05-tls-setup/index.html +++ b/docs/en/tour/05-tls-setup/index.html @@ -17,16 +17,16 @@
      - cpp-httplib v0.36.0 + cpp-httplib v0.36.0
      @@ -113,22 +115,22 @@

      Compile Options

      To enable TLS, define the CPPHTTPLIB_OPENSSL_SUPPORT macro when compiling. You'll need a few extra options compared to the previous chapters.

      -
      -# macOS (Homebrew)
      -clang++ -std=c++17 -DCPPHTTPLIB_OPENSSL_SUPPORT \
      -    -I$(brew --prefix openssl)/include \
      -    -L$(brew --prefix openssl)/lib \
      -    -lssl -lcrypto \
      -    -framework CoreFoundation -framework Security \
      -    -o server server.cpp
      -
      -# Linux
      -clang++ -std=c++17 -pthread -DCPPHTTPLIB_OPENSSL_SUPPORT \
      -    -lssl -lcrypto \
      -    -o server server.cpp
      -
      -# Windows (Developer Command Prompt)
      -cl /EHsc /std:c++17 /DCPPHTTPLIB_OPENSSL_SUPPORT server.cpp libssl.lib libcrypto.lib
      +
      +# macOS (Homebrew)
      +clang++ -std=c++17 -DCPPHTTPLIB_OPENSSL_SUPPORT \
      +    -I$(brew --prefix openssl)/include \
      +    -L$(brew --prefix openssl)/lib \
      +    -lssl -lcrypto \
      +    -framework CoreFoundation -framework Security \
      +    -o server server.cpp
      +
      +# Linux
      +clang++ -std=c++17 -pthread -DCPPHTTPLIB_OPENSSL_SUPPORT \
      +    -lssl -lcrypto \
      +    -o server server.cpp
      +
      +# Windows (Developer Command Prompt)
      +cl /EHsc /std:c++17 /DCPPHTTPLIB_OPENSSL_SUPPORT server.cpp libssl.lib libcrypto.lib
       
       # macOS (Homebrew)
      @@ -157,21 +159,21 @@
       
       

      Verifying the Setup

      Let's make sure everything works. Here's a simple program that passes an HTTPS URL to httplib::Client.

      -
      -#define CPPHTTPLIB_OPENSSL_SUPPORT
      -#include "httplib.h"
      -#include <iostream>
      -
      -int main() {
      -    httplib::Client cli("https://www.google.com");
      -
      -    auto res = cli.Get("/");
      -    if (res) {
      -        std::cout << "Status: " << res->status << std::endl;
      -    } else {
      -        std::cout << "Error: " << httplib::to_string(res.error()) << std::endl;
      -    }
      -}
      +
      +#define CPPHTTPLIB_OPENSSL_SUPPORT
      +#include "httplib.h"
      +#include <iostream>
      +
      +int main() {
      +    httplib::Client cli("https://www.google.com");
      +
      +    auto res = cli.Get("/");
      +    if (res) {
      +        std::cout << "Status: " << res->status << std::endl;
      +    } else {
      +        std::cout << "Error: " << httplib::to_string(res.error()) << std::endl;
      +    }
      +}
       
       #define CPPHTTPLIB_OPENSSL_SUPPORT
      @@ -209,7 +211,7 @@
         
      - © 2026 yhirose. All rights reserved. + © 2026 Yuji Hirose. All rights reserved.
      diff --git a/docs/en/tour/06-https-client/index.html b/docs/en/tour/06-https-client/index.html index 602996f..a13ffb8 100644 --- a/docs/en/tour/06-https-client/index.html +++ b/docs/en/tour/06-https-client/index.html @@ -17,16 +17,16 @@
      - cpp-httplib v0.36.0 + cpp-httplib v0.36.0
      @@ -105,22 +107,22 @@

      In the previous chapter, you set up OpenSSL. Now let's put it to use with an HTTPS client. You can use the same httplib::Client from Chapter 2. Just pass a URL with the https:// scheme to the constructor.

      GET Request

      Let's try accessing a real HTTPS site.

      -
      -#define CPPHTTPLIB_OPENSSL_SUPPORT
      -#include "httplib.h"
      -#include <iostream>
      -
      -int main() {
      -    httplib::Client cli("https://nghttp2.org");
      -
      -    auto res = cli.Get("/");
      -    if (res) {
      -        std::cout << res->status << std::endl;           // 200
      -        std::cout << res->body.substr(0, 100) << std::endl;  // First 100 chars of the HTML
      -    } else {
      -        std::cout << "Error: " << httplib::to_string(res.error()) << std::endl;
      -    }
      -}
      +
      +#define CPPHTTPLIB_OPENSSL_SUPPORT
      +#include "httplib.h"
      +#include <iostream>
      +
      +int main() {
      +    httplib::Client cli("https://nghttp2.org");
      +
      +    auto res = cli.Get("/");
      +    if (res) {
      +        std::cout << res->status << std::endl;           // 200
      +        std::cout << res->body.substr(0, 100) << std::endl;  // First 100 chars of the HTML
      +    } else {
      +        std::cout << "Error: " << httplib::to_string(res.error()) << std::endl;
      +    }
      +}
       
       #define CPPHTTPLIB_OPENSSL_SUPPORT
      @@ -141,8 +143,8 @@
       

      In Chapter 2, you wrote httplib::Client cli("http://localhost:8080"). All you need to change is the scheme to https://. Every API you learned in Chapter 2 -- Get(), Post(), and so on -- works exactly the same way.

      -
      -curl https://nghttp2.org/
      +
      +curl https://nghttp2.org/
       
       curl https://nghttp2.org/
      @@ -150,8 +152,8 @@
       

      Specifying a Port

      The default port for HTTPS is 443. If you need a different port, include it in the URL.

      -
      -httplib::Client cli("https://localhost:8443");
      +
      +httplib::Client cli("https://localhost:8443");
       
       httplib::Client cli("https://localhost:8443");
      @@ -162,11 +164,11 @@
       

      CA certificates are loaded automatically from the Keychain on macOS, the system CA certificate store on Linux, and the Windows certificate store on Windows. In most cases, no extra configuration is needed.

      Specifying a CA Certificate File

      On some environments, the system CA certificates may not be found. In that case, use set_ca_cert_path() to specify the path directly.

      -
      -httplib::Client cli("https://nghttp2.org");
      -cli.set_ca_cert_path("/etc/ssl/certs/ca-certificates.crt");
      -
      -auto res = cli.Get("/");
      +
      +httplib::Client cli("https://nghttp2.org");
      +cli.set_ca_cert_path("/etc/ssl/certs/ca-certificates.crt");
      +
      +auto res = cli.Get("/");
       
       httplib::Client cli("https://nghttp2.org");
      @@ -174,8 +176,8 @@
       
       auto res = cli.Get("/");
       
      -
      -curl --cacert /etc/ssl/certs/ca-certificates.crt https://nghttp2.org/
      +
      +curl --cacert /etc/ssl/certs/ca-certificates.crt https://nghttp2.org/
       
       curl --cacert /etc/ssl/certs/ca-certificates.crt https://nghttp2.org/
      @@ -183,11 +185,11 @@
       

      Disabling Certificate Verification

      During development, you might want to connect to a server with a self-signed certificate. You can disable verification for that.

      -
      -httplib::Client cli("https://localhost:8443");
      -cli.enable_server_certificate_verification(false);
      -
      -auto res = cli.Get("/");
      +
      +httplib::Client cli("https://localhost:8443");
      +cli.enable_server_certificate_verification(false);
      +
      +auto res = cli.Get("/");
       
       httplib::Client cli("https://localhost:8443");
      @@ -195,8 +197,8 @@
       
       auto res = cli.Get("/");
       
      -
      -curl -k https://localhost:8443/
      +
      +curl -k https://localhost:8443/
       
       curl -k https://localhost:8443/
      @@ -206,14 +208,14 @@
       

      Following Redirects

      When accessing HTTPS sites, you'll often encounter redirects. For example, http:// to https://, or a bare domain to www.

      By default, redirects are not followed. You can check the redirect target in the Location header.

      -
      -httplib::Client cli("https://nghttp2.org");
      -
      -auto res = cli.Get("/httpbin/redirect/3");
      -if (res) {
      -    std::cout << res->status << std::endl;  // 302
      -    std::cout << res->get_header_value("Location") << std::endl;
      -}
      +
      +httplib::Client cli("https://nghttp2.org");
      +
      +auto res = cli.Get("/httpbin/redirect/3");
      +if (res) {
      +    std::cout << res->status << std::endl;  // 302
      +    std::cout << res->get_header_value("Location") << std::endl;
      +}
       
       httplib::Client cli("https://nghttp2.org");
      @@ -224,22 +226,22 @@
           std::cout << res->get_header_value("Location") << std::endl;
       }
       
      -
      -curl https://nghttp2.org/httpbin/redirect/3
      +
      +curl https://nghttp2.org/httpbin/redirect/3
       
       curl https://nghttp2.org/httpbin/redirect/3
       

      Call set_follow_location(true) to automatically follow redirects and get the final response.

      -
      -httplib::Client cli("https://nghttp2.org");
      -cli.set_follow_location(true);
      -
      -auto res = cli.Get("/httpbin/redirect/3");
      -if (res) {
      -    std::cout << res->status << std::endl;  // 200 (the final response)
      -}
      +
      +httplib::Client cli("https://nghttp2.org");
      +cli.set_follow_location(true);
      +
      +auto res = cli.Get("/httpbin/redirect/3");
      +if (res) {
      +    std::cout << res->status << std::endl;  // 200 (the final response)
      +}
       
       httplib::Client cli("https://nghttp2.org");
      @@ -250,8 +252,8 @@
           std::cout << res->status << std::endl;  // 200 (the final response)
       }
       
      -
      -curl -L https://nghttp2.org/httpbin/redirect/3
      +
      +curl -L https://nghttp2.org/httpbin/redirect/3
       
       curl -L https://nghttp2.org/httpbin/redirect/3
      @@ -267,7 +269,7 @@
         
      - © 2026 yhirose. All rights reserved. + © 2026 Yuji Hirose. All rights reserved.
      diff --git a/docs/en/tour/07-https-server/index.html b/docs/en/tour/07-https-server/index.html index 42c0045..14c97bb 100644 --- a/docs/en/tour/07-https-server/index.html +++ b/docs/en/tour/07-https-server/index.html @@ -17,16 +17,16 @@
      - cpp-httplib v0.36.0 + cpp-httplib v0.36.0
      @@ -106,8 +108,8 @@

      A TLS server needs a server certificate and a private key, though. Let's get those ready first.

      Creating a Self-Signed Certificate

      For development and testing, a self-signed certificate works just fine. You can generate one quickly with an OpenSSL command.

      -
      -openssl req -x509 -noenc -keyout key.pem -out cert.pem -subj /CN=localhost
      +
      +openssl req -x509 -noenc -keyout key.pem -out cert.pem -subj /CN=localhost
       
       openssl req -x509 -noenc -keyout key.pem -out cert.pem -subj /CN=localhost
      @@ -120,21 +122,21 @@
       
       

      A Minimal HTTPS Server

      Once you have your certificate, let's write the server.

      -
      -#define CPPHTTPLIB_OPENSSL_SUPPORT
      -#include "httplib.h"
      -#include <iostream>
      -
      -int main() {
      -    httplib::SSLServer svr("cert.pem", "key.pem");
      -
      -    svr.Get("/", [](const auto &, auto &res) {
      -        res.set_content("Hello, HTTPS!", "text/plain");
      -    });
      -
      -    std::cout << "Listening on https://localhost:8443" << std::endl;
      -    svr.listen("0.0.0.0", 8443);
      -}
      +
      +#define CPPHTTPLIB_OPENSSL_SUPPORT
      +#include "httplib.h"
      +#include <iostream>
      +
      +int main() {
      +    httplib::SSLServer svr("cert.pem", "key.pem");
      +
      +    svr.Get("/", [](const auto &, auto &res) {
      +        res.set_content("Hello, HTTPS!", "text/plain");
      +    });
      +
      +    std::cout << "Listening on https://localhost:8443" << std::endl;
      +    svr.listen("0.0.0.0", 8443);
      +}
       
       #define CPPHTTPLIB_OPENSSL_SUPPORT
      @@ -157,9 +159,9 @@
       

      Compile and start it up.

      Testing It Out

      With the server running, try accessing it with curl. Since we're using a self-signed certificate, add the -k option to skip certificate verification.

      -
      -curl -k https://localhost:8443/
      -# Hello, HTTPS!
      +
      +curl -k https://localhost:8443/
      +# Hello, HTTPS!
       
       curl -k https://localhost:8443/
      @@ -171,20 +173,20 @@
       

      Let's connect using httplib::Client from the previous chapter. There are two ways to connect to a server with a self-signed certificate.

      Option 1: Disable Certificate Verification

      This is the quick and easy approach for development.

      -
      -#define CPPHTTPLIB_OPENSSL_SUPPORT
      -#include "httplib.h"
      -#include <iostream>
      -
      -int main() {
      -    httplib::Client cli("https://localhost:8443");
      -    cli.enable_server_certificate_verification(false);
      -
      -    auto res = cli.Get("/");
      -    if (res) {
      -        std::cout << res->body << std::endl;  // Hello, HTTPS!
      -    }
      -}
      +
      +#define CPPHTTPLIB_OPENSSL_SUPPORT
      +#include "httplib.h"
      +#include <iostream>
      +
      +int main() {
      +    httplib::Client cli("https://localhost:8443");
      +    cli.enable_server_certificate_verification(false);
      +
      +    auto res = cli.Get("/");
      +    if (res) {
      +        std::cout << res->body << std::endl;  // Hello, HTTPS!
      +    }
      +}
       
       #define CPPHTTPLIB_OPENSSL_SUPPORT
      @@ -204,20 +206,20 @@
       

      Option 2: Specify the Self-Signed Certificate as a CA Certificate

      This is the safer approach. You tell the client to trust cert.pem as a CA certificate.

      -
      -#define CPPHTTPLIB_OPENSSL_SUPPORT
      -#include "httplib.h"
      -#include <iostream>
      -
      -int main() {
      -    httplib::Client cli("https://localhost:8443");
      -    cli.set_ca_cert_path("cert.pem");
      -
      -    auto res = cli.Get("/");
      -    if (res) {
      -        std::cout << res->body << std::endl;  // Hello, HTTPS!
      -    }
      -}
      +
      +#define CPPHTTPLIB_OPENSSL_SUPPORT
      +#include "httplib.h"
      +#include <iostream>
      +
      +int main() {
      +    httplib::Client cli("https://localhost:8443");
      +    cli.set_ca_cert_path("cert.pem");
      +
      +    auto res = cli.Get("/");
      +    if (res) {
      +        std::cout << res->body << std::endl;  // Hello, HTTPS!
      +    }
      +}
       
       #define CPPHTTPLIB_OPENSSL_SUPPORT
      @@ -256,7 +258,7 @@
         
      - © 2026 yhirose. All rights reserved. + © 2026 Yuji Hirose. All rights reserved.
      diff --git a/docs/en/tour/08-websocket/index.html b/docs/en/tour/08-websocket/index.html index 1b34c3e..5b13259 100644 --- a/docs/en/tour/08-websocket/index.html +++ b/docs/en/tour/08-websocket/index.html @@ -17,16 +17,16 @@
      - cpp-httplib v0.36.0 + cpp-httplib v0.36.0
      @@ -106,23 +108,23 @@

      Let's build an echo server and client right away.

      Echo Server

      Here's an echo server that sends back whatever message it receives.

      -
      -#include "httplib.h"
      -#include <iostream>
      -
      -int main() {
      -    httplib::Server svr;
      -
      -    svr.WebSocket("/ws", [](const httplib::Request &, httplib::ws::WebSocket &ws) {
      -        std::string msg;
      -        while (ws.read(msg)) {
      -            ws.send(msg);  // Send back the received message as-is
      -        }
      -    });
      -
      -    std::cout << "Listening on port 8080..." << std::endl;
      -    svr.listen("0.0.0.0", 8080);
      -}
      +
      +#include "httplib.h"
      +#include <iostream>
      +
      +int main() {
      +    httplib::Server svr;
      +
      +    svr.WebSocket("/ws", [](const httplib::Request &, httplib::ws::WebSocket &ws) {
      +        std::string msg;
      +        while (ws.read(msg)) {
      +            ws.send(msg);  // Send back the received message as-is
      +        }
      +    });
      +
      +    std::cout << "Listening on port 8080..." << std::endl;
      +    svr.listen("0.0.0.0", 8080);
      +}
       
       #include "httplib.h"
      @@ -147,29 +149,29 @@
       

      Inside the handler, ws.read(msg) waits for a message. When the connection closes, read() returns false, so the loop exits. ws.send(msg) sends a message back.

      Connecting from a Client

      Let's connect to the server using httplib::ws::WebSocketClient.

      -
      -#include "httplib.h"
      -#include <iostream>
      -
      -int main() {
      -    httplib::ws::WebSocketClient client("ws://localhost:8080/ws");
      -
      -    if (!client.connect()) {
      -        std::cout << "Connection failed" << std::endl;
      -        return 1;
      -    }
      -
      -    // Send a message
      -    client.send("Hello, WebSocket!");
      -
      -    // Receive a response from the server
      -    std::string msg;
      -    if (client.read(msg)) {
      -        std::cout << msg << std::endl;  // Hello, WebSocket!
      -    }
      -
      -    client.close();
      -}
      +
      +#include "httplib.h"
      +#include <iostream>
      +
      +int main() {
      +    httplib::ws::WebSocketClient client("ws://localhost:8080/ws");
      +
      +    if (!client.connect()) {
      +        std::cout << "Connection failed" << std::endl;
      +        return 1;
      +    }
      +
      +    // Send a message
      +    client.send("Hello, WebSocket!");
      +
      +    // Receive a response from the server
      +    std::string msg;
      +    if (client.read(msg)) {
      +        std::cout << msg << std::endl;  // Hello, WebSocket!
      +    }
      +
      +    client.close();
      +}
       
       #include "httplib.h"
      @@ -199,18 +201,18 @@
       

      Pass a URL in ws://host:port/path format to the constructor. Call connect() to start the connection, then use send() and read() to exchange messages.

      Text and Binary

      WebSocket has two types of messages: text and binary. You can tell them apart by the return value of read().

      -
      -svr.WebSocket("/ws", [](const httplib::Request &, httplib::ws::WebSocket &ws) {
      -    std::string msg;
      -    httplib::ws::ReadResult ret;
      -    while ((ret = ws.read(msg))) {
      -        if (ret == httplib::ws::Binary) {
      -            ws.send(msg.data(), msg.size());  // Send as binary
      -        } else {
      -            ws.send(msg);  // Send as text
      -        }
      -    }
      -});
      +
      +svr.WebSocket("/ws", [](const httplib::Request &, httplib::ws::WebSocket &ws) {
      +    std::string msg;
      +    httplib::ws::ReadResult ret;
      +    while ((ret = ws.read(msg))) {
      +        if (ret == httplib::ws::Binary) {
      +            ws.send(msg.data(), msg.size());  // Send as binary
      +        } else {
      +            ws.send(msg);  // Send as text
      +        }
      +    }
      +});
       
       svr.WebSocket("/ws", [](const httplib::Request &, httplib::ws::WebSocket &ws) {
      @@ -233,19 +235,19 @@
       

      The client-side API is the same.

      Accessing Request Information

      You can read HTTP request information from the handshake through the first argument req in the handler. This is handy for checking authentication tokens.

      -
      -svr.WebSocket("/ws", [](const httplib::Request &req, httplib::ws::WebSocket &ws) {
      -    auto token = req.get_header_value("Authorization");
      -    if (token.empty()) {
      -        ws.close(httplib::ws::CloseStatus::PolicyViolation, "unauthorized");
      -        return;
      -    }
      -
      -    std::string msg;
      -    while (ws.read(msg)) {
      -        ws.send(msg);
      -    }
      -});
      +
      +svr.WebSocket("/ws", [](const httplib::Request &req, httplib::ws::WebSocket &ws) {
      +    auto token = req.get_header_value("Authorization");
      +    if (token.empty()) {
      +        ws.close(httplib::ws::CloseStatus::PolicyViolation, "unauthorized");
      +        return;
      +    }
      +
      +    std::string msg;
      +    while (ws.read(msg)) {
      +        ws.send(msg);
      +    }
      +});
       
       svr.WebSocket("/ws", [](const httplib::Request &req, httplib::ws::WebSocket &ws) {
      @@ -264,17 +266,17 @@
       

      Using WSS

      WebSocket over HTTPS (WSS) is also supported. On the server side, just register a WebSocket handler on httplib::SSLServer.

      -
      -httplib::SSLServer svr("cert.pem", "key.pem");
      -
      -svr.WebSocket("/ws", [](const httplib::Request &, httplib::ws::WebSocket &ws) {
      -    std::string msg;
      -    while (ws.read(msg)) {
      -        ws.send(msg);
      -    }
      -});
      -
      -svr.listen("0.0.0.0", 8443);
      +
      +httplib::SSLServer svr("cert.pem", "key.pem");
      +
      +svr.WebSocket("/ws", [](const httplib::Request &, httplib::ws::WebSocket &ws) {
      +    std::string msg;
      +    while (ws.read(msg)) {
      +        ws.send(msg);
      +    }
      +});
      +
      +svr.listen("0.0.0.0", 8443);
       
       httplib::SSLServer svr("cert.pem", "key.pem");
      @@ -290,8 +292,8 @@
       

      On the client side, use the wss:// scheme.

      -
      -httplib::ws::WebSocketClient client("wss://localhost:8443/ws");
      +
      +httplib::ws::WebSocketClient client("wss://localhost:8443/ws");
       
       httplib::ws::WebSocketClient client("wss://localhost:8443/ws");
      @@ -308,7 +310,7 @@
         
      - © 2026 yhirose. All rights reserved. + © 2026 Yuji Hirose. All rights reserved.
      diff --git a/docs/en/tour/09-whats-next/index.html b/docs/en/tour/09-whats-next/index.html index 17d440d..6641b85 100644 --- a/docs/en/tour/09-whats-next/index.html +++ b/docs/en/tour/09-whats-next/index.html @@ -17,16 +17,16 @@
      - cpp-httplib v0.36.0 + cpp-httplib v0.36.0
      @@ -105,16 +107,16 @@

      Great job finishing the Tour! You now have a solid grasp of the cpp-httplib basics. But there's a lot more to explore. Here's a quick overview of features we didn't cover in the Tour, organized by category.

      Streaming API

      When you're working with LLM streaming responses or downloading large files, you don't want to load the entire response into memory. Use stream::Get() to process data chunk by chunk.

      -
      -httplib::Client cli("http://localhost:11434");
      -
      -auto result = httplib::stream::Get(cli, "/api/generate");
      -
      -if (result) {
      -    while (result.next()) {
      -        std::cout.write(result.data(), result.size());
      -    }
      -}
      +
      +httplib::Client cli("http://localhost:11434");
      +
      +auto result = httplib::stream::Get(cli, "/api/generate");
      +
      +if (result) {
      +    while (result.next()) {
      +        std::cout.write(result.data(), result.size());
      +    }
      +}
       
       httplib::Client cli("http://localhost:11434");
      @@ -129,13 +131,13 @@
       

      You can also pass a content_receiver callback to Get(). This approach works with Keep-Alive.

      -
      -httplib::Client cli("http://localhost:8080");
      -
      -cli.Get("/stream", [](const char *data, size_t len) {
      -    std::cout.write(data, len);
      -    return true;
      -});
      +
      +httplib::Client cli("http://localhost:8080");
      +
      +cli.Get("/stream", [](const char *data, size_t len) {
      +    std::cout.write(data, len);
      +    return true;
      +});
       
       httplib::Client cli("http://localhost:8080");
      @@ -147,25 +149,25 @@
       

      On the server side, you have set_content_provider() and set_chunked_content_provider(). Use the former when you know the size, and the latter when you don't.

      -
      -// With known size (sets Content-Length)
      -svr.Get("/file", [](const auto &, auto &res) {
      -    auto size = get_file_size("large.bin");
      -    res.set_content_provider(size, "application/octet-stream",
      -        [](size_t offset, size_t length, httplib::DataSink &sink) {
      -            // Send 'length' bytes starting from 'offset'
      -            return true;
      -        });
      -});
      -
      -// Unknown size (Chunked Transfer Encoding)
      -svr.Get("/stream", [](const auto &, auto &res) {
      -    res.set_chunked_content_provider("text/plain",
      -        [](size_t offset, httplib::DataSink &sink) {
      -            sink.write("chunk\n", 6);
      -            return true;  // Return false to finish
      -        });
      -});
      +
      +// With known size (sets Content-Length)
      +svr.Get("/file", [](const auto &, auto &res) {
      +    auto size = get_file_size("large.bin");
      +    res.set_content_provider(size, "application/octet-stream",
      +        [](size_t offset, size_t length, httplib::DataSink &sink) {
      +            // Send 'length' bytes starting from 'offset'
      +            return true;
      +        });
      +});
      +
      +// Unknown size (Chunked Transfer Encoding)
      +svr.Get("/stream", [](const auto &, auto &res) {
      +    res.set_chunked_content_provider("text/plain",
      +        [](size_t offset, httplib::DataSink &sink) {
      +            sink.write("chunk\n", 6);
      +            return true;  // Return false to finish
      +        });
      +});
       
       // With known size (sets Content-Length)
      @@ -189,12 +191,12 @@
       

      For uploading large files, make_file_provider() comes in handy. It streams the file instead of loading it all into memory.

      -
      -httplib::Client cli("http://localhost:8080");
      -
      -auto res = cli.Post("/upload", {}, {
      -    httplib::make_file_provider("file", "/path/to/large-file.zip")
      -});
      +
      +httplib::Client cli("http://localhost:8080");
      +
      +auto res = cli.Post("/upload", {}, {
      +    httplib::make_file_provider("file", "/path/to/large-file.zip")
      +});
       
       httplib::Client cli("http://localhost:8080");
      @@ -206,15 +208,15 @@
       

      Server-Sent Events (SSE)

      We provide an SSE client as well. It supports automatic reconnection and resuming via Last-Event-ID.

      -
      -httplib::Client cli("http://localhost:8080");
      -httplib::sse::SSEClient sse(cli, "/events");
      -
      -sse.on_message([](const httplib::sse::SSEMessage &msg) {
      -    std::cout << msg.event << ": " << msg.data << std::endl;
      -});
      -
      -sse.start();  // Blocking, with auto-reconnection
      +
      +httplib::Client cli("http://localhost:8080");
      +httplib::sse::SSEClient sse(cli, "/events");
      +
      +sse.on_message([](const httplib::sse::SSEMessage &msg) {
      +    std::cout << msg.event << ": " << msg.data << std::endl;
      +});
      +
      +sse.start();  // Blocking, with auto-reconnection
       
       httplib::Client cli("http://localhost:8080");
      @@ -228,10 +230,10 @@
       

      You can also set separate handlers for each event type.

      -
      -sse.on_event("update", [](const httplib::sse::SSEMessage &msg) {
      -    // Only handles "update" events
      -});
      +
      +sse.on_event("update", [](const httplib::sse::SSEMessage &msg) {
      +    // Only handles "update" events
      +});
       
       sse.on_event("update", [](const httplib::sse::SSEMessage &msg) {
      @@ -241,10 +243,10 @@
       

      Authentication

      The client has helpers for Basic auth, Bearer Token auth, and Digest auth.

      -
      -httplib::Client cli("https://api.example.com");
      -cli.set_basic_auth("user", "password");
      -cli.set_bearer_token_auth("my-token");
      +
      +httplib::Client cli("https://api.example.com");
      +cli.set_basic_auth("user", "password");
      +cli.set_bearer_token_auth("my-token");
       
       httplib::Client cli("https://api.example.com");
      @@ -259,10 +261,10 @@
       BrotliCPPHTTPLIB_BROTLI_SUPPORT
       ZstandardCPPHTTPLIB_ZSTD_SUPPORT
       
      -
      -httplib::Client cli("https://example.com");
      -cli.set_compress(true);    // Compress request body
      -cli.set_decompress(true);  // Decompress response body
      +
      +httplib::Client cli("https://example.com");
      +cli.set_compress(true);    // Compress request body
      +cli.set_decompress(true);  // Decompress response body
       
       httplib::Client cli("https://example.com");
      @@ -272,10 +274,10 @@
       

      Proxy

      You can connect through an HTTP proxy.

      -
      -httplib::Client cli("https://example.com");
      -cli.set_proxy("proxy.example.com", 8080);
      -cli.set_proxy_basic_auth("user", "password");
      +
      +httplib::Client cli("https://example.com");
      +cli.set_proxy("proxy.example.com", 8080);
      +cli.set_proxy_basic_auth("user", "password");
       
       httplib::Client cli("https://example.com");
      @@ -285,11 +287,11 @@
       

      Timeouts

      You can set connection, read, and write timeouts individually.

      -
      -httplib::Client cli("https://example.com");
      -cli.set_connection_timeout(5, 0);  // 5 seconds
      -cli.set_read_timeout(10, 0);       // 10 seconds
      -cli.set_write_timeout(10, 0);      // 10 seconds
      +
      +httplib::Client cli("https://example.com");
      +cli.set_connection_timeout(5, 0);  // 5 seconds
      +cli.set_read_timeout(10, 0);       // 10 seconds
      +cli.set_write_timeout(10, 0);      // 10 seconds
       
       httplib::Client cli("https://example.com");
      @@ -300,9 +302,9 @@
       

      Keep-Alive

      If you're making multiple requests to the same server, enable Keep-Alive. It reuses the TCP connection, which is much more efficient.

      -
      -httplib::Client cli("https://example.com");
      -cli.set_keep_alive(true);
      +
      +httplib::Client cli("https://example.com");
      +cli.set_keep_alive(true);
       
       httplib::Client cli("https://example.com");
      @@ -311,16 +313,16 @@
       

      Server Middleware

      You can hook into request processing before and after handlers run.

      -
      -svr.set_pre_routing_handler([](const auto &req, auto &res) {
      -    // Runs before every request
      -    return httplib::Server::HandlerResponse::Unhandled;  // Continue to normal routing
      -});
      -
      -svr.set_post_routing_handler([](const auto &req, auto &res) {
      -    // Runs after the response is sent
      -    res.set_header("X-Server", "cpp-httplib");
      -});
      +
      +svr.set_pre_routing_handler([](const auto &req, auto &res) {
      +    // Runs before every request
      +    return httplib::Server::HandlerResponse::Unhandled;  // Continue to normal routing
      +});
      +
      +svr.set_post_routing_handler([](const auto &req, auto &res) {
      +    // Runs after the response is sent
      +    res.set_header("X-Server", "cpp-httplib");
      +});
       
       svr.set_pre_routing_handler([](const auto &req, auto &res) {
      @@ -335,16 +337,16 @@
       

      Use req.user_data to pass data from middleware to handlers. This is useful for sharing things like decoded auth tokens.

      -
      -svr.set_pre_routing_handler([](const auto &req, auto &res) {
      -    req.user_data["auth_user"] = std::string("alice");
      -    return httplib::Server::HandlerResponse::Unhandled;
      -});
      -
      -svr.Get("/me", [](const auto &req, auto &res) {
      -    auto user = std::any_cast<std::string>(req.user_data.at("auth_user"));
      -    res.set_content("Hello, " + user, "text/plain");
      -});
      +
      +svr.set_pre_routing_handler([](const auto &req, auto &res) {
      +    req.user_data["auth_user"] = std::string("alice");
      +    return httplib::Server::HandlerResponse::Unhandled;
      +});
      +
      +svr.Get("/me", [](const auto &req, auto &res) {
      +    auto user = std::any_cast<std::string>(req.user_data.at("auth_user"));
      +    res.set_content("Hello, " + user, "text/plain");
      +});
       
       svr.set_pre_routing_handler([](const auto &req, auto &res) {
      @@ -359,15 +361,15 @@
       

      You can also customize error and exception handlers.

      -
      -svr.set_error_handler([](const auto &req, auto &res) {
      -    res.set_content("Custom Error Page", "text/html");
      -});
      -
      -svr.set_exception_handler([](const auto &req, auto &res, std::exception_ptr ep) {
      -    res.status = 500;
      -    res.set_content("Internal Server Error", "text/plain");
      -});
      +
      +svr.set_error_handler([](const auto &req, auto &res) {
      +    res.set_content("Custom Error Page", "text/html");
      +});
      +
      +svr.set_exception_handler([](const auto &req, auto &res, std::exception_ptr ep) {
      +    res.status = 500;
      +    res.set_content("Internal Server Error", "text/plain");
      +});
       
       svr.set_error_handler([](const auto &req, auto &res) {
      @@ -382,10 +384,10 @@
       

      Logging

      You can set a logger on both the server and the client.

      -
      -svr.set_logger([](const auto &req, const auto &res) {
      -    std::cout << req.method << " " << req.path << " " << res.status << std::endl;
      -});
      +
      +svr.set_logger([](const auto &req, const auto &res) {
      +    std::cout << req.method << " " << req.path << " " << res.status << std::endl;
      +});
       
       svr.set_logger([](const auto &req, const auto &res) {
      @@ -395,11 +397,11 @@
       

      Unix Domain Socket

      In addition to TCP, we support Unix Domain Sockets. You can use them for inter-process communication on the same machine.

      -
      -// Server
      -httplib::Server svr;
      -svr.set_address_family(AF_UNIX);
      -svr.listen("/tmp/httplib.sock", 0);
      +
      +// Server
      +httplib::Server svr;
      +svr.set_address_family(AF_UNIX);
      +svr.listen("/tmp/httplib.sock", 0);
       
       // Server
      @@ -407,13 +409,13 @@
       svr.set_address_family(AF_UNIX);
       svr.listen("/tmp/httplib.sock", 0);
       
      -
      -// Client
      -httplib::Client cli("http://localhost");
      -cli.set_address_family(AF_UNIX);
      -cli.set_hostname_addr_map({{"localhost", "/tmp/httplib.sock"}});
      -
      -auto res = cli.Get("/");
      +
      +// Client
      +httplib::Client cli("http://localhost");
      +cli.set_address_family(AF_UNIX);
      +cli.set_hostname_addr_map({{"localhost", "/tmp/httplib.sock"}});
      +
      +auto res = cli.Get("/");
       
       // Client
      @@ -440,7 +442,7 @@
         
      - © 2026 yhirose. All rights reserved. + © 2026 Yuji Hirose. All rights reserved.
      diff --git a/docs/en/tour/index.html b/docs/en/tour/index.html index 4c22481..46940e7 100644 --- a/docs/en/tour/index.html +++ b/docs/en/tour/index.html @@ -17,16 +17,16 @@
      - cpp-httplib v0.36.0 + cpp-httplib v0.36.0
      @@ -121,7 +123,7 @@
      - © 2026 yhirose. All rights reserved. + © 2026 Yuji Hirose. All rights reserved.
      diff --git a/docs/ja/cookbook/index.html b/docs/ja/cookbook/index.html index b53cf63..4171a36 100644 --- a/docs/ja/cookbook/index.html +++ b/docs/ja/cookbook/index.html @@ -17,16 +17,16 @@
      - cpp-httplib v0.36.0 + cpp-httplib v0.36.0
      @@ -89,7 +91,7 @@
      - © 2026 yhirose. All rights reserved. + © 2026 Yuji Hirose. All rights reserved.
      diff --git a/docs/ja/index.html b/docs/ja/index.html index cd49770..2fb9b12 100644 --- a/docs/ja/index.html +++ b/docs/ja/index.html @@ -17,16 +17,16 @@
      - cpp-httplib v0.36.0 + cpp-httplib v0.36.0
      @@ -88,7 +90,7 @@
      - © 2026 yhirose. All rights reserved. + © 2026 Yuji Hirose. All rights reserved.
      diff --git a/docs/ja/tour/01-getting-started/index.html b/docs/ja/tour/01-getting-started/index.html index 7310a5a..1f05ac0 100644 --- a/docs/ja/tour/01-getting-started/index.html +++ b/docs/ja/tour/01-getting-started/index.html @@ -17,16 +17,16 @@
      - cpp-httplib v0.36.0 + cpp-httplib v0.36.0
      @@ -105,8 +107,8 @@

      cpp-httplibを始めるのに必要なのは、httplib.hとC++コンパイラーだけです。ファイルをダウンロードして、Hello Worldサーバーを動かすところまでやってみましょう。

      httplib.h の入手

      GitHubから直接ダウンロードできます。常に最新版を使ってください。

      -
      -curl -LO https://github.com/yhirose/cpp-httplib/raw/refs/tags/latest/httplib.h
      +
      +curl -LO https://github.com/yhirose/cpp-httplib/raw/refs/tags/latest/httplib.h
       
       curl -LO https://github.com/yhirose/cpp-httplib/raw/refs/tags/latest/httplib.h
      @@ -121,18 +123,18 @@
       
       

      Hello World サーバー

      次のコードを server.cpp として保存しましょう。

      -
      -#include "httplib.h"
      -
      -int main() {
      -    httplib::Server svr;
      -
      -    svr.Get("/", [](const httplib::Request&, httplib::Response& res) {
      -        res.set_content("Hello, World!", "text/plain");
      -    });
      -
      -    svr.listen("0.0.0.0", 8080);
      -}
      +
      +#include "httplib.h"
      +
      +int main() {
      +    httplib::Server svr;
      +
      +    svr.Get("/", [](const httplib::Request&, httplib::Response& res) {
      +        res.set_content("Hello, World!", "text/plain");
      +    });
      +
      +    svr.listen("0.0.0.0", 8080);
      +}
       
       #include "httplib.h"
      @@ -151,17 +153,17 @@
       

      たった数行で、HTTPリクエストに応答するサーバーが書けます。

      コンパイルと実行

      このチュートリアルのサンプルコードは、コードを簡潔に書けるC++17で書いています。cpp-httplib自体はC++11でもコンパイルできます。

      -
      -# macOS
      -clang++ -std=c++17 -o server server.cpp
      -
      -# Linux
      -# `-pthread`: cpp-httplibは内部でスレッドを使用
      -clang++ -std=c++17 -pthread -o server server.cpp
      -
      -# Windows (Developer Command Prompt)
      -# `/EHsc`: C++例外処理を有効化
      -cl /EHsc /std:c++17 server.cpp
      +
      +# macOS
      +clang++ -std=c++17 -o server server.cpp
      +
      +# Linux
      +# `-pthread`: cpp-httplibは内部でスレッドを使用
      +clang++ -std=c++17 -pthread -o server server.cpp
      +
      +# Windows (Developer Command Prompt)
      +# `/EHsc`: C++例外処理を有効化
      +cl /EHsc /std:c++17 server.cpp
       
       # macOS
      @@ -177,12 +179,12 @@
       

      コンパイルできたら実行します。

      -
      -# macOS / Linux
      -./server
      -
      -# Windows
      -server.exe
      +
      +# macOS / Linux
      +./server
      +
      +# Windows
      +server.exe
       
       # macOS / Linux
      @@ -194,9 +196,9 @@
       

      ブラウザで http://localhost:8080 を開いてください。"Hello, World!" と表示されれば成功です。

      curl でも確認できます。

      -
      -curl http://localhost:8080/
      -# Hello, World!
      +
      +curl http://localhost:8080/
      +# Hello, World!
       
       curl http://localhost:8080/
      @@ -214,7 +216,7 @@
         
      - © 2026 yhirose. All rights reserved. + © 2026 Yuji Hirose. All rights reserved.
      diff --git a/docs/ja/tour/02-basic-client/index.html b/docs/ja/tour/02-basic-client/index.html index a6f579e..08f94de 100644 --- a/docs/ja/tour/02-basic-client/index.html +++ b/docs/ja/tour/02-basic-client/index.html @@ -17,16 +17,16 @@
      - cpp-httplib v0.36.0 + cpp-httplib v0.36.0
      @@ -105,53 +107,53 @@

      cpp-httplibはサーバーだけでなく、HTTPクライアント機能も備えています。httplib::Client を使って、GETやPOSTリクエストを送ってみましょう。

      テスト用サーバーの準備

      クライアントの動作を確認するために、リクエストを受け付けるサーバーを用意します。次のコードを保存し、前章と同じ手順でコンパイル・実行してください。サーバーの詳しい解説は次章で行います。

      -
      -#include "httplib.h"
      -#include <iostream>
      -
      -int main() {
      -    httplib::Server svr;
      -
      -    svr.Get("/hi", [](const auto &, auto &res) {
      -        res.set_content("Hello!", "text/plain");
      -    });
      -
      -    svr.Get("/search", [](const auto &req, auto &res) {
      -        auto q = req.get_param_value("q");
      -        res.set_content("Query: " + q, "text/plain");
      -    });
      -
      -    svr.Post("/post", [](const auto &req, auto &res) {
      -        res.set_content(req.body, "text/plain");
      -    });
      -
      -    svr.Post("/submit", [](const auto &req, auto &res) {
      -        std::string result;
      -        for (auto &[key, val] : req.params) {
      -            result += key + " = " + val + "\n";
      -        }
      -        res.set_content(result, "text/plain");
      -    });
      -
      -    svr.Post("/upload", [](const auto &req, auto &res) {
      -        auto f = req.form.get_file("file");
      -        auto content = f.filename + " (" + std::to_string(f.content.size()) + " bytes)";
      -        res.set_content(content, "text/plain");
      -    });
      -
      -    svr.Get("/users/:id", [](const auto &req, auto &res) {
      -        auto id = req.path_params.at("id");
      -        res.set_content("User ID: " + id, "text/plain");
      -    });
      -
      -    svr.Get(R"(/files/(\d+))", [](const auto &req, auto &res) {
      -        auto id = req.matches[1];
      -        res.set_content("File ID: " + std::string(id), "text/plain");
      -    });
      -
      -    std::cout << "Listening on port 8080..." << std::endl;
      -    svr.listen("0.0.0.0", 8080);
      -}
      +
      +#include "httplib.h"
      +#include <iostream>
      +
      +int main() {
      +    httplib::Server svr;
      +
      +    svr.Get("/hi", [](const auto &, auto &res) {
      +        res.set_content("Hello!", "text/plain");
      +    });
      +
      +    svr.Get("/search", [](const auto &req, auto &res) {
      +        auto q = req.get_param_value("q");
      +        res.set_content("Query: " + q, "text/plain");
      +    });
      +
      +    svr.Post("/post", [](const auto &req, auto &res) {
      +        res.set_content(req.body, "text/plain");
      +    });
      +
      +    svr.Post("/submit", [](const auto &req, auto &res) {
      +        std::string result;
      +        for (auto &[key, val] : req.params) {
      +            result += key + " = " + val + "\n";
      +        }
      +        res.set_content(result, "text/plain");
      +    });
      +
      +    svr.Post("/upload", [](const auto &req, auto &res) {
      +        auto f = req.form.get_file("file");
      +        auto content = f.filename + " (" + std::to_string(f.content.size()) + " bytes)";
      +        res.set_content(content, "text/plain");
      +    });
      +
      +    svr.Get("/users/:id", [](const auto &req, auto &res) {
      +        auto id = req.path_params.at("id");
      +        res.set_content("User ID: " + id, "text/plain");
      +    });
      +
      +    svr.Get(R"(/files/(\d+))", [](const auto &req, auto &res) {
      +        auto id = req.matches[1];
      +        res.set_content("File ID: " + std::string(id), "text/plain");
      +    });
      +
      +    std::cout << "Listening on port 8080..." << std::endl;
      +    svr.listen("0.0.0.0", 8080);
      +}
       
       #include "httplib.h"
      @@ -204,19 +206,19 @@
       

      GETリクエスト

      サーバーが起動したら、別のターミナルを開いて試してみましょう。まず、最もシンプルなGETリクエストです。

      -
      -#include "httplib.h"
      -#include <iostream>
      -
      -int main() {
      -    httplib::Client cli("http://localhost:8080");
      -
      -    auto res = cli.Get("/hi");
      -    if (res) {
      -        std::cout << res->status << std::endl;  // 200
      -        std::cout << res->body << std::endl;    // Hello!
      -    }
      -}
      +
      +#include "httplib.h"
      +#include <iostream>
      +
      +int main() {
      +    httplib::Client cli("http://localhost:8080");
      +
      +    auto res = cli.Get("/hi");
      +    if (res) {
      +        std::cout << res->status << std::endl;  // 200
      +        std::cout << res->body << std::endl;    // Hello!
      +    }
      +}
       
       #include "httplib.h"
      @@ -235,9 +237,9 @@
       

      httplib::Client のコンストラクターにサーバーのアドレスを渡し、Get() でリクエストを送ります。戻り値の res からステータスコードやボディを取得できます。

      対応する curl コマンドはこうなります。

      -
      -curl http://localhost:8080/hi
      -# Hello!
      +
      +curl http://localhost:8080/hi
      +# Hello!
       
       curl http://localhost:8080/hi
      @@ -246,18 +248,18 @@
       

      レスポンスの確認

      レスポンスには、ステータスコードとボディ以外にもヘッダー情報が含まれています。

      -
      -auto res = cli.Get("/hi");
      -if (res) {
      -    // ステータスコード
      -    std::cout << res->status << std::endl;  // 200
      -
      -    // ボディ
      -    std::cout << res->body << std::endl;  // Hello!
      -
      -    // ヘッダー
      -    std::cout << res->get_header_value("Content-Type") << std::endl;  // text/plain
      -}
      +
      +auto res = cli.Get("/hi");
      +if (res) {
      +    // ステータスコード
      +    std::cout << res->status << std::endl;  // 200
      +
      +    // ボディ
      +    std::cout << res->body << std::endl;  // Hello!
      +
      +    // ヘッダー
      +    std::cout << res->get_header_value("Content-Type") << std::endl;  // text/plain
      +}
       
       auto res = cli.Get("/hi");
      @@ -276,11 +278,11 @@
       

      res->bodystd::string なので、JSON レスポンスをパースしたい場合は nlohmann/json などの JSON ライブラリにそのまま渡せます。

      クエリパラメーター

      GETリクエストにクエリパラメーターを付けるには、URLに直接書くか、httplib::Params を使います。

      -
      -auto res = cli.Get("/search", httplib::Params{{"q", "cpp-httplib"}});
      -if (res) {
      -    std::cout << res->body << std::endl;  // Query: cpp-httplib
      -}
      +
      +auto res = cli.Get("/search", httplib::Params{{"q", "cpp-httplib"}});
      +if (res) {
      +    std::cout << res->body << std::endl;  // Query: cpp-httplib
      +}
       
       auto res = cli.Get("/search", httplib::Params{{"q", "cpp-httplib"}});
      @@ -290,9 +292,9 @@
       

      httplib::Params を使うと、特殊文字のURLエンコードを自動で行ってくれます。

      -
      -curl "http://localhost:8080/search?q=cpp-httplib"
      -# Query: cpp-httplib
      +
      +curl "http://localhost:8080/search?q=cpp-httplib"
      +# Query: cpp-httplib
       
       curl "http://localhost:8080/search?q=cpp-httplib"
      @@ -301,11 +303,11 @@
       

      パスパラメーター

      URLのパスに値を直接埋め込む場合も、クライアント側は特別なAPIは不要です。パスをそのまま Get() に渡すだけです。

      -
      -auto res = cli.Get("/users/42");
      -if (res) {
      -    std::cout << res->body << std::endl;  // User ID: 42
      -}
      +
      +auto res = cli.Get("/users/42");
      +if (res) {
      +    std::cout << res->body << std::endl;  // User ID: 42
      +}
       
       auto res = cli.Get("/users/42");
      @@ -313,9 +315,9 @@
           std::cout << res->body << std::endl;  // User ID: 42
       }
       
      -
      -curl http://localhost:8080/users/42
      -# User ID: 42
      +
      +curl http://localhost:8080/users/42
      +# User ID: 42
       
       curl http://localhost:8080/users/42
      @@ -323,11 +325,11 @@
       

      テスト用サーバーには、正規表現でIDを数字のみに絞った /files/(\d+) もあります。

      -
      -auto res = cli.Get("/files/42");
      -if (res) {
      -    std::cout << res->body << std::endl;  // File ID: 42
      -}
      +
      +auto res = cli.Get("/files/42");
      +if (res) {
      +    std::cout << res->body << std::endl;  // File ID: 42
      +}
       
       auto res = cli.Get("/files/42");
      @@ -335,9 +337,9 @@
           std::cout << res->body << std::endl;  // File ID: 42
       }
       
      -
      -curl http://localhost:8080/files/42
      -# File ID: 42
      +
      +curl http://localhost:8080/files/42
      +# File ID: 42
       
       curl http://localhost:8080/files/42
      @@ -347,18 +349,18 @@
       

      /files/abc のように数字以外を渡すと404が返ります。仕組みは次章で解説します。

      リクエストヘッダー

      カスタムHTTPヘッダーを付けるには、httplib::Headers を渡します。Get()Post() のどちらでも使えます。

      -
      -auto res = cli.Get("/hi", httplib::Headers{
      -    {"Authorization", "Bearer my-token"}
      -});
      +
      +auto res = cli.Get("/hi", httplib::Headers{
      +    {"Authorization", "Bearer my-token"}
      +});
       
       auto res = cli.Get("/hi", httplib::Headers{
           {"Authorization", "Bearer my-token"}
       });
       
      -
      -curl -H "Authorization: Bearer my-token" http://localhost:8080/hi
      +
      +curl -H "Authorization: Bearer my-token" http://localhost:8080/hi
       
       curl -H "Authorization: Bearer my-token" http://localhost:8080/hi
      @@ -366,12 +368,12 @@
       

      POSTリクエスト

      テキストデータをPOSTしてみましょう。Post() の第2引数にボディ、第3引数にContent-Typeを指定します。

      -
      -auto res = cli.Post("/post", "Hello, Server!", "text/plain");
      -if (res) {
      -    std::cout << res->status << std::endl;  // 200
      -    std::cout << res->body << std::endl;    // Hello, Server!
      -}
      +
      +auto res = cli.Post("/post", "Hello, Server!", "text/plain");
      +if (res) {
      +    std::cout << res->status << std::endl;  // 200
      +    std::cout << res->body << std::endl;    // Hello, Server!
      +}
       
       auto res = cli.Post("/post", "Hello, Server!", "text/plain");
      @@ -382,9 +384,9 @@
       

      テスト用サーバーの /post はボディをそのまま返すので、送った文字列がそのまま返ってきます。

      -
      -curl -X POST -H "Content-Type: text/plain" -d "Hello, Server!" http://localhost:8080/post
      -# Hello, Server!
      +
      +curl -X POST -H "Content-Type: text/plain" -d "Hello, Server!" http://localhost:8080/post
      +# Hello, Server!
       
       curl -X POST -H "Content-Type: text/plain" -d "Hello, Server!" http://localhost:8080/post
      @@ -393,16 +395,16 @@
       

      フォームデータの送信

      HTMLフォームのように、キーと値のペアを送ることもできます。httplib::Params を使います。

      -
      -auto res = cli.Post("/submit", httplib::Params{
      -    {"name", "Alice"},
      -    {"age", "30"}
      -});
      -if (res) {
      -    std::cout << res->body << std::endl;
      -    // age = 30
      -    // name = Alice
      -}
      +
      +auto res = cli.Post("/submit", httplib::Params{
      +    {"name", "Alice"},
      +    {"age", "30"}
      +});
      +if (res) {
      +    std::cout << res->body << std::endl;
      +    // age = 30
      +    // name = Alice
      +}
       
       auto res = cli.Post("/submit", httplib::Params{
      @@ -417,8 +419,8 @@
       

      これは application/x-www-form-urlencoded 形式で送信されます。

      -
      -curl -X POST -d "name=Alice&age=30" http://localhost:8080/submit
      +
      +curl -X POST -d "name=Alice&age=30" http://localhost:8080/submit
       
       curl -X POST -d "name=Alice&age=30" http://localhost:8080/submit
      @@ -426,13 +428,13 @@
       

      ファイルのPOST

      ファイルをアップロードするには、httplib::UploadFormDataItems を使ってマルチパートフォームデータとして送信します。

      -
      -auto res = cli.Post("/upload", httplib::UploadFormDataItems{
      -    {"file", "Hello, File!", "hello.txt", "text/plain"}
      -});
      -if (res) {
      -    std::cout << res->body << std::endl;  // hello.txt (12 bytes)
      -}
      +
      +auto res = cli.Post("/upload", httplib::UploadFormDataItems{
      +    {"file", "Hello, File!", "hello.txt", "text/plain"}
      +});
      +if (res) {
      +    std::cout << res->body << std::endl;  // hello.txt (12 bytes)
      +}
       
       auto res = cli.Post("/upload", httplib::UploadFormDataItems{
      @@ -444,8 +446,8 @@
       

      UploadFormDataItems の各要素は {name, content, filename, content_type} の4つのフィールドで構成されます。

      -
      -curl -F "file=Hello, File!;filename=hello.txt;type=text/plain" http://localhost:8080/upload
      +
      +curl -F "file=Hello, File!;filename=hello.txt;type=text/plain" http://localhost:8080/upload
       
       curl -F "file=Hello, File!;filename=hello.txt;type=text/plain" http://localhost:8080/upload
      @@ -453,24 +455,24 @@
       

      エラーハンドリング

      ネットワーク通信では、サーバーに接続できない場合があります。res が有効かどうかを必ず確認しましょう。

      -
      -httplib::Client cli("http://localhost:9999");  // 存在しないポート
      -auto res = cli.Get("/hi");
      -
      -if (!res) {
      -    // 接続エラー
      -    std::cout << "Error: " << httplib::to_string(res.error()) << std::endl;
      -    // Error: Connection
      -    return 1;
      -}
      -
      -// ここに到達すればレスポンスを受信できている
      -if (res->status != 200) {
      -    std::cout << "HTTP Error: " << res->status << std::endl;
      -    return 1;
      -}
      -
      -std::cout << res->body << std::endl;
      +
      +httplib::Client cli("http://localhost:9999");  // 存在しないポート
      +auto res = cli.Get("/hi");
      +
      +if (!res) {
      +    // 接続エラー
      +    std::cout << "Error: " << httplib::to_string(res.error()) << std::endl;
      +    // Error: Connection
      +    return 1;
      +}
      +
      +// ここに到達すればレスポンスを受信できている
      +if (res->status != 200) {
      +    std::cout << "HTTP Error: " << res->status << std::endl;
      +    return 1;
      +}
      +
      +std::cout << res->body << std::endl;
       
       httplib::Client cli("http://localhost:9999");  // 存在しないポート
      @@ -507,7 +509,7 @@
         
      - © 2026 yhirose. All rights reserved. + © 2026 Yuji Hirose. All rights reserved.
      diff --git a/docs/ja/tour/03-basic-server/index.html b/docs/ja/tour/03-basic-server/index.html index 1695033..6502aee 100644 --- a/docs/ja/tour/03-basic-server/index.html +++ b/docs/ja/tour/03-basic-server/index.html @@ -17,16 +17,16 @@
      - cpp-httplib v0.36.0 + cpp-httplib v0.36.0
      @@ -105,8 +107,8 @@

      前章ではクライアントからリクエストを送りました。そのとき、テスト用サーバーを用意しましたね。この章では、あのサーバーの仕組みをひとつずつ紐解いていきます。

      サーバーの起動

      ルーティングを登録したら、最後に svr.listen() を呼んでサーバーを起動します。

      -
      -svr.listen("0.0.0.0", 8080);
      +
      +svr.listen("0.0.0.0", 8080);
       
       svr.listen("0.0.0.0", 8080);
      @@ -116,12 +118,12 @@
       

      listen() はブロッキング呼び出しです。サーバーが停止するまで、この行から先には進みません。ターミナルで Ctrl+C を押すか、別スレッドから svr.stop() を呼ぶまでサーバーは動き続けます。

      ルーティング

      サーバーの核になるのは「ルーティング」です。どのURLに、どのHTTPメソッドでアクセスされたら、何をするか。それを登録する仕組みです。

      -
      -httplib::Server svr;
      -
      -svr.Get("/hi", [](const httplib::Request &req, httplib::Response &res) {
      -    res.set_content("Hello!", "text/plain");
      -});
      +
      +httplib::Server svr;
      +
      +svr.Get("/hi", [](const httplib::Request &req, httplib::Response &res) {
      +    res.set_content("Hello!", "text/plain");
      +});
       
       httplib::Server svr;
      @@ -133,11 +135,11 @@
       

      svr.Get() は、GETリクエストに対するハンドラーを登録します。第1引数がパス、第2引数がハンドラー関数です。/hi にGETリクエストが来たら、このラムダが呼ばれます。

      HTTPメソッドごとにメソッドが用意されています。

      -
      -svr.Get("/path",    handler);  // GET
      -svr.Post("/path",   handler);  // POST
      -svr.Put("/path",    handler);  // PUT
      -svr.Delete("/path", handler);  // DELETE
      +
      +svr.Get("/path",    handler);  // GET
      +svr.Post("/path",   handler);  // POST
      +svr.Put("/path",    handler);  // PUT
      +svr.Delete("/path", handler);  // DELETE
       
       svr.Get("/path",    handler);  // GET
      @@ -147,10 +149,10 @@
       

      ハンドラーのシグネチャは (const httplib::Request &req, httplib::Response &res) です。auto を使って短く書くこともできます。

      -
      -svr.Get("/hi", [](const auto &req, auto &res) {
      -    res.set_content("Hello!", "text/plain");
      -});
      +
      +svr.Get("/hi", [](const auto &req, auto &res) {
      +    res.set_content("Hello!", "text/plain");
      +});
       
       svr.Get("/hi", [](const auto &req, auto &res) {
      @@ -163,11 +165,11 @@
       

      ハンドラーの第1引数 req から、クライアントが送ってきた情報を読み取れます。

      ボディ

      req.body でリクエストボディを取得できます。型は std::string です。

      -
      -svr.Post("/post", [](const auto &req, auto &res) {
      -    // クライアントが送ったボディをそのまま返す
      -    res.set_content(req.body, "text/plain");
      -});
      +
      +svr.Post("/post", [](const auto &req, auto &res) {
      +    // クライアントが送ったボディをそのまま返す
      +    res.set_content(req.body, "text/plain");
      +});
       
       svr.Post("/post", [](const auto &req, auto &res) {
      @@ -178,11 +180,11 @@
       

      ヘッダー

      req.get_header_value() でリクエストヘッダーの値を取得できます。

      -
      -svr.Get("/check", [](const auto &req, auto &res) {
      -    auto auth = req.get_header_value("Authorization");
      -    res.set_content("Auth: " + auth, "text/plain");
      -});
      +
      +svr.Get("/check", [](const auto &req, auto &res) {
      +    auto auth = req.get_header_value("Authorization");
      +    res.set_content("Auth: " + auth, "text/plain");
      +});
       
       svr.Get("/check", [](const auto &req, auto &res) {
      @@ -193,11 +195,11 @@
       

      クエリパラメーターとフォームデータ

      req.get_param_value() でパラメーターを取得できます。GETのクエリパラメーターと、POSTのフォームデータの両方に使えます。

      -
      -svr.Get("/search", [](const auto &req, auto &res) {
      -    auto q = req.get_param_value("q");
      -    res.set_content("Query: " + q, "text/plain");
      -});
      +
      +svr.Get("/search", [](const auto &req, auto &res) {
      +    auto q = req.get_param_value("q");
      +    res.set_content("Query: " + q, "text/plain");
      +});
       
       svr.Get("/search", [](const auto &req, auto &res) {
      @@ -208,14 +210,14 @@
       

      /search?q=cpp-httplib にアクセスすると、q の値は "cpp-httplib" になります。

      すべてのパラメーターをループで処理したいときは、req.params を使います。

      -
      -svr.Post("/submit", [](const auto &req, auto &res) {
      -    std::string result;
      -    for (auto &[key, val] : req.params) {
      -        result += key + " = " + val + "\n";
      -    }
      -    res.set_content(result, "text/plain");
      -});
      +
      +svr.Post("/submit", [](const auto &req, auto &res) {
      +    std::string result;
      +    for (auto &[key, val] : req.params) {
      +        result += key + " = " + val + "\n";
      +    }
      +    res.set_content(result, "text/plain");
      +});
       
       svr.Post("/submit", [](const auto &req, auto &res) {
      @@ -229,12 +231,12 @@
       

      ファイルアップロード

      マルチパートフォームでアップロードされたファイルは、req.form.get_file() で取得します。

      -
      -svr.Post("/upload", [](const auto &req, auto &res) {
      -    auto f = req.form.get_file("file");
      -    auto content = f.filename + " (" + std::to_string(f.content.size()) + " bytes)";
      -    res.set_content(content, "text/plain");
      -});
      +
      +svr.Post("/upload", [](const auto &req, auto &res) {
      +    auto f = req.form.get_file("file");
      +    auto content = f.filename + " (" + std::to_string(f.content.size()) + " bytes)";
      +    res.set_content(content, "text/plain");
      +});
       
       svr.Post("/upload", [](const auto &req, auto &res) {
      @@ -247,11 +249,11 @@
       

      f.filename でファイル名、f.content でファイルの中身にアクセスできます。

      パスパラメーター

      URLの一部を変数として受け取りたいことがあります。たとえば /users/4242 を取得したい場合です。:param 記法を使うと、URLの一部をキャプチャできます。

      -
      -svr.Get("/users/:id", [](const auto &req, auto &res) {
      -    auto id = req.path_params.at("id");
      -    res.set_content("User ID: " + id, "text/plain");
      -});
      +
      +svr.Get("/users/:id", [](const auto &req, auto &res) {
      +    auto id = req.path_params.at("id");
      +    res.set_content("User ID: " + id, "text/plain");
      +});
       
       svr.Get("/users/:id", [](const auto &req, auto &res) {
      @@ -262,12 +264,12 @@
       

      /users/42 にアクセスすると、req.path_params.at("id")"42" を返します。/users/100 なら "100" です。

      複数のパスパラメーターも使えます。

      -
      -svr.Get("/users/:user_id/posts/:post_id", [](const auto &req, auto &res) {
      -    auto user_id = req.path_params.at("user_id");
      -    auto post_id = req.path_params.at("post_id");
      -    res.set_content("User: " + user_id + ", Post: " + post_id, "text/plain");
      -});
      +
      +svr.Get("/users/:user_id/posts/:post_id", [](const auto &req, auto &res) {
      +    auto user_id = req.path_params.at("user_id");
      +    auto post_id = req.path_params.at("post_id");
      +    res.set_content("User: " + user_id + ", Post: " + post_id, "text/plain");
      +});
       
       svr.Get("/users/:user_id/posts/:post_id", [](const auto &req, auto &res) {
      @@ -279,12 +281,12 @@
       

      正規表現パターン

      :param の代わりに正規表現をパスに書くこともできます。キャプチャグループの値は req.matches で取得します。型は std::smatch です。

      -
      -// 数字のみのIDを受け付ける
      -svr.Get(R"(/files/(\d+))", [](const auto &req, auto &res) {
      -    auto id = req.matches[1];  // 最初のキャプチャグループ
      -    res.set_content("File ID: " + std::string(id), "text/plain");
      -});
      +
      +// 数字のみのIDを受け付ける
      +svr.Get(R"(/files/(\d+))", [](const auto &req, auto &res) {
      +    auto id = req.matches[1];  // 最初のキャプチャグループ
      +    res.set_content("File ID: " + std::string(id), "text/plain");
      +});
       
       // 数字のみのIDを受け付ける
      @@ -299,10 +301,10 @@
       

      ハンドラーの第2引数 res を使って、クライアントに返すレスポンスを組み立てます。

      ボディとContent-Type

      res.set_content() でボディとContent-Typeを設定します。これだけでステータスコード200のレスポンスが返ります。

      -
      -svr.Get("/hi", [](const auto &req, auto &res) {
      -    res.set_content("Hello!", "text/plain");
      -});
      +
      +svr.Get("/hi", [](const auto &req, auto &res) {
      +    res.set_content("Hello!", "text/plain");
      +});
       
       svr.Get("/hi", [](const auto &req, auto &res) {
      @@ -312,11 +314,11 @@
       

      ステータスコード

      ステータスコードを変えたいときは、res.status に代入します。

      -
      -svr.Get("/not-found", [](const auto &req, auto &res) {
      -    res.status = 404;
      -    res.set_content("Not found", "text/plain");
      -});
      +
      +svr.Get("/not-found", [](const auto &req, auto &res) {
      +    res.status = 404;
      +    res.set_content("Not found", "text/plain");
      +});
       
       svr.Get("/not-found", [](const auto &req, auto &res) {
      @@ -327,11 +329,11 @@
       

      レスポンスヘッダー

      res.set_header() でレスポンスヘッダーを追加できます。

      -
      -svr.Get("/with-header", [](const auto &req, auto &res) {
      -    res.set_header("X-Custom", "my-value");
      -    res.set_content("Hello!", "text/plain");
      -});
      +
      +svr.Get("/with-header", [](const auto &req, auto &res) {
      +    res.set_header("X-Custom", "my-value");
      +    res.set_content("Hello!", "text/plain");
      +});
       
       svr.Get("/with-header", [](const auto &req, auto &res) {
      @@ -343,10 +345,10 @@
       

      前章のサーバーを読み解く

      ここまでの知識を使って、前章で用意したテスト用サーバーを改めて見てみましょう。

      GET /hi

      -
      -svr.Get("/hi", [](const auto &, auto &res) {
      -    res.set_content("Hello!", "text/plain");
      -});
      +
      +svr.Get("/hi", [](const auto &, auto &res) {
      +    res.set_content("Hello!", "text/plain");
      +});
       
       svr.Get("/hi", [](const auto &, auto &res) {
      @@ -356,11 +358,11 @@
       

      最もシンプルなハンドラーです。リクエストの情報は使わないので、req の変数名を省略しています。"Hello!" というテキストをそのまま返します。

      GET /search

      -
      -svr.Get("/search", [](const auto &req, auto &res) {
      -    auto q = req.get_param_value("q");
      -    res.set_content("Query: " + q, "text/plain");
      -});
      +
      +svr.Get("/search", [](const auto &req, auto &res) {
      +    auto q = req.get_param_value("q");
      +    res.set_content("Query: " + q, "text/plain");
      +});
       
       svr.Get("/search", [](const auto &req, auto &res) {
      @@ -371,10 +373,10 @@
       

      req.get_param_value("q") でクエリパラメーター q の値を取り出します。/search?q=cpp-httplib なら、レスポンスは "Query: cpp-httplib" になります。

      POST /post

      -
      -svr.Post("/post", [](const auto &req, auto &res) {
      -    res.set_content(req.body, "text/plain");
      -});
      +
      +svr.Post("/post", [](const auto &req, auto &res) {
      +    res.set_content(req.body, "text/plain");
      +});
       
       svr.Post("/post", [](const auto &req, auto &res) {
      @@ -384,14 +386,14 @@
       

      クライアントが送ったリクエストボディを、そのままレスポンスとして返すエコーサーバーです。req.body にボディが丸ごと入っています。

      POST /submit

      -
      -svr.Post("/submit", [](const auto &req, auto &res) {
      -    std::string result;
      -    for (auto &[key, val] : req.params) {
      -        result += key + " = " + val + "\n";
      -    }
      -    res.set_content(result, "text/plain");
      -});
      +
      +svr.Post("/submit", [](const auto &req, auto &res) {
      +    std::string result;
      +    for (auto &[key, val] : req.params) {
      +        result += key + " = " + val + "\n";
      +    }
      +    res.set_content(result, "text/plain");
      +});
       
       svr.Post("/submit", [](const auto &req, auto &res) {
      @@ -405,12 +407,12 @@
       

      フォームデータとして送られたキーと値のペアを、req.params でループ処理しています。構造化束縛 auto &[key, val] を使って、各ペアを取り出しています。

      POST /upload

      -
      -svr.Post("/upload", [](const auto &req, auto &res) {
      -    auto f = req.form.get_file("file");
      -    auto content = f.filename + " (" + std::to_string(f.content.size()) + " bytes)";
      -    res.set_content(content, "text/plain");
      -});
      +
      +svr.Post("/upload", [](const auto &req, auto &res) {
      +    auto f = req.form.get_file("file");
      +    auto content = f.filename + " (" + std::to_string(f.content.size()) + " bytes)";
      +    res.set_content(content, "text/plain");
      +});
       
       svr.Post("/upload", [](const auto &req, auto &res) {
      @@ -422,11 +424,11 @@
       

      マルチパートフォームで送られたファイルを受け取ります。req.form.get_file("file")"file" という名前のフィールドを取得し、f.filenamef.content.size() でファイル名とサイズを返しています。

      GET /users/:id

      -
      -svr.Get("/users/:id", [](const auto &req, auto &res) {
      -    auto id = req.path_params.at("id");
      -    res.set_content("User ID: " + id, "text/plain");
      -});
      +
      +svr.Get("/users/:id", [](const auto &req, auto &res) {
      +    auto id = req.path_params.at("id");
      +    res.set_content("User ID: " + id, "text/plain");
      +});
       
       svr.Get("/users/:id", [](const auto &req, auto &res) {
      @@ -437,11 +439,11 @@
       

      :id の部分がパスパラメーターです。req.path_params.at("id") で値を取り出しています。/users/42 なら "42"/users/alice なら "alice" が得られます。

      GET /files/(\d+)

      -
      -svr.Get(R"(/files/(\d+))", [](const auto &req, auto &res) {
      -    auto id = req.matches[1];
      -    res.set_content("File ID: " + std::string(id), "text/plain");
      -});
      +
      +svr.Get(R"(/files/(\d+))", [](const auto &req, auto &res) {
      +    auto id = req.matches[1];
      +    res.set_content("File ID: " + std::string(id), "text/plain");
      +});
       
       svr.Get(R"(/files/(\d+))", [](const auto &req, auto &res) {
      @@ -462,7 +464,7 @@
         
      - © 2026 yhirose. All rights reserved. + © 2026 Yuji Hirose. All rights reserved.
      diff --git a/docs/ja/tour/04-static-file-server/index.html b/docs/ja/tour/04-static-file-server/index.html index 79642a7..4487952 100644 --- a/docs/ja/tour/04-static-file-server/index.html +++ b/docs/ja/tour/04-static-file-server/index.html @@ -17,16 +17,16 @@
      - cpp-httplib v0.36.0 + cpp-httplib v0.36.0
      @@ -105,18 +107,18 @@

      cpp-httplibは、HTMLやCSS、画像ファイルなどの静的ファイルも配信できます。面倒な設定は要りません。set_mount_point() を1行呼ぶだけです。

      set_mount_point の基本

      さっそくやってみましょう。set_mount_point() は、URLのパスとローカルディレクトリを紐づけます。

      -
      -#include "httplib.h"
      -#include <iostream>
      -
      -int main() {
      -    httplib::Server svr;
      -
      -    svr.set_mount_point("/", "./html");
      -
      -    std::cout << "Listening on port 8080..." << std::endl;
      -    svr.listen("0.0.0.0", 8080);
      -}
      +
      +#include "httplib.h"
      +#include <iostream>
      +
      +int main() {
      +    httplib::Server svr;
      +
      +    svr.set_mount_point("/", "./html");
      +
      +    std::cout << "Listening on port 8080..." << std::endl;
      +    svr.listen("0.0.0.0", 8080);
      +}
       
       #include "httplib.h"
      @@ -134,21 +136,21 @@
       

      第1引数がURLのマウントポイント、第2引数がローカルのディレクトリパスです。この例だと、/ へのリクエストを ./html ディレクトリから配信します。

      試してみましょう。まず html ディレクトリを作って、index.html を置きます。

      -
      -mkdir html
      +
      +mkdir html
       
       mkdir html
       
      -
      -<!DOCTYPE html>
      -<html>
      -<head><title>My Page</title></head>
      -<body>
      -    <h1>Hello from cpp-httplib!</h1>
      -    <p>This is a static file.</p>
      -</body>
      -</html>
      +
      +<!DOCTYPE html>
      +<html>
      +<head><title>My Page</title></head>
      +<body>
      +    <h1>Hello from cpp-httplib!</h1>
      +    <p>This is a static file.</p>
      +</body>
      +</html>
       
       <!DOCTYPE html>
      @@ -162,9 +164,9 @@
       

      コンパイルして起動します。

      -
      -g++ -std=c++17 -o server server.cpp -pthread
      -./server
      +
      +g++ -std=c++17 -o server server.cpp -pthread
      +./server
       
       g++ -std=c++17 -o server server.cpp -pthread
      @@ -173,12 +175,12 @@
       

      ブラウザで http://localhost:8080 を開いてみてください。html/index.html の内容が表示されるはずです。http://localhost:8080/index.html でも同じページが返ります。

      もちろん、前章のクライアントコードや curl でもアクセスできますよ。

      -
      -httplib::Client cli("http://localhost:8080");
      -auto res = cli.Get("/");
      -if (res) {
      -    std::cout << res->body << std::endl;  // HTMLが表示される
      -}
      +
      +httplib::Client cli("http://localhost:8080");
      +auto res = cli.Get("/");
      +if (res) {
      +    std::cout << res->body << std::endl;  // HTMLが表示される
      +}
       
       httplib::Client cli("http://localhost:8080");
      @@ -187,8 +189,8 @@
           std::cout << res->body << std::endl;  // HTMLが表示される
       }
       
      -
      -curl http://localhost:8080
      +
      +curl http://localhost:8080
       
       curl http://localhost:8080
      @@ -196,10 +198,10 @@
       

      複数のマウントポイント

      set_mount_point() は何回でも呼べます。URLのパスごとに、別々のディレクトリを割り当てられます。

      -
      -svr.set_mount_point("/", "./public");
      -svr.set_mount_point("/assets", "./static/assets");
      -svr.set_mount_point("/docs", "./documentation");
      +
      +svr.set_mount_point("/", "./public");
      +svr.set_mount_point("/assets", "./static/assets");
      +svr.set_mount_point("/docs", "./documentation");
       
       svr.set_mount_point("/", "./public");
      @@ -210,18 +212,18 @@
       

      /assets/style.css なら ./static/assets/style.css を、/docs/guide.html なら ./documentation/guide.html を配信します。

      ハンドラーとの組み合わせ

      静的ファイルの配信と、前章で学んだルーティングハンドラーは共存できます。

      -
      -httplib::Server svr;
      -
      -// APIエンドポイント
      -svr.Get("/api/hello", [](const auto &, auto &res) {
      -    res.set_content(R"({"message":"Hello!"})", "application/json");
      -});
      -
      -// 静的ファイル配信
      -svr.set_mount_point("/", "./public");
      -
      -svr.listen("0.0.0.0", 8080);
      +
      +httplib::Server svr;
      +
      +// APIエンドポイント
      +svr.Get("/api/hello", [](const auto &, auto &res) {
      +    res.set_content(R"({"message":"Hello!"})", "application/json");
      +});
      +
      +// 静的ファイル配信
      +svr.set_mount_point("/", "./public");
      +
      +svr.listen("0.0.0.0", 8080);
       
       httplib::Server svr;
      @@ -240,10 +242,10 @@
       

      ハンドラーが先に評価されます。/api/hello にはハンドラーが応答し、それ以外のパスは ./public ディレクトリからファイルを探します。

      レスポンスヘッダーの追加

      set_mount_point() の第3引数にヘッダーを渡すと、静的ファイルのレスポンスにカスタムヘッダーを付けられます。キャッシュ制御に便利です。

      -
      -svr.set_mount_point("/", "./public", {
      -    {"Cache-Control", "max-age=3600"}
      -});
      +
      +svr.set_mount_point("/", "./public", {
      +    {"Cache-Control", "max-age=3600"}
      +});
       
       svr.set_mount_point("/", "./public", {
      @@ -254,14 +256,14 @@
       

      こうすると、ブラウザは配信されたファイルを1時間キャッシュします。

      静的ファイルサーバー用のDockerファイル

      cpp-httplibのリポジトリには、静的ファイルサーバー用の Dockerfile が含まれています。Docker Hubにビルド済みイメージも公開しているので、1コマンドで起動できます。

      -
      -> docker run -p 8080:80 -v ./my-site:/html yhirose4dockerhub/cpp-httplib-server
      -Serving HTTP on 0.0.0.0:80
      -Mount point: / -> ./html
      -Press Ctrl+C to shutdown gracefully...
      -192.168.65.1 - - [22/Feb/2026:12:00:00 +0000] "GET / HTTP/1.1" 200 256 "-" "Mozilla/5.0 ..."
      -192.168.65.1 - - [22/Feb/2026:12:00:00 +0000] "GET /style.css HTTP/1.1" 200 1024 "-" "Mozilla/5.0 ..."
      -192.168.65.1 - - [22/Feb/2026:12:00:01 +0000] "GET /favicon.ico HTTP/1.1" 404 152 "-" "Mozilla/5.0 ..."
      +
      +> docker run -p 8080:80 -v ./my-site:/html yhirose4dockerhub/cpp-httplib-server
      +Serving HTTP on 0.0.0.0:80
      +Mount point: / -> ./html
      +Press Ctrl+C to shutdown gracefully...
      +192.168.65.1 - - [22/Feb/2026:12:00:00 +0000] "GET / HTTP/1.1" 200 256 "-" "Mozilla/5.0 ..."
      +192.168.65.1 - - [22/Feb/2026:12:00:00 +0000] "GET /style.css HTTP/1.1" 200 1024 "-" "Mozilla/5.0 ..."
      +192.168.65.1 - - [22/Feb/2026:12:00:01 +0000] "GET /favicon.ico HTTP/1.1" 404 152 "-" "Mozilla/5.0 ..."
       
       > docker run -p 8080:80 -v ./my-site:/html yhirose4dockerhub/cpp-httplib-server
      @@ -285,7 +287,7 @@
         
      - © 2026 yhirose. All rights reserved. + © 2026 Yuji Hirose. All rights reserved.
      diff --git a/docs/ja/tour/05-tls-setup/index.html b/docs/ja/tour/05-tls-setup/index.html index 9d0293b..863265e 100644 --- a/docs/ja/tour/05-tls-setup/index.html +++ b/docs/ja/tour/05-tls-setup/index.html @@ -17,16 +17,16 @@
      - cpp-httplib v0.36.0 + cpp-httplib v0.36.0
      @@ -113,22 +115,22 @@

      コンパイルオプション

      TLS機能を有効にするには、CPPHTTPLIB_OPENSSL_SUPPORT マクロを定義してコンパイルします。前章までのコンパイルコマンドに、いくつかオプションが増えます。

      -
      -# macOS (Homebrew)
      -clang++ -std=c++17 -DCPPHTTPLIB_OPENSSL_SUPPORT \
      -    -I$(brew --prefix openssl)/include \
      -    -L$(brew --prefix openssl)/lib \
      -    -lssl -lcrypto \
      -    -framework CoreFoundation -framework Security \
      -    -o server server.cpp
      -
      -# Linux
      -clang++ -std=c++17 -pthread -DCPPHTTPLIB_OPENSSL_SUPPORT \
      -    -lssl -lcrypto \
      -    -o server server.cpp
      -
      -# Windows (Developer Command Prompt)
      -cl /EHsc /std:c++17 /DCPPHTTPLIB_OPENSSL_SUPPORT server.cpp libssl.lib libcrypto.lib
      +
      +# macOS (Homebrew)
      +clang++ -std=c++17 -DCPPHTTPLIB_OPENSSL_SUPPORT \
      +    -I$(brew --prefix openssl)/include \
      +    -L$(brew --prefix openssl)/lib \
      +    -lssl -lcrypto \
      +    -framework CoreFoundation -framework Security \
      +    -o server server.cpp
      +
      +# Linux
      +clang++ -std=c++17 -pthread -DCPPHTTPLIB_OPENSSL_SUPPORT \
      +    -lssl -lcrypto \
      +    -o server server.cpp
      +
      +# Windows (Developer Command Prompt)
      +cl /EHsc /std:c++17 /DCPPHTTPLIB_OPENSSL_SUPPORT server.cpp libssl.lib libcrypto.lib
       
       # macOS (Homebrew)
      @@ -157,21 +159,21 @@
       
       

      動作確認

      ちゃんと動くか確認してみましょう。httplib::Client にHTTPSのURLを渡してアクセスするだけのプログラムです。

      -
      -#define CPPHTTPLIB_OPENSSL_SUPPORT
      -#include "httplib.h"
      -#include <iostream>
      -
      -int main() {
      -    httplib::Client cli("https://www.google.com");
      -
      -    auto res = cli.Get("/");
      -    if (res) {
      -        std::cout << "Status: " << res->status << std::endl;
      -    } else {
      -        std::cout << "Error: " << httplib::to_string(res.error()) << std::endl;
      -    }
      -}
      +
      +#define CPPHTTPLIB_OPENSSL_SUPPORT
      +#include "httplib.h"
      +#include <iostream>
      +
      +int main() {
      +    httplib::Client cli("https://www.google.com");
      +
      +    auto res = cli.Get("/");
      +    if (res) {
      +        std::cout << "Status: " << res->status << std::endl;
      +    } else {
      +        std::cout << "Error: " << httplib::to_string(res.error()) << std::endl;
      +    }
      +}
       
       #define CPPHTTPLIB_OPENSSL_SUPPORT
      @@ -209,7 +211,7 @@
         
      - © 2026 yhirose. All rights reserved. + © 2026 Yuji Hirose. All rights reserved.
      diff --git a/docs/ja/tour/06-https-client/index.html b/docs/ja/tour/06-https-client/index.html index d846cb6..8a0915b 100644 --- a/docs/ja/tour/06-https-client/index.html +++ b/docs/ja/tour/06-https-client/index.html @@ -17,16 +17,16 @@
      - cpp-httplib v0.36.0 + cpp-httplib v0.36.0
      @@ -105,22 +107,22 @@

      前章でOpenSSLのセットアップが済んだので、さっそくHTTPSクライアントを使ってみましょう。2章で使った httplib::Client がそのまま使えます。コンストラクタに https:// 付きのURLを渡すだけです。

      GETリクエスト

      実在するHTTPSサイトにアクセスしてみましょう。

      -
      -#define CPPHTTPLIB_OPENSSL_SUPPORT
      -#include "httplib.h"
      -#include <iostream>
      -
      -int main() {
      -    httplib::Client cli("https://nghttp2.org");
      -
      -    auto res = cli.Get("/");
      -    if (res) {
      -        std::cout << res->status << std::endl;           // 200
      -        std::cout << res->body.substr(0, 100) << std::endl;  // HTMLの先頭部分
      -    } else {
      -        std::cout << "Error: " << httplib::to_string(res.error()) << std::endl;
      -    }
      -}
      +
      +#define CPPHTTPLIB_OPENSSL_SUPPORT
      +#include "httplib.h"
      +#include <iostream>
      +
      +int main() {
      +    httplib::Client cli("https://nghttp2.org");
      +
      +    auto res = cli.Get("/");
      +    if (res) {
      +        std::cout << res->status << std::endl;           // 200
      +        std::cout << res->body.substr(0, 100) << std::endl;  // HTMLの先頭部分
      +    } else {
      +        std::cout << "Error: " << httplib::to_string(res.error()) << std::endl;
      +    }
      +}
       
       #define CPPHTTPLIB_OPENSSL_SUPPORT
      @@ -141,8 +143,8 @@
       

      2章では httplib::Client cli("http://localhost:8080") と書きましたよね。スキームを https:// に変えるだけです。Get()Post() など、2章で学んだAPIはすべてそのまま使えます。

      -
      -curl https://nghttp2.org/
      +
      +curl https://nghttp2.org/
       
       curl https://nghttp2.org/
      @@ -150,8 +152,8 @@
       

      ポートの指定

      HTTPSのデフォルトポートは443です。別のポートを使いたい場合は、URLにポートを含めます。

      -
      -httplib::Client cli("https://localhost:8443");
      +
      +httplib::Client cli("https://localhost:8443");
       
       httplib::Client cli("https://localhost:8443");
      @@ -162,11 +164,11 @@
       

      CA証明書は、macOSならKeychain、LinuxならシステムのCA証明書ストア、WindowsならWindowsの証明書ストアから自動で読み込みます。ほとんどの場合、追加の設定は要りません。

      CA証明書ファイルの指定

      環境によってはシステムのCA証明書が見つからないこともあります。そのときは set_ca_cert_path() でパスを直接指定してください。

      -
      -httplib::Client cli("https://nghttp2.org");
      -cli.set_ca_cert_path("/etc/ssl/certs/ca-certificates.crt");
      -
      -auto res = cli.Get("/");
      +
      +httplib::Client cli("https://nghttp2.org");
      +cli.set_ca_cert_path("/etc/ssl/certs/ca-certificates.crt");
      +
      +auto res = cli.Get("/");
       
       httplib::Client cli("https://nghttp2.org");
      @@ -174,8 +176,8 @@
       
       auto res = cli.Get("/");
       
      -
      -curl --cacert /etc/ssl/certs/ca-certificates.crt https://nghttp2.org/
      +
      +curl --cacert /etc/ssl/certs/ca-certificates.crt https://nghttp2.org/
       
       curl --cacert /etc/ssl/certs/ca-certificates.crt https://nghttp2.org/
      @@ -183,11 +185,11 @@
       

      証明書検証の無効化

      開発中、自己署名証明書のサーバーに接続したいときは、検証を無効にできます。

      -
      -httplib::Client cli("https://localhost:8443");
      -cli.enable_server_certificate_verification(false);
      -
      -auto res = cli.Get("/");
      +
      +httplib::Client cli("https://localhost:8443");
      +cli.enable_server_certificate_verification(false);
      +
      +auto res = cli.Get("/");
       
       httplib::Client cli("https://localhost:8443");
      @@ -195,8 +197,8 @@
       
       auto res = cli.Get("/");
       
      -
      -curl -k https://localhost:8443/
      +
      +curl -k https://localhost:8443/
       
       curl -k https://localhost:8443/
      @@ -206,14 +208,14 @@
       

      リダイレクトの追跡

      HTTPSサイトへのアクセスでは、リダイレクトに遭遇することがよくあります。たとえば http:// から https:// へ、あるいは www なしから www ありへ転送されるケースです。

      デフォルトではリダイレクトを追跡しません。リダイレクト先は Location ヘッダーで確認できます。

      -
      -httplib::Client cli("https://nghttp2.org");
      -
      -auto res = cli.Get("/httpbin/redirect/3");
      -if (res) {
      -    std::cout << res->status << std::endl;  // 302
      -    std::cout << res->get_header_value("Location") << std::endl;
      -}
      +
      +httplib::Client cli("https://nghttp2.org");
      +
      +auto res = cli.Get("/httpbin/redirect/3");
      +if (res) {
      +    std::cout << res->status << std::endl;  // 302
      +    std::cout << res->get_header_value("Location") << std::endl;
      +}
       
       httplib::Client cli("https://nghttp2.org");
      @@ -224,22 +226,22 @@
           std::cout << res->get_header_value("Location") << std::endl;
       }
       
      -
      -curl https://nghttp2.org/httpbin/redirect/3
      +
      +curl https://nghttp2.org/httpbin/redirect/3
       
       curl https://nghttp2.org/httpbin/redirect/3
       

      set_follow_location(true) を設定すると、リダイレクトを自動で追跡して、最終的なレスポンスを返してくれます。

      -
      -httplib::Client cli("https://nghttp2.org");
      -cli.set_follow_location(true);
      -
      -auto res = cli.Get("/httpbin/redirect/3");
      -if (res) {
      -    std::cout << res->status << std::endl;  // 200(最終的なレスポンス)
      -}
      +
      +httplib::Client cli("https://nghttp2.org");
      +cli.set_follow_location(true);
      +
      +auto res = cli.Get("/httpbin/redirect/3");
      +if (res) {
      +    std::cout << res->status << std::endl;  // 200(最終的なレスポンス)
      +}
       
       httplib::Client cli("https://nghttp2.org");
      @@ -250,8 +252,8 @@
           std::cout << res->status << std::endl;  // 200(最終的なレスポンス)
       }
       
      -
      -curl -L https://nghttp2.org/httpbin/redirect/3
      +
      +curl -L https://nghttp2.org/httpbin/redirect/3
       
       curl -L https://nghttp2.org/httpbin/redirect/3
      @@ -267,7 +269,7 @@
         
      - © 2026 yhirose. All rights reserved. + © 2026 Yuji Hirose. All rights reserved.
      diff --git a/docs/ja/tour/07-https-server/index.html b/docs/ja/tour/07-https-server/index.html index a188dae..32c3d64 100644 --- a/docs/ja/tour/07-https-server/index.html +++ b/docs/ja/tour/07-https-server/index.html @@ -17,16 +17,16 @@
      - cpp-httplib v0.36.0 + cpp-httplib v0.36.0
      @@ -106,8 +108,8 @@

      ただし、TLSサーバーにはサーバー証明書と秘密鍵が必要です。まずはそこから準備しましょう。

      自己署名証明書の作成

      開発やテスト用なら、自己署名証明書(いわゆるオレオレ証明書)で十分です。OpenSSLのコマンドでサクッと作れます。

      -
      -openssl req -x509 -noenc -keyout key.pem -out cert.pem -subj /CN=localhost
      +
      +openssl req -x509 -noenc -keyout key.pem -out cert.pem -subj /CN=localhost
       
       openssl req -x509 -noenc -keyout key.pem -out cert.pem -subj /CN=localhost
      @@ -120,21 +122,21 @@
       
       

      最小のHTTPSサーバー

      証明書ができたら、さっそくサーバーを書いてみましょう。

      -
      -#define CPPHTTPLIB_OPENSSL_SUPPORT
      -#include "httplib.h"
      -#include <iostream>
      -
      -int main() {
      -    httplib::SSLServer svr("cert.pem", "key.pem");
      -
      -    svr.Get("/", [](const auto &, auto &res) {
      -        res.set_content("Hello, HTTPS!", "text/plain");
      -    });
      -
      -    std::cout << "Listening on https://localhost:8443" << std::endl;
      -    svr.listen("0.0.0.0", 8443);
      -}
      +
      +#define CPPHTTPLIB_OPENSSL_SUPPORT
      +#include "httplib.h"
      +#include <iostream>
      +
      +int main() {
      +    httplib::SSLServer svr("cert.pem", "key.pem");
      +
      +    svr.Get("/", [](const auto &, auto &res) {
      +        res.set_content("Hello, HTTPS!", "text/plain");
      +    });
      +
      +    std::cout << "Listening on https://localhost:8443" << std::endl;
      +    svr.listen("0.0.0.0", 8443);
      +}
       
       #define CPPHTTPLIB_OPENSSL_SUPPORT
      @@ -157,9 +159,9 @@
       

      コンパイルして起動しましょう。

      動作確認

      サーバーが起動したら、curl でアクセスしてみましょう。自己署名証明書なので、-k オプションで証明書検証をスキップします。

      -
      -curl -k https://localhost:8443/
      -# Hello, HTTPS!
      +
      +curl -k https://localhost:8443/
      +# Hello, HTTPS!
       
       curl -k https://localhost:8443/
      @@ -171,20 +173,20 @@
       

      前章の httplib::Client で接続してみましょう。自己署名証明書のサーバーに接続するには、2つの方法があります。

      方法1: 証明書検証を無効にする

      開発時の手軽な方法です。

      -
      -#define CPPHTTPLIB_OPENSSL_SUPPORT
      -#include "httplib.h"
      -#include <iostream>
      -
      -int main() {
      -    httplib::Client cli("https://localhost:8443");
      -    cli.enable_server_certificate_verification(false);
      -
      -    auto res = cli.Get("/");
      -    if (res) {
      -        std::cout << res->body << std::endl;  // Hello, HTTPS!
      -    }
      -}
      +
      +#define CPPHTTPLIB_OPENSSL_SUPPORT
      +#include "httplib.h"
      +#include <iostream>
      +
      +int main() {
      +    httplib::Client cli("https://localhost:8443");
      +    cli.enable_server_certificate_verification(false);
      +
      +    auto res = cli.Get("/");
      +    if (res) {
      +        std::cout << res->body << std::endl;  // Hello, HTTPS!
      +    }
      +}
       
       #define CPPHTTPLIB_OPENSSL_SUPPORT
      @@ -204,20 +206,20 @@
       

      方法2: 自己署名証明書をCA証明書として指定する

      こちらのほうが安全です。cert.pem をCA証明書として信頼するよう指定します。

      -
      -#define CPPHTTPLIB_OPENSSL_SUPPORT
      -#include "httplib.h"
      -#include <iostream>
      -
      -int main() {
      -    httplib::Client cli("https://localhost:8443");
      -    cli.set_ca_cert_path("cert.pem");
      -
      -    auto res = cli.Get("/");
      -    if (res) {
      -        std::cout << res->body << std::endl;  // Hello, HTTPS!
      -    }
      -}
      +
      +#define CPPHTTPLIB_OPENSSL_SUPPORT
      +#include "httplib.h"
      +#include <iostream>
      +
      +int main() {
      +    httplib::Client cli("https://localhost:8443");
      +    cli.set_ca_cert_path("cert.pem");
      +
      +    auto res = cli.Get("/");
      +    if (res) {
      +        std::cout << res->body << std::endl;  // Hello, HTTPS!
      +    }
      +}
       
       #define CPPHTTPLIB_OPENSSL_SUPPORT
      @@ -256,7 +258,7 @@
         
      - © 2026 yhirose. All rights reserved. + © 2026 Yuji Hirose. All rights reserved.
      diff --git a/docs/ja/tour/08-websocket/index.html b/docs/ja/tour/08-websocket/index.html index 5b83e8b..197e5b7 100644 --- a/docs/ja/tour/08-websocket/index.html +++ b/docs/ja/tour/08-websocket/index.html @@ -17,16 +17,16 @@
      - cpp-httplib v0.36.0 + cpp-httplib v0.36.0
      @@ -106,23 +108,23 @@

      さっそく、エコーサーバーとクライアントを作ってみましょう。

      エコーサーバー

      受け取ったメッセージをそのまま返すエコーサーバーです。

      -
      -#include "httplib.h"
      -#include <iostream>
      -
      -int main() {
      -    httplib::Server svr;
      -
      -    svr.WebSocket("/ws", [](const httplib::Request &, httplib::ws::WebSocket &ws) {
      -        std::string msg;
      -        while (ws.read(msg)) {
      -            ws.send(msg);  // 受け取ったメッセージをそのまま返す
      -        }
      -    });
      -
      -    std::cout << "Listening on port 8080..." << std::endl;
      -    svr.listen("0.0.0.0", 8080);
      -}
      +
      +#include "httplib.h"
      +#include <iostream>
      +
      +int main() {
      +    httplib::Server svr;
      +
      +    svr.WebSocket("/ws", [](const httplib::Request &, httplib::ws::WebSocket &ws) {
      +        std::string msg;
      +        while (ws.read(msg)) {
      +            ws.send(msg);  // 受け取ったメッセージをそのまま返す
      +        }
      +    });
      +
      +    std::cout << "Listening on port 8080..." << std::endl;
      +    svr.listen("0.0.0.0", 8080);
      +}
       
       #include "httplib.h"
      @@ -147,29 +149,29 @@
       

      ハンドラーの中では、ws.read(msg) でメッセージを待ちます。接続が閉じられると read()false を返すので、ループを抜けます。ws.send(msg) でメッセージを送り返します。

      クライアントからの接続

      httplib::ws::WebSocketClient を使ってサーバーに接続してみましょう。

      -
      -#include "httplib.h"
      -#include <iostream>
      -
      -int main() {
      -    httplib::ws::WebSocketClient client("ws://localhost:8080/ws");
      -
      -    if (!client.connect()) {
      -        std::cout << "Connection failed" << std::endl;
      -        return 1;
      -    }
      -
      -    // メッセージを送信
      -    client.send("Hello, WebSocket!");
      -
      -    // サーバーからの応答を受信
      -    std::string msg;
      -    if (client.read(msg)) {
      -        std::cout << msg << std::endl;  // Hello, WebSocket!
      -    }
      -
      -    client.close();
      -}
      +
      +#include "httplib.h"
      +#include <iostream>
      +
      +int main() {
      +    httplib::ws::WebSocketClient client("ws://localhost:8080/ws");
      +
      +    if (!client.connect()) {
      +        std::cout << "Connection failed" << std::endl;
      +        return 1;
      +    }
      +
      +    // メッセージを送信
      +    client.send("Hello, WebSocket!");
      +
      +    // サーバーからの応答を受信
      +    std::string msg;
      +    if (client.read(msg)) {
      +        std::cout << msg << std::endl;  // Hello, WebSocket!
      +    }
      +
      +    client.close();
      +}
       
       #include "httplib.h"
      @@ -199,18 +201,18 @@
       

      コンストラクタには ws://host:port/path 形式のURLを渡します。connect() で接続を開始し、send()read() でメッセージをやり取りします。

      テキストとバイナリ

      WebSocketにはテキストとバイナリの2種類のメッセージがあります。read() の戻り値で区別できます。

      -
      -svr.WebSocket("/ws", [](const httplib::Request &, httplib::ws::WebSocket &ws) {
      -    std::string msg;
      -    httplib::ws::ReadResult ret;
      -    while ((ret = ws.read(msg))) {
      -        if (ret == httplib::ws::Binary) {
      -            ws.send(msg.data(), msg.size());  // バイナリとして送信
      -        } else {
      -            ws.send(msg);  // テキストとして送信
      -        }
      -    }
      -});
      +
      +svr.WebSocket("/ws", [](const httplib::Request &, httplib::ws::WebSocket &ws) {
      +    std::string msg;
      +    httplib::ws::ReadResult ret;
      +    while ((ret = ws.read(msg))) {
      +        if (ret == httplib::ws::Binary) {
      +            ws.send(msg.data(), msg.size());  // バイナリとして送信
      +        } else {
      +            ws.send(msg);  // テキストとして送信
      +        }
      +    }
      +});
       
       svr.WebSocket("/ws", [](const httplib::Request &, httplib::ws::WebSocket &ws) {
      @@ -233,19 +235,19 @@
       

      クライアント側も同じAPIです。

      リクエスト情報へのアクセス

      ハンドラーの第1引数 req から、ハンドシェイク時のHTTPリクエスト情報を読み取れます。認証トークンの確認などに便利です。

      -
      -svr.WebSocket("/ws", [](const httplib::Request &req, httplib::ws::WebSocket &ws) {
      -    auto token = req.get_header_value("Authorization");
      -    if (token.empty()) {
      -        ws.close(httplib::ws::CloseStatus::PolicyViolation, "unauthorized");
      -        return;
      -    }
      -
      -    std::string msg;
      -    while (ws.read(msg)) {
      -        ws.send(msg);
      -    }
      -});
      +
      +svr.WebSocket("/ws", [](const httplib::Request &req, httplib::ws::WebSocket &ws) {
      +    auto token = req.get_header_value("Authorization");
      +    if (token.empty()) {
      +        ws.close(httplib::ws::CloseStatus::PolicyViolation, "unauthorized");
      +        return;
      +    }
      +
      +    std::string msg;
      +    while (ws.read(msg)) {
      +        ws.send(msg);
      +    }
      +});
       
       svr.WebSocket("/ws", [](const httplib::Request &req, httplib::ws::WebSocket &ws) {
      @@ -264,17 +266,17 @@
       

      WSSで使う

      HTTPS上のWebSocket(WSS)にも対応しています。サーバー側は httplib::SSLServer にWebSocketハンドラーを登録するだけです。

      -
      -httplib::SSLServer svr("cert.pem", "key.pem");
      -
      -svr.WebSocket("/ws", [](const httplib::Request &, httplib::ws::WebSocket &ws) {
      -    std::string msg;
      -    while (ws.read(msg)) {
      -        ws.send(msg);
      -    }
      -});
      -
      -svr.listen("0.0.0.0", 8443);
      +
      +httplib::SSLServer svr("cert.pem", "key.pem");
      +
      +svr.WebSocket("/ws", [](const httplib::Request &, httplib::ws::WebSocket &ws) {
      +    std::string msg;
      +    while (ws.read(msg)) {
      +        ws.send(msg);
      +    }
      +});
      +
      +svr.listen("0.0.0.0", 8443);
       
       httplib::SSLServer svr("cert.pem", "key.pem");
      @@ -290,8 +292,8 @@
       

      クライアント側は wss:// スキームを使います。

      -
      -httplib::ws::WebSocketClient client("wss://localhost:8443/ws");
      +
      +httplib::ws::WebSocketClient client("wss://localhost:8443/ws");
       
       httplib::ws::WebSocketClient client("wss://localhost:8443/ws");
      @@ -308,7 +310,7 @@
         
      - © 2026 yhirose. All rights reserved. + © 2026 Yuji Hirose. All rights reserved.
      diff --git a/docs/ja/tour/09-whats-next/index.html b/docs/ja/tour/09-whats-next/index.html index ccf2628..add4f45 100644 --- a/docs/ja/tour/09-whats-next/index.html +++ b/docs/ja/tour/09-whats-next/index.html @@ -17,16 +17,16 @@
      - cpp-httplib v0.36.0 + cpp-httplib v0.36.0
      @@ -105,16 +107,16 @@

      Tourお疲れさまでした! cpp-httplibの基本はひと通り押さえましたね。でも、まだまだ便利な機能があります。Tourで取り上げなかった機能をカテゴリー別に紹介します。

      Streaming API

      LLMのストリーミング応答や大きなファイルのダウンロードでは、レスポンス全体をメモリに載せたくないですよね。stream::Get() を使えば、データをチャンクごとに処理できます。

      -
      -httplib::Client cli("http://localhost:11434");
      -
      -auto result = httplib::stream::Get(cli, "/api/generate");
      -
      -if (result) {
      -    while (result.next()) {
      -        std::cout.write(result.data(), result.size());
      -    }
      -}
      +
      +httplib::Client cli("http://localhost:11434");
      +
      +auto result = httplib::stream::Get(cli, "/api/generate");
      +
      +if (result) {
      +    while (result.next()) {
      +        std::cout.write(result.data(), result.size());
      +    }
      +}
       
       httplib::Client cli("http://localhost:11434");
      @@ -129,13 +131,13 @@
       

      Get()content_receiver コールバックを渡す方法もあります。こちらはKeep-Aliveと併用できます。

      -
      -httplib::Client cli("http://localhost:8080");
      -
      -cli.Get("/stream", [](const char *data, size_t len) {
      -    std::cout.write(data, len);
      -    return true;
      -});
      +
      +httplib::Client cli("http://localhost:8080");
      +
      +cli.Get("/stream", [](const char *data, size_t len) {
      +    std::cout.write(data, len);
      +    return true;
      +});
       
       httplib::Client cli("http://localhost:8080");
      @@ -147,25 +149,25 @@
       

      サーバー側には set_content_provider()set_chunked_content_provider() があります。サイズがわかっているなら前者、不明なら後者を使ってください。

      -
      -// サイズ指定あり(Content-Length が設定される)
      -svr.Get("/file", [](const auto &, auto &res) {
      -    auto size = get_file_size("large.bin");
      -    res.set_content_provider(size, "application/octet-stream",
      -        [](size_t offset, size_t length, httplib::DataSink &sink) {
      -            // offset から length バイト分を送る
      -            return true;
      -        });
      -});
      -
      -// サイズ不明(Chunked Transfer Encoding)
      -svr.Get("/stream", [](const auto &, auto &res) {
      -    res.set_chunked_content_provider("text/plain",
      -        [](size_t offset, httplib::DataSink &sink) {
      -            sink.write("chunk\n", 6);
      -            return true;  // falseを返すと終了
      -        });
      -});
      +
      +// サイズ指定あり(Content-Length が設定される)
      +svr.Get("/file", [](const auto &, auto &res) {
      +    auto size = get_file_size("large.bin");
      +    res.set_content_provider(size, "application/octet-stream",
      +        [](size_t offset, size_t length, httplib::DataSink &sink) {
      +            // offset から length バイト分を送る
      +            return true;
      +        });
      +});
      +
      +// サイズ不明(Chunked Transfer Encoding)
      +svr.Get("/stream", [](const auto &, auto &res) {
      +    res.set_chunked_content_provider("text/plain",
      +        [](size_t offset, httplib::DataSink &sink) {
      +            sink.write("chunk\n", 6);
      +            return true;  // falseを返すと終了
      +        });
      +});
       
       // サイズ指定あり(Content-Length が設定される)
      @@ -189,12 +191,12 @@
       

      大きなファイルのアップロードには make_file_provider() が便利です。ファイルを全部メモリに読み込まず、ストリーミングで送れます。

      -
      -httplib::Client cli("http://localhost:8080");
      -
      -auto res = cli.Post("/upload", {}, {
      -    httplib::make_file_provider("file", "/path/to/large-file.zip")
      -});
      +
      +httplib::Client cli("http://localhost:8080");
      +
      +auto res = cli.Post("/upload", {}, {
      +    httplib::make_file_provider("file", "/path/to/large-file.zip")
      +});
       
       httplib::Client cli("http://localhost:8080");
      @@ -206,15 +208,15 @@
       

      Server-Sent Events (SSE)

      SSEクライアントも用意しています。自動再接続や Last-Event-ID による再開にも対応しています。

      -
      -httplib::Client cli("http://localhost:8080");
      -httplib::sse::SSEClient sse(cli, "/events");
      -
      -sse.on_message([](const httplib::sse::SSEMessage &msg) {
      -    std::cout << msg.event << ": " << msg.data << std::endl;
      -});
      -
      -sse.start();  // ブロッキング、自動再接続あり
      +
      +httplib::Client cli("http://localhost:8080");
      +httplib::sse::SSEClient sse(cli, "/events");
      +
      +sse.on_message([](const httplib::sse::SSEMessage &msg) {
      +    std::cout << msg.event << ": " << msg.data << std::endl;
      +});
      +
      +sse.start();  // ブロッキング、自動再接続あり
       
       httplib::Client cli("http://localhost:8080");
      @@ -228,10 +230,10 @@
       

      イベントタイプごとにハンドラーを分けることもできますよ。

      -
      -sse.on_event("update", [](const httplib::sse::SSEMessage &msg) {
      -    // "update" イベントだけ処理
      -});
      +
      +sse.on_event("update", [](const httplib::sse::SSEMessage &msg) {
      +    // "update" イベントだけ処理
      +});
       
       sse.on_event("update", [](const httplib::sse::SSEMessage &msg) {
      @@ -241,10 +243,10 @@
       

      認証

      クライアントにはBasic認証、Bearer Token認証、Digest認証のヘルパーを用意しています。

      -
      -httplib::Client cli("https://api.example.com");
      -cli.set_basic_auth("user", "password");
      -cli.set_bearer_token_auth("my-token");
      +
      +httplib::Client cli("https://api.example.com");
      +cli.set_basic_auth("user", "password");
      +cli.set_bearer_token_auth("my-token");
       
       httplib::Client cli("https://api.example.com");
      @@ -259,10 +261,10 @@
       BrotliCPPHTTPLIB_BROTLI_SUPPORT
       ZstandardCPPHTTPLIB_ZSTD_SUPPORT
       
      -
      -httplib::Client cli("https://example.com");
      -cli.set_compress(true);    // リクエストボディを圧縮
      -cli.set_decompress(true);  // レスポンスボディを展開
      +
      +httplib::Client cli("https://example.com");
      +cli.set_compress(true);    // リクエストボディを圧縮
      +cli.set_decompress(true);  // レスポンスボディを展開
       
       httplib::Client cli("https://example.com");
      @@ -272,10 +274,10 @@
       

      プロキシ

      HTTPプロキシ経由で接続できます。

      -
      -httplib::Client cli("https://example.com");
      -cli.set_proxy("proxy.example.com", 8080);
      -cli.set_proxy_basic_auth("user", "password");
      +
      +httplib::Client cli("https://example.com");
      +cli.set_proxy("proxy.example.com", 8080);
      +cli.set_proxy_basic_auth("user", "password");
       
       httplib::Client cli("https://example.com");
      @@ -285,11 +287,11 @@
       

      タイムアウト

      接続・読み取り・書き込みのタイムアウトを個別に設定できます。

      -
      -httplib::Client cli("https://example.com");
      -cli.set_connection_timeout(5, 0);  // 5秒
      -cli.set_read_timeout(10, 0);       // 10秒
      -cli.set_write_timeout(10, 0);      // 10秒
      +
      +httplib::Client cli("https://example.com");
      +cli.set_connection_timeout(5, 0);  // 5秒
      +cli.set_read_timeout(10, 0);       // 10秒
      +cli.set_write_timeout(10, 0);      // 10秒
       
       httplib::Client cli("https://example.com");
      @@ -300,9 +302,9 @@
       

      Keep-Alive

      同じサーバーに何度もリクエストするなら、Keep-Aliveを有効にしましょう。TCP接続を再利用するので効率的です。

      -
      -httplib::Client cli("https://example.com");
      -cli.set_keep_alive(true);
      +
      +httplib::Client cli("https://example.com");
      +cli.set_keep_alive(true);
       
       httplib::Client cli("https://example.com");
      @@ -311,16 +313,16 @@
       

      サーバーのミドルウェア

      リクエスト処理の前後にフックを挟めます。

      -
      -svr.set_pre_routing_handler([](const auto &req, auto &res) {
      -    // すべてのリクエストの前に実行される
      -    return httplib::Server::HandlerResponse::Unhandled;  // 通常のルーティングに進む
      -});
      -
      -svr.set_post_routing_handler([](const auto &req, auto &res) {
      -    // レスポンスが返された後に実行される
      -    res.set_header("X-Server", "cpp-httplib");
      -});
      +
      +svr.set_pre_routing_handler([](const auto &req, auto &res) {
      +    // すべてのリクエストの前に実行される
      +    return httplib::Server::HandlerResponse::Unhandled;  // 通常のルーティングに進む
      +});
      +
      +svr.set_post_routing_handler([](const auto &req, auto &res) {
      +    // レスポンスが返された後に実行される
      +    res.set_header("X-Server", "cpp-httplib");
      +});
       
       svr.set_pre_routing_handler([](const auto &req, auto &res) {
      @@ -335,16 +337,16 @@
       

      req.user_data を使うと、ミドルウェアからハンドラーにデータを渡せます。認証トークンのデコード結果を共有するときに便利です。

      -
      -svr.set_pre_routing_handler([](const auto &req, auto &res) {
      -    req.user_data["auth_user"] = std::string("alice");
      -    return httplib::Server::HandlerResponse::Unhandled;
      -});
      -
      -svr.Get("/me", [](const auto &req, auto &res) {
      -    auto user = std::any_cast<std::string>(req.user_data.at("auth_user"));
      -    res.set_content("Hello, " + user, "text/plain");
      -});
      +
      +svr.set_pre_routing_handler([](const auto &req, auto &res) {
      +    req.user_data["auth_user"] = std::string("alice");
      +    return httplib::Server::HandlerResponse::Unhandled;
      +});
      +
      +svr.Get("/me", [](const auto &req, auto &res) {
      +    auto user = std::any_cast<std::string>(req.user_data.at("auth_user"));
      +    res.set_content("Hello, " + user, "text/plain");
      +});
       
       svr.set_pre_routing_handler([](const auto &req, auto &res) {
      @@ -359,15 +361,15 @@
       

      エラーや例外のハンドラーもカスタマイズできますよ。

      -
      -svr.set_error_handler([](const auto &req, auto &res) {
      -    res.set_content("Custom Error Page", "text/html");
      -});
      -
      -svr.set_exception_handler([](const auto &req, auto &res, std::exception_ptr ep) {
      -    res.status = 500;
      -    res.set_content("Internal Server Error", "text/plain");
      -});
      +
      +svr.set_error_handler([](const auto &req, auto &res) {
      +    res.set_content("Custom Error Page", "text/html");
      +});
      +
      +svr.set_exception_handler([](const auto &req, auto &res, std::exception_ptr ep) {
      +    res.status = 500;
      +    res.set_content("Internal Server Error", "text/plain");
      +});
       
       svr.set_error_handler([](const auto &req, auto &res) {
      @@ -382,10 +384,10 @@
       

      ロギング

      サーバーでもクライアントでもロガーを設定できます。

      -
      -svr.set_logger([](const auto &req, const auto &res) {
      -    std::cout << req.method << " " << req.path << " " << res.status << std::endl;
      -});
      +
      +svr.set_logger([](const auto &req, const auto &res) {
      +    std::cout << req.method << " " << req.path << " " << res.status << std::endl;
      +});
       
       svr.set_logger([](const auto &req, const auto &res) {
      @@ -395,11 +397,11 @@
       

      Unix Domain Socket

      TCP以外に、Unix Domain Socketでの通信にも対応しています。同じマシン上のプロセス間通信に使えます。

      -
      -// サーバー
      -httplib::Server svr;
      -svr.set_address_family(AF_UNIX);
      -svr.listen("/tmp/httplib.sock", 0);
      +
      +// サーバー
      +httplib::Server svr;
      +svr.set_address_family(AF_UNIX);
      +svr.listen("/tmp/httplib.sock", 0);
       
       // サーバー
      @@ -407,13 +409,13 @@
       svr.set_address_family(AF_UNIX);
       svr.listen("/tmp/httplib.sock", 0);
       
      -
      -// クライアント
      -httplib::Client cli("http://localhost");
      -cli.set_address_family(AF_UNIX);
      -cli.set_hostname_addr_map({{"localhost", "/tmp/httplib.sock"}});
      -
      -auto res = cli.Get("/");
      +
      +// クライアント
      +httplib::Client cli("http://localhost");
      +cli.set_address_family(AF_UNIX);
      +cli.set_hostname_addr_map({{"localhost", "/tmp/httplib.sock"}});
      +
      +auto res = cli.Get("/");
       
       // クライアント
      @@ -440,7 +442,7 @@
         
      - © 2026 yhirose. All rights reserved. + © 2026 Yuji Hirose. All rights reserved.
      diff --git a/docs/ja/tour/index.html b/docs/ja/tour/index.html index fc7a6ea..2c31798 100644 --- a/docs/ja/tour/index.html +++ b/docs/ja/tour/index.html @@ -17,16 +17,16 @@
      - cpp-httplib v0.36.0 + cpp-httplib v0.36.0
      @@ -121,7 +123,7 @@
      - © 2026 yhirose. All rights reserved. + © 2026 Yuji Hirose. All rights reserved.