| 1 | module veb |
| 2 | |
| 3 | import net.http |
| 4 | |
| 5 | // max read and write limits in bytes |
| 6 | const max_read = int($d('veb_max_read_bytes', 8192)) |
| 7 | const max_write = int($d('veb_max_write_bytes', 2048)) |
| 8 | |
| 9 | pub const max_http_post_size = $d('veb_max_http_post_size_bytes', 1048576) |
| 10 | pub const default_port = int($d('veb_default_port', 8080)) |
| 11 | pub const methods_with_form = [http.Method.post, .put, .patch] |
| 12 | |
| 13 | pub const headers_close = http.new_custom_header_from_map({ |
| 14 | 'Server': 'veb' |
| 15 | })! |
| 16 | |
| 17 | pub const http_302 = http.new_response( |
| 18 | status: .found |
| 19 | body: '302 Found' |
| 20 | header: headers_close |
| 21 | ) |
| 22 | |
| 23 | pub const http_400 = http.new_response( |
| 24 | status: .bad_request |
| 25 | body: '400 Bad Request' |
| 26 | header: http.new_header( |
| 27 | key: .content_type |
| 28 | value: 'text/plain' |
| 29 | ).join(headers_close) |
| 30 | ) |
| 31 | |
| 32 | pub const http_404 = http.new_response( |
| 33 | status: .not_found |
| 34 | body: '404 Not Found' |
| 35 | header: http.new_header( |
| 36 | key: .content_type |
| 37 | value: 'text/plain' |
| 38 | ).join(headers_close) |
| 39 | ) |
| 40 | |
| 41 | pub const http_408 = http.new_response( |
| 42 | status: .request_timeout |
| 43 | body: '408 Request Timeout' |
| 44 | header: http.new_header( |
| 45 | key: .content_type |
| 46 | value: 'text/plain' |
| 47 | ).join(headers_close) |
| 48 | ) |
| 49 | |
| 50 | pub const http_413 = http.new_response( |
| 51 | status: .request_entity_too_large |
| 52 | body: '413 Request entity is too large' |
| 53 | header: http.new_header( |
| 54 | key: .content_type |
| 55 | value: 'text/plain' |
| 56 | ).join(headers_close) |
| 57 | ) |
| 58 | |
| 59 | pub const http_500 = http.new_response( |
| 60 | status: .internal_server_error |
| 61 | body: '500 Internal Server Error' |
| 62 | header: http.new_header( |
| 63 | key: .content_type |
| 64 | value: 'text/plain' |
| 65 | ).join(headers_close) |
| 66 | ) |
| 67 | |
| 68 | pub const mime_types = { |
| 69 | '.aac': 'audio/aac' |
| 70 | '.abw': 'application/x-abiword' |
| 71 | '.arc': 'application/x-freearc' |
| 72 | '.avi': 'video/x-msvideo' |
| 73 | '.azw': 'application/vnd.amazon.ebook' |
| 74 | '.bin': 'application/octet-stream' |
| 75 | '.bmp': 'image/bmp' |
| 76 | '.bz': 'application/x-bzip' |
| 77 | '.bz2': 'application/x-bzip2' |
| 78 | '.cda': 'application/x-cdf' |
| 79 | '.csh': 'application/x-csh' |
| 80 | '.css': 'text/css' |
| 81 | '.csv': 'text/csv' |
| 82 | '.doc': 'application/msword' |
| 83 | '.docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' |
| 84 | '.eot': 'application/vnd.ms-fontobject' |
| 85 | '.epub': 'application/epub+zip' |
| 86 | '.gz': 'application/gzip' |
| 87 | '.gif': 'image/gif' |
| 88 | '.htm': 'text/html' |
| 89 | '.html': 'text/html' |
| 90 | '.ico': 'image/vnd.microsoft.icon' |
| 91 | '.ics': 'text/calendar' |
| 92 | '.jar': 'application/java-archive' |
| 93 | '.jpeg': 'image/jpeg' |
| 94 | '.jpg': 'image/jpeg' |
| 95 | '.js': 'text/javascript' |
| 96 | '.json': 'application/json' |
| 97 | '.jsonld': 'application/ld+json' |
| 98 | '.md': 'text/markdown' |
| 99 | '.mid': 'audio/midi audio/x-midi' |
| 100 | '.midi': 'audio/midi audio/x-midi' |
| 101 | '.mjs': 'text/javascript' |
| 102 | '.mp3': 'audio/mpeg' |
| 103 | '.mp4': 'video/mp4' |
| 104 | '.mpeg': 'video/mpeg' |
| 105 | '.mpkg': 'application/vnd.apple.installer+xml' |
| 106 | '.odp': 'application/vnd.oasis.opendocument.presentation' |
| 107 | '.ods': 'application/vnd.oasis.opendocument.spreadsheet' |
| 108 | '.odt': 'application/vnd.oasis.opendocument.text' |
| 109 | '.oga': 'audio/ogg' |
| 110 | '.ogv': 'video/ogg' |
| 111 | '.ogx': 'application/ogg' |
| 112 | '.opus': 'audio/opus' |
| 113 | '.otf': 'font/otf' |
| 114 | '.png': 'image/png' |
| 115 | '.pdf': 'application/pdf' |
| 116 | '.php': 'application/x-httpd-php' |
| 117 | '.ppt': 'application/vnd.ms-powerpoint' |
| 118 | '.pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation' |
| 119 | '.rar': 'application/vnd.rar' |
| 120 | '.rtf': 'application/rtf' |
| 121 | '.scss': 'text/css' |
| 122 | '.sh': 'application/x-sh' |
| 123 | '.svg': 'image/svg+xml' |
| 124 | '.swf': 'application/x-shockwave-flash' |
| 125 | '.tar': 'application/x-tar' |
| 126 | '.tif': 'image/tiff' |
| 127 | '.tiff': 'image/tiff' |
| 128 | '.ts': 'video/mp2t' |
| 129 | '.ttf': 'font/ttf' |
| 130 | '.txt': 'text/plain' |
| 131 | '.vsd': 'application/vnd.visio' |
| 132 | '.wasm': 'application/wasm' |
| 133 | '.wav': 'audio/wav' |
| 134 | '.weba': 'audio/webm' |
| 135 | '.webm': 'video/webm' |
| 136 | '.webp': 'image/webp' |
| 137 | '.woff': 'font/woff' |
| 138 | '.woff2': 'font/woff2' |
| 139 | '.xhtml': 'application/xhtml+xml' |
| 140 | '.xls': 'application/vnd.ms-excel' |
| 141 | '.xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' |
| 142 | '.xml': 'application/xml' |
| 143 | '.xul': 'application/vnd.mozilla.xul+xml' |
| 144 | '.zip': 'application/zip' |
| 145 | '.zst': 'application/zstd' |
| 146 | '.3gp': 'video/3gpp' |
| 147 | '.3g2': 'video/3gpp2' |
| 148 | '.7z': 'application/x-7z-compressed' |
| 149 | '.m3u8': 'application/vnd.apple.mpegurl' |
| 150 | '.vsh': 'text/x-vlang' |
| 151 | '.v': 'text/x-vlang' |
| 152 | } |
| 153 | |