╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ serve_http.zig ───────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
239 } 240 241 fn normalizeMethod(method: std.http.Method) std.http.Method { 242 return if (method == .HEAD) .GET else method; 243 } 244 245 fn findHeader(request: *std.http.Server.Request, name: []const u8) ?[]const u8 { 246 var it = request.iterateHeaders(); 247 while (it.next()) |header| { 248 if (std.ascii.eqlIgnoreCase(header.name, name)) return header.value; 249 } 250 return null; 251 } 252 253 fn writeSimpleResponse( 254 http_server: *std.http.Server, 255 code: u16, 256 message: []const u8, 257 content_type: []const u8, 258 body: []const u8, 259 ) !void { 260 try http_server.out.print( 261 "HTTP/1.1 {d} {s}\r\nContent-Type: {s}\r\nContent-Length: {d}\r\n\r\n{s}", 262 .{ code, message, content_type, body.len, body }, 263 ); 264 } 265