Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frameworks/sober/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# The sober toolchain is pulled as an image (built by the release CI from the release tarball,
# sha256-checked - alpine with the single static ELF compiler on PATH). A registry pull only:
# nothing is downloaded from github.com at docker-build time.
FROM ghcr.io/sober-lang/sober:0.7.4 AS build
FROM ghcr.io/sober-lang/sober:0.7.5 AS build
WORKDIR /app
COPY main.sober ./
RUN sober build main.sober -o server
Expand Down
2 changes: 1 addition & 1 deletion frameworks/sober/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## Stack

- Language: Sober 0.7.4
- Language: Sober 0.7.5
- Framework: none beyond the standard library: `std/http/server` (server, router, middleware, gzip), `std/json`, `std/tls`, `std/pg`
- Build: the release tarball of the compiler (one static ELF, standard library built in) on `alpine`, static binary on `scratch`

Expand Down
66 changes: 66 additions & 0 deletions frameworks/sober/main.sober
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package main

import "std/builder"
import "std/compress/flate"
import "std/compress/gzip"
import "std/convert"
import "std/http"
import "std/http/server"
Expand Down Expand Up @@ -126,6 +127,70 @@ func specHeaders(r http.server.Request) http.server.Response {
return http.server.Text(strings.Join(freeze(lines), ""))
}

// /parse, the resilience suite's parser endpoint: the body goes through the standard parser its Content-Type names
// (JSON → json.Parse, a form → url.ParseQuery, multipart → http.server.Multipart). A body in a Content-Encoding (gzip /
// deflate) is decoded first, its output capped at maxBody like a plain body (the zlib checksum of deflate is not checked). 200 when it parses, 400 when it does not, 413
// when the decoded body is over the cap, 415 for an encoding the server does not decode
func parse(r http.server.Request) http.server.Response {
enc := field(r, "content-encoding")
if enc != "" && enc != "identity" {
if enc != "gzip" && enc != "x-gzip" && enc != "deflate" {
return http.server.Status(http.StatusCode(415))
}
if enc == "deflate" {
// the deflate coding is the zlib format (RFC 9110 8.4.1.2): a 2-byte header, the DEFLATE data, a 4-byte Adler-32
z := r.body
if len(z) < 6 || int(z[0]) % 16 != 8 || (int(z[0]) * 256 + int(z[1])) % 31 != 0 || int(z[1]) / 32 % 2 != 0 {
return http.server.Status(http.BadRequest)
}
b, e := compress.flate.Decode(z[2:len(z) - 4], maxSize: maxBody)
return decoded(mediaType(r), b, e)
}
b, e := compress.gzip.Decode(r.body, maxSize: maxBody)
return decoded(mediaType(r), b, e)
}
mt := mediaType(r)
if mt == "multipart/form-data" {
_ := http.server.Multipart(r) catch return http.server.Status(http.BadRequest)
return http.server.Text("ok")
}
return parsed(mt, r.body)
}

func decoded(mt string, b []byte, e error?) http.server.Response {
return switch e {
case nil: parsed(mt, b)
case compress.flate.TooLarge{}: http.server.Status(http.ContentTooLarge)
default: http.server.Status(http.BadRequest)
}
}

// A request header's value, lower case and trimmed ("" when absent)
func field(r http.server.Request, name string) string {
v := http.server.Header(r, name)
if v == nil {
return ""
}
return strings.ToLower(strings.TrimSpace(v))
}

// The media type of the request, lower case, without its parameters
func mediaType(r http.server.Request) string {
mt, _, _ := strings.Cut(field(r, "content-type"), ";")
return strings.TrimSpace(mt)
}

// JSON and form bodies are parsed; any other type is only buffered (a multipart body that came in a Content-Encoding too)
func parsed(mt string, b []byte) http.server.Response {
if mt == "application/json" {
_ := json.Parse(b) catch return http.server.Status(http.BadRequest)
} else if mt == "application/x-www-form-urlencoded" {
q := string(b) catch return http.server.Status(http.BadRequest)
_ := url.ParseQuery(q) catch return http.server.Status(http.BadRequest)
}
return http.server.Text("ok")
}

func routes(ds []Item) []http.server.Route {
none := []http.server.Middleware{}
return []http.server.Route{
Expand All @@ -135,6 +200,7 @@ func routes(ds []Item) []http.server.Route {
http.server.Route{method: "GET", path: "/delay/:ms", handler: delay, middleware: none},
http.server.Route{method: "GET", path: "/json/:count", handler: (r) => items(ds, r), middleware: none, cache: http.server.Unstated{}},
http.server.Route{method: "POST", path: "/echo", handler: echo, middleware: none},
http.server.Route{method: "POST", path: "/parse", handler: parse, middleware: none},
http.server.Route{method: "GET", path: "/spec", handler: specText, middleware: none},
http.server.Route{method: "OPTIONS", path: "/spec", handler: specOptions, middleware: none},
http.server.Route{method: "POST", path: "/spec", handler: echo, middleware: none},
Expand Down
1 change: 1 addition & 0 deletions frameworks/sober/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"description": "Sober's standard library HTTP/1.1 server (std/http on std/net, TLS 1.3 from std/tls), default configuration. One task per connection; one io_uring and one SO_REUSEPORT listener per worker — each worker accepts on its own ring and runs the connection itself (epoll fallback), with workers pinned one per CPU. Routes are a plain table ([]http.Route with method, :param / *rest patterns, Mount / Merge, before / after middleware), JSON through std/json, gzip through the built-in compression: option of the server. /async-db through std/pg, the standard library's own PostgreSQL client (wire protocol 3.0, extended query, SCRAM-SHA-256) and its connection pool (pg.OpenPool / pg.With) sized from DATABASE_MAX_CONN. Static ELF with no libc, FROM scratch.",
"repo": "https://github.com/sober-lang/sober",
"enabled": true,
"resilience": true,
"tests": [
"baseline",
"pipelined",
Expand Down
2 changes: 1 addition & 1 deletion site/data/frameworks.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
},
"aegon": {
"dir": "aegon",
"description": "Linux-native C++26 asynchronous web framework powered by io_uring multishot primitives, coroutines, stepped SIMD vectorization, Glaze JSON serialization, and native zero-overhead gRPC over HTTP/2 with kTLS TX offload.",
"description": "Linux-native C++26 asynchronous web framework on io_uring: one event loop per core with multishot accept and recv over provided buffer rings, requests parsed in place from the receive buffer, coroutine handlers with userspace timers, Glaze JSON serialization, and gzip/deflate (libdeflate) and brotli compression middleware. Static files are served from a per-worker cache that follows the disk through inotify, with precompressed .br/.gz variants. TLS 1.3 through OpenSSL with a zero-copy connection BIO and ALPN; HTTP/2 and HTTP/3 (QUIC) with pooled streams; WebSocket; native gRPC over HTTP/2.",
"repo": "https://github.com/UdayKhare09/Aegon",
"type": "experimental",
"engine": "io_uring",
Expand Down
Loading