| @@ -9,25 +9,50 @@ |
| 9 | 9 | /// } |
| 10 | 10 | /// } |
| 11 | 11 | /// |
| 12 | | −/// Each connection is handled by an actor of its own, which reads one |
| 13 | | −/// request, calls the handler, writes the response, and closes the |
| 14 | | −/// connection (`Connection: close`). Request heads are parsed by |
| 15 | | −/// httparse (picohttpparser's design) in the runtime. |
| 12 | +/// Each connection is handled by an actor of its own, which serves its |
| 13 | +/// requests one after another (keep-alive; ADR 0012): |
| 14 | +/// - an HTTP/1.1 connection stays open unless the request or the response |
| 15 | +/// has `Connection: close`; an HTTP/1.0 one only if the request has |
| 16 | +/// `Connection: keep-alive`; |
| 17 | +/// - a connection that waits longer than the idle timeout for a request, |
| 18 | +/// or for more of one, is closed (the handler and the response are not |
| 19 | +/// timed); |
| 20 | +/// - request bodies are read whole, sized by `Content-Length` or chunked |
| 21 | +/// (`Transfer-Encoding: chunked`); a malformed request gets an error |
| 22 | +/// response, and the connection is closed; |
| 23 | +/// - the server sets `Content-Length` and `Connection` on responses. |
| 24 | +/// |
| 25 | +/// Request heads and chunk sizes are parsed by httparse (picohttpparser's |
| 26 | +/// design) in the runtime. |
| 16 | 27 | |
| 17 | 28 | import std/io |
| 18 | 29 | import std/list |
| 30 | +import std/option |
| 19 | 31 | import std/string |
| 32 | +import std/bytes.{type Builder} |
| 20 | 33 | import std/net.{type TcpListener, type TcpStream} |
| 21 | 34 | import std/ffi.{type Resource} |
| 22 | 35 | import std/html.{type Html} |
| 23 | | −import std/process.{type proc} |
| 36 | +import std/process.{type proc, type Pid, type Subject} |
| 24 | 37 | |
| 25 | 38 | pub type Request { |
| 26 | | − Request(method: String, path: String, headers: List<(String, String)>, body: String) |
| 39 | + Request(method: String, path: String, headers: List<(String, String)>, body: Bytes) |
| 27 | 40 | } |
| 28 | 41 | |
| 29 | 42 | pub type Response { |
| 30 | | − Response(status: Int, headers: List<(String, String)>, body: String) |
| 43 | + Response(status: Int, headers: List<(String, String)>, body: Bytes) |
| 44 | +} |
| 45 | + |
| 46 | +pub type Settings { |
| 47 | + /// Serve `connections` connections, then return (all of them if |
| 48 | + /// negative). Close a connection that waits `idle_timeout` milliseconds |
| 49 | + /// for a request or for more of one (never if negative). |
| 50 | + Settings(connections: Int, idle_timeout: Int) |
| 51 | +} |
| 52 | + |
| 53 | +/// Every connection, closed after 5 idle seconds. |
| 54 | +pub fn defaults() -> Settings { |
| 55 | + Settings(connections: -1, idle_timeout: 5000) |
| 31 | 56 | } |
| 32 | 57 | |
| 33 | 58 | /// The value of header `name` (case-insensitive), if present. |
| @@ -42,19 +67,29 @@ fn find_header(headers, name) { |
| 42 | 67 | } |
| 43 | 68 | } |
| 44 | 69 | |
| 70 | +/// The request body as text, if it is valid UTF-8. |
| 71 | +pub fn body_text(req: Request) -> Result<String, String> { |
| 72 | + bytes.to_string(req.body) |
| 73 | +} |
| 74 | + |
| 75 | +/// The fields of a form-encoded request body (see `form`). |
| 76 | +pub fn form_body(req: Request) -> List<(String, String)> { |
| 77 | + form(bytes.to_string_lossy(req.body)) |
| 78 | +} |
| 79 | + |
| 45 | 80 | /// A response with `body` of type `content_type`. |
| 46 | | −pub fn response(status: Int, content_type: String, body: String) -> Response { |
| 81 | +pub fn response(status: Int, content_type: String, body: Bytes) -> Response { |
| 47 | 82 | Response(status, [("Content-Type", content_type)], body) |
| 48 | 83 | } |
| 49 | 84 | |
| 50 | 85 | /// A 200 response with a rendered page. |
| 51 | 86 | pub fn html(page: Html) -> Response { |
| 52 | | − response(200, "text/html; charset=utf-8", html.render(page)) |
| 87 | + response(200, "text/html; charset=utf-8", bytes.from_string(html.render(page))) |
| 53 | 88 | } |
| 54 | 89 | |
| 55 | 90 | /// A plain-text response. |
| 56 | 91 | pub fn text(status: Int, body: String) -> Response { |
| 57 | | − response(status, "text/plain; charset=utf-8", body) |
| 92 | + response(status, "text/plain; charset=utf-8", bytes.from_string(body)) |
| 58 | 93 | } |
| 59 | 94 | |
| 60 | 95 | pub fn not_found() -> Response { |
| @@ -66,93 +101,292 @@ pub fn listen(host: String, port: Int) -> Result<Resource<TcpListener>, String> |
| 66 | 101 | net.listen(host, port) |
| 67 | 102 | } |
| 68 | 103 | |
| 69 | | −/// Serve forever: one actor per connection. |
| 104 | +/// Serve forever with the default settings. |
| 70 | 105 | pub fn serve(server: Resource<TcpListener>, handler: fn(Request) -> Response / <io, proc, ffi>) -> () / <io, proc> { |
| 71 | | − serve_some(server, -1, handler) |
| 106 | + serve_with(server, defaults(), handler) |
| 72 | 107 | } |
| 73 | 108 | |
| 74 | | −/// Serve `count` connections (all of them if negative), then return. The |
| 75 | | −/// last connection's actor may still be running. |
| 76 | | −pub fn serve_some(server: Resource<TcpListener>, count: Int, handler: fn(Request) -> Response / <io, proc, ffi>) -> () / <io, proc> { |
| 77 | | − if count != 0 { |
| 109 | +/// Serve with `settings`: one actor per connection. When this returns, |
| 110 | +/// the last connections' actors may still be running. |
| 111 | +pub fn serve_with(server: Resource<TcpListener>, settings: Settings, handler: fn(Request) -> Response / <io, proc, ffi>) -> () / <io, proc> { |
| 112 | + let Settings(connections, idle_timeout) = settings |
| 113 | + if connections != 0 { |
| 78 | 114 | match net.accept(server) { |
| 79 | 115 | Ok(conn) -> { |
| 80 | | − process.spawn(fn() { handle_connection(conn, handler) }) |
| 116 | + process.spawn(fn() { handle_connection(conn, idle_timeout, handler) }) |
| 81 | 117 | () |
| 82 | 118 | }, |
| 83 | 119 | Error(e) -> io.eprintln("http: accept failed: " <> e), |
| 84 | 120 | } |
| 85 | | − serve_some(server, count - 1, handler) |
| 121 | + serve_with(server, Settings(connections - 1, idle_timeout), handler) |
| 86 | 122 | } else { |
| 87 | 123 | () |
| 88 | 124 | } |
| 89 | 125 | } |
| 90 | 126 | |
| 91 | | −fn handle_connection(conn: Resource<TcpStream>, handler: fn(Request) -> Response / <io, proc, ffi>) -> () / <io, proc, ffi> { |
| 92 | | − match read_request(conn, "") { |
| 93 | | − Ok(req) -> { |
| 127 | +/// What a connection's watchdog learns. |
| 128 | +type Activity { |
| 129 | + /// The connection's actor waits for a request, or for more of one: |
| 130 | + /// timed. |
| 131 | + Reading |
| 132 | + /// It runs the handler and sends the response: not timed. |
| 133 | + Handling |
| 134 | + /// It stopped (also by crashing). |
| 135 | + Stopped |
| 136 | +} |
| 137 | + |
| 138 | +fn handle_connection(conn: Resource<TcpStream>, idle_timeout: Int, handler: fn(Request) -> Response / <io, proc, ffi>) -> () / <io, proc, ffi> { |
| 139 | + let me = process.self() |
| 140 | + let ready = process.subject() |
| 141 | + let _ = process.spawn(fn() { watchdog(conn, me, idle_timeout, ready) }) |
| 142 | + let activity = process.receive_forever(ready) |
| 143 | + serve_requests(conn, activity, handler, bytes.empty(), 0) |
| 144 | + net.close(conn) |
| 145 | +} |
| 146 | + |
| 147 | +/// Close the connection when it waits too long for a request: its actor |
| 148 | +/// then reads the end of the stream and stops. The watchdog monitors that |
| 149 | +/// actor, and stops with it, releasing its reference to the socket. |
| 150 | +fn watchdog(conn: Resource<TcpStream>, owner: Pid, idle_timeout: Int, ready: Subject<Subject<Activity>>) -> () / <io, proc> { |
| 151 | + let activity = process.subject() |
| 152 | + let down = process.monitor(owner) |
| 153 | + process.send(ready, activity) |
| 154 | + let events = process.new_selector() |
| 155 | + |> process.selecting(activity, fn(a) { a }) |
| 156 | + |> process.selecting(down, fn(_) { Stopped }) |
| 157 | + watch(conn, idle_timeout, events, idle_timeout) |
| 158 | +} |
| 159 | + |
| 160 | +fn watch(conn, idle_timeout, events, timeout) { |
| 161 | + match process.select(events, timeout) { |
| 162 | + None -> net.close(conn), |
| 163 | + Some(Reading) -> watch(conn, idle_timeout, events, idle_timeout), |
| 164 | + Some(Handling) -> watch(conn, idle_timeout, events, -1), |
| 165 | + Some(Stopped) -> (), |
| 166 | + } |
| 167 | +} |
| 168 | + |
| 169 | +/// Why no request was read. |
| 170 | +type Failure { |
| 171 | + /// The connection closed or failed: nothing to answer. |
| 172 | + Closed |
| 173 | + /// A malformed request, answered with `status` before closing. |
| 174 | + Bad(status: Int, message: String) |
| 175 | +} |
| 176 | + |
| 177 | +/// A request, whether the client keeps the connection open after it, and |
| 178 | +/// where the next request starts (offset `at` of `buffer`). |
| 179 | +type Incoming { |
| 180 | + Incoming(request: Request, keep_alive: Bool, buffer: Bytes, at: Int) |
| 181 | +} |
| 182 | + |
| 183 | +/// Serve the requests in `buffer` (from offset `at`), then those that |
| 184 | +/// arrive, until either side closes the connection. |
| 185 | +fn serve_requests(conn: Resource<TcpStream>, activity: Subject<Activity>, handler: fn(Request) -> Response / <io, proc, ffi>, buffer: Bytes, at: Int) -> () / <io, proc, ffi> { |
| 186 | + match read_request(conn, activity, buffer, at) { |
| 187 | + Ok(Incoming(req, keep_alive, buffer, at)) -> { |
| 188 | + process.send(activity, Handling) |
| 189 | + let with_body = req.method != "HEAD" |
| 94 | 190 | let resp = handler(req) |
| 95 | | − let _ = net.write(conn, serialize(resp)) |
| 96 | | − () |
| 191 | + let keep = keep_alive && !has_token(option.unwrap_or(find_header(resp.headers, "connection"), ""), "close") |
| 192 | + match net.write(conn, serialize(resp, keep, with_body)) { |
| 193 | + Ok(_) -> if keep { serve_requests(conn, activity, handler, buffer, at) } else { () }, |
| 194 | + Error(_) -> (), |
| 195 | + } |
| 97 | 196 | }, |
| 98 | | − Error(e) -> { |
| 99 | | − let _ = net.write(conn, serialize(text(400, e))) |
| 197 | + Error(Closed) -> (), |
| 198 | + Error(Bad(status, message)) -> { |
| 199 | + let _ = net.write(conn, serialize(text(status, message), False, True)) |
| 100 | 200 | () |
| 101 | 201 | }, |
| 102 | 202 | } |
| 103 | | − net.close(conn) |
| 104 | 203 | } |
| 105 | 204 | |
| 106 | | −/// Read until the head is complete, then the body (`Content-Length`). |
| 107 | | −fn read_request(conn: Resource<TcpStream>, buffer: String) -> Result<Request, String> / <io> { |
| 108 | | − match parse_head(buffer) { |
| 109 | | − Complete(method, path, headers, rest, length) -> |
| 110 | | − match read_body(conn, rest, length) { |
| 111 | | − Ok(body) -> Ok(Request(method, path, headers, body)), |
| 205 | +fn read_request(conn, activity, buffer: Bytes, at: Int) -> Result<Incoming, Failure> / <io, proc> { |
| 206 | + match parse_head(buffer, at) { |
| 207 | + Complete(method, path, version, headers, end, length) -> |
| 208 | + match read_body(conn, activity, headers, length, buffer, end) { |
| 209 | + Ok((body, buffer, at)) -> Ok(Incoming(Request(method, path, headers, body), keeps_alive(version, headers), buffer, at)), |
| 112 | 210 | Error(e) -> Error(e), |
| 113 | 211 | }, |
| 114 | | − Invalid(reason) -> Error("bad request: " <> reason), |
| 212 | + Invalid(reason) -> Error(Bad(400, "bad request: " <> reason)), |
| 115 | 213 | Partial -> |
| 116 | | − if string.byte_length(buffer) > 65536 { |
| 117 | | − Error("request head too large") |
| 214 | + if bytes.length(buffer) - at > 65536 { |
| 215 | + Error(Bad(431, "request head too large")) |
| 216 | + } else { |
| 217 | + match receive_more(conn, activity, buffer, at) { |
| 218 | + Ok(buffer) -> read_request(conn, activity, buffer, 0), |
| 219 | + Error(e) -> Error(e), |
| 220 | + } |
| 221 | + }, |
| 222 | + } |
| 223 | +} |
| 224 | + |
| 225 | +/// Whether the client wants the connection kept open after its request. |
| 226 | +fn keeps_alive(version: Int, headers: List<(String, String)>) -> Bool { |
| 227 | + let connection = option.unwrap_or(find_header(headers, "connection"), "") |
| 228 | + if version == 0 { has_token(connection, "keep-alive") } else { !has_token(connection, "close") } |
| 229 | +} |
| 230 | + |
| 231 | +/// Whether the comma-separated `value` lists `token` (lowercase). |
| 232 | +fn has_token(value: String, token: String) -> Bool { |
| 233 | + list.any(string.split(string.to_lower(value), ","), fn(t) { string.trim(t) == token }) |
| 234 | +} |
| 235 | + |
| 236 | +/// The body that starts at offset `at` of `buffer`, then where the next |
| 237 | +/// request starts. |
| 238 | +fn read_body(conn, activity, headers, length: Int, buffer: Bytes, at: Int) -> Result<(Bytes, Bytes, Int), Failure> / <io, proc> { |
| 239 | + match find_header(headers, "transfer-encoding") { |
| 240 | + Some(coding) -> |
| 241 | + if length >= 0 { |
| 242 | + // Two framings: reading the wrong one would desynchronize the |
| 243 | + // connection (request smuggling). |
| 244 | + Error(Bad(400, "bad request: both Content-Length and Transfer-Encoding")) |
| 245 | + } else if string.to_lower(string.trim(coding)) == "chunked" { |
| 246 | + continue_if_expected(conn, headers, buffer, at) |
| 247 | + read_chunks(conn, activity, buffer, at, bytes.builder()) |
| 248 | + } else { |
| 249 | + Error(Bad(501, "unsupported Transfer-Encoding: " <> coding)) |
| 250 | + }, |
| 251 | + None -> |
| 252 | + if length > 0 { |
| 253 | + continue_if_expected(conn, headers, buffer, at) |
| 254 | + take(conn, activity, buffer, at, length) |
| 118 | 255 | } else { |
| 119 | | − match net.read(conn, 4096) { |
| 120 | | − Ok("") -> Error("connection closed before the request was complete"), |
| 121 | | − Ok(more) -> read_request(conn, buffer <> more), |
| 256 | + Ok((bytes.empty(), buffer, at)) |
| 257 | + }, |
| 258 | + } |
| 259 | +} |
| 260 | + |
| 261 | +/// Tell a client that waits for it (`Expect: 100-continue`) to send the |
| 262 | +/// body. |
| 263 | +fn continue_if_expected(conn, headers, buffer: Bytes, at: Int) -> () / <io> { |
| 264 | + let expect = option.map(find_header(headers, "expect"), string.to_lower) |
| 265 | + if expect == Some("100-continue") && bytes.length(buffer) == at { |
| 266 | + let _ = net.write_string(conn, "HTTP/1.1 100 Continue\r\n\r\n") |
| 267 | + () |
| 268 | + } else { |
| 269 | + () |
| 270 | + } |
| 271 | +} |
| 272 | + |
| 273 | +/// The data of the chunks from offset `at` of `buffer` on, appended to |
| 274 | +/// `body`; then where the next request starts. |
| 275 | +fn read_chunks(conn, activity, buffer: Bytes, at: Int, body: Builder) -> Result<(Bytes, Bytes, Int), Failure> / <io, proc> { |
| 276 | + match parse_chunk(buffer, at) { |
| 277 | + ChunkData(start, size) -> |
| 278 | + match take(conn, activity, buffer, start, size + 2) { |
| 279 | + Ok((data, buffer, at)) -> |
| 280 | + if bytes.slice(data, size, size + 2) == bytes.from_string("\r\n") { |
| 281 | + read_chunks(conn, activity, buffer, at, bytes.append(body, bytes.slice(data, 0, size))) |
| 282 | + } else { |
| 283 | + Error(Bad(400, "bad request: no CRLF after a chunk")) |
| 284 | + }, |
| 285 | + Error(e) -> Error(e), |
| 286 | + }, |
| 287 | + ChunkEnd(end) -> Ok((bytes.build(body), buffer, end)), |
| 288 | + ChunkInvalid(reason) -> Error(Bad(400, "bad request: " <> reason)), |
| 289 | + ChunkPartial -> |
| 290 | + if bytes.length(buffer) - at > 65536 { |
| 291 | + Error(Bad(400, "bad request: chunk header too large")) |
| 292 | + } else { |
| 293 | + match receive_more(conn, activity, buffer, at) { |
| 294 | + Ok(buffer) -> read_chunks(conn, activity, buffer, 0, body), |
| 122 | 295 | Error(e) -> Error(e), |
| 123 | 296 | } |
| 124 | 297 | }, |
| 125 | 298 | } |
| 126 | 299 | } |
| 127 | 300 | |
| 128 | | −fn read_body(conn: Resource<TcpStream>, body: String, length: Int) -> Result<String, String> / <io> { |
| 129 | | − if length < 0 || string.byte_length(body) >= length { |
| 130 | | − Ok(body) |
| 301 | +/// `length` bytes from offset `at` of `buffer`, reading more as needed; |
| 302 | +/// then where what follows them starts. Reads go into a builder, so a |
| 303 | +/// large body is copied a bounded number of times. |
| 304 | +fn take(conn, activity, buffer: Bytes, at: Int, length: Int) -> Result<(Bytes, Bytes, Int), Failure> / <io, proc> { |
| 305 | + let available = bytes.length(buffer) - at |
| 306 | + if available >= length { |
| 307 | + Ok((bytes.slice(buffer, at, at + length), buffer, at + length)) |
| 308 | + } else { |
| 309 | + let rest = bytes.slice(buffer, at, bytes.length(buffer)) |
| 310 | + take_more(conn, activity, bytes.append(bytes.builder(), rest), available, length) |
| 311 | + } |
| 312 | +} |
| 313 | + |
| 314 | +fn take_more(conn, activity, received: Builder, size: Int, length: Int) -> Result<(Bytes, Bytes, Int), Failure> / <io, proc> { |
| 315 | + if size >= length { |
| 316 | + let all = bytes.build(received) |
| 317 | + Ok((bytes.slice(all, 0, length), all, length)) |
| 131 | 318 | } else { |
| 132 | | − match net.read(conn, 65536) { |
| 133 | | − Ok("") -> Error("connection closed in the body"), |
| 134 | | − Ok(more) -> read_body(conn, body <> more, length), |
| 319 | + match read_some(conn, activity) { |
| 320 | + Ok(more) -> take_more(conn, activity, bytes.append(received, more), size + bytes.length(more), length), |
| 135 | 321 | Error(e) -> Error(e), |
| 136 | 322 | } |
| 137 | 323 | } |
| 138 | 324 | } |
| 139 | 325 | |
| 140 | | −pub type Head { |
| 326 | +/// The unread part of `buffer` (from offset `at`), then what arrives next. |
| 327 | +fn receive_more(conn, activity, buffer: Bytes, at: Int) -> Result<Bytes, Failure> / <io, proc> { |
| 328 | + match read_some(conn, activity) { |
| 329 | + Ok(more) -> Ok(bytes.concat(bytes.slice(buffer, at, bytes.length(buffer)), more)), |
| 330 | + Error(e) -> Error(e), |
| 331 | + } |
| 332 | +} |
| 333 | + |
| 334 | +/// The next bytes from the connection (timed by the watchdog). |
| 335 | +fn read_some(conn: Resource<TcpStream>, activity: Subject<Activity>) -> Result<Bytes, Failure> / <io, proc> { |
| 336 | + process.send(activity, Reading) |
| 337 | + match net.read(conn, 65536) { |
| 338 | + Ok(more) -> if bytes.length(more) == 0 { Error(Closed) } else { Ok(more) }, |
| 339 | + Error(_) -> Error(Closed), |
| 340 | + } |
| 341 | +} |
| 342 | + |
| 343 | +type Head { |
| 141 | 344 | Partial |
| 142 | 345 | Invalid(reason: String) |
| 143 | | − Complete(method: String, path: String, headers: List<(String, String)>, rest: String, content_length: Int) |
| 346 | + /// The head ends at offset `end`; `content_length` is -1 when absent. |
| 347 | + Complete(method: String, path: String, version: Int, headers: List<(String, String)>, end: Int, content_length: Int) |
| 144 | 348 | } |
| 145 | 349 | |
| 146 | 350 | @extern(c, "tl_http_parse_request") |
| 147 | | −fn parse_head(buffer: String) -> Head |
| 351 | +fn parse_head(buffer: Bytes, at: Int) -> Head |
| 352 | + |
| 353 | +type Chunk { |
| 354 | + ChunkPartial |
| 355 | + ChunkInvalid(reason: String) |
| 356 | + /// `size` bytes of data from offset `start`, then CRLF. |
| 357 | + ChunkData(start: Int, size: Int) |
| 358 | + /// The last chunk and its trailers end at offset `end`. |
| 359 | + ChunkEnd(end: Int) |
| 360 | +} |
| 361 | + |
| 362 | +@extern(c, "tl_http_parse_chunk") |
| 363 | +fn parse_chunk(buffer: Bytes, at: Int) -> Chunk |
| 364 | + |
| 365 | +/// The head and (unless `with_body` is false, for HEAD requests) the body, |
| 366 | +/// in one buffer so they leave in one write. |
| 367 | +fn serialize(resp: Response, keep_alive: Bool, with_body: Bool) -> Bytes { |
| 368 | + let own = list.filter(resp.headers, fn(h) { !is_framing(string.to_lower(h.0)) }) |
| 369 | + let head = string.concat([ |
| 370 | + "HTTP/1.1 ", |
| 371 | + show(resp.status), |
| 372 | + " ", |
| 373 | + reason(resp.status), |
| 374 | + "\r\n", |
| 375 | + string.concat(list.map(own, fn(h) { h.0 <> ": " <> h.1 <> "\r\n" })), |
| 376 | + "Content-Length: ", |
| 377 | + show(bytes.length(resp.body)), |
| 378 | + if keep_alive { "\r\nConnection: keep-alive\r\n\r\n" } else { "\r\nConnection: close\r\n\r\n" }, |
| 379 | + ]) |
| 380 | + let out = bytes.append_string(bytes.builder(), head) |
| 381 | + bytes.build(if with_body { bytes.append(out, resp.body) } else { out }) |
| 382 | +} |
| 148 | 383 | |
| 149 | | −fn serialize(resp: Response) -> String { |
| 150 | | − let head = { |
| 151 | | − use acc, h <- list.fold(resp.headers, "HTTP/1.1 " <> show(resp.status) <> " " <> reason(resp.status) <> "\r\n") |
| 152 | | − let (name, value) = h |
| 153 | | − acc <> name <> ": " <> value <> "\r\n" |
| 384 | +/// Headers the server sets itself. |
| 385 | +fn is_framing(name: String) -> Bool { |
| 386 | + match name { |
| 387 | + "content-length" | "connection" | "transfer-encoding" -> True, |
| 388 | + _ -> False, |
| 154 | 389 | } |
| 155 | | − head <> "Content-Length: " <> show(string.byte_length(resp.body)) <> "\r\nConnection: close\r\n\r\n" <> resp.body |
| 156 | 390 | } |
| 157 | 391 | |
| 158 | 392 | fn reason(status) { |
| @@ -169,7 +403,9 @@ fn reason(status) { |
| 169 | 403 | 403 -> "Forbidden", |
| 170 | 404 | 404 -> "Not Found", |
| 171 | 405 | 405 -> "Method Not Allowed", |
| 406 | + 431 -> "Request Header Fields Too Large", |
| 172 | 407 | 500 -> "Internal Server Error", |
| 408 | + 501 -> "Not Implemented", |
| 173 | 409 | _ -> "Status", |
| 174 | 410 | } |
| 175 | 411 | } |