リクエスト、レスポンス、ハンドラー、サーバーを定義した最小限のフレームワークです。
- Cargo.toml
- src/lib.rs
- app.php
| # VOICEVOX v0.16.0 C API サンプルのMakefile(辞書パス対応版) | |
| # 環境変数またはデフォルトパス | |
| VOICEVOX_DIR ?= /home/masakielastic/.voicevox/squashfs-root/vv-engine | |
| # コンパイル設定 | |
| CC = gcc | |
| CFLAGS = -Wall -Wextra -std=c99 -DVOICEVOX_LINK_ONNXRUNTIME | |
| LDFLAGS = -L$(VOICEVOX_DIR) -lvoicevox_core -lonnxruntime | |
| INCLUDES = -I. |
| [package] | |
| name = "smol-http-server" | |
| version = "0.1.0" | |
| edition = "2021" | |
| [dependencies] | |
| smol = "2.0" |
| [package] | |
| name = "tokio_http" | |
| version = "0.1.0" | |
| edition = "2021" | |
| [lib] | |
| crate-type = ["cdylib"] | |
| [dependencies] | |
| ext-php-rs = "0.13" |
| <?php | |
| // PHP libuv拡張を使ったシンプルなHTTP/1.1サーバー | |
| function createHttpResponse($statusCode, $statusText, $body, $headers = []) { | |
| $response = "HTTP/1.1 {$statusCode} {$statusText}\r\n"; | |
| // デフォルトヘッダー | |
| $defaultHeaders = [ | |
| 'Content-Type' => 'text/html; charset=utf-8', | |
| 'Content-Length' => strlen($body), |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <string.h> | |
| #include <unistd.h> | |
| #include <sys/socket.h> | |
| #include <netinet/in.h> | |
| #include <arpa/inet.h> | |
| #include <poll.h> | |
| #include <errno.h> | |
| #include <fcntl.h> |