Skip to content

Commit d89e6df

Browse files
authored
veb: extract constants into consts.v (#22132)
1 parent 01fd719 commit d89e6df

File tree

2 files changed

+173
-170
lines changed

2 files changed

+173
-170
lines changed

vlib/veb/consts.v

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
module veb
2+
3+
import net.http
4+
5+
// max read and write limits in bytes
6+
const max_read = 8096
7+
const max_write = 8096 * 2
8+
9+
pub const max_http_post_size = 1024 * 1024
10+
pub const 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+
}) or { panic('should never fail') }
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+
'.mid': 'audio/midi audio/x-midi'
99+
'.midi': 'audio/midi audio/x-midi'
100+
'.mjs': 'text/javascript'
101+
'.mp3': 'audio/mpeg'
102+
'.mp4': 'video/mp4'
103+
'.mpeg': 'video/mpeg'
104+
'.mpkg': 'application/vnd.apple.installer+xml'
105+
'.odp': 'application/vnd.oasis.opendocument.presentation'
106+
'.ods': 'application/vnd.oasis.opendocument.spreadsheet'
107+
'.odt': 'application/vnd.oasis.opendocument.text'
108+
'.oga': 'audio/ogg'
109+
'.ogv': 'video/ogg'
110+
'.ogx': 'application/ogg'
111+
'.opus': 'audio/opus'
112+
'.otf': 'font/otf'
113+
'.png': 'image/png'
114+
'.pdf': 'application/pdf'
115+
'.php': 'application/x-httpd-php'
116+
'.ppt': 'application/vnd.ms-powerpoint'
117+
'.pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation'
118+
'.rar': 'application/vnd.rar'
119+
'.rtf': 'application/rtf'
120+
'.sh': 'application/x-sh'
121+
'.svg': 'image/svg+xml'
122+
'.swf': 'application/x-shockwave-flash'
123+
'.tar': 'application/x-tar'
124+
'.tif': 'image/tiff'
125+
'.tiff': 'image/tiff'
126+
'.ts': 'video/mp2t'
127+
'.ttf': 'font/ttf'
128+
'.txt': 'text/plain'
129+
'.vsd': 'application/vnd.visio'
130+
'.wasm': 'application/wasm'
131+
'.wav': 'audio/wav'
132+
'.weba': 'audio/webm'
133+
'.webm': 'video/webm'
134+
'.webp': 'image/webp'
135+
'.woff': 'font/woff'
136+
'.woff2': 'font/woff2'
137+
'.xhtml': 'application/xhtml+xml'
138+
'.xls': 'application/vnd.ms-excel'
139+
'.xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
140+
'.xml': 'application/xml'
141+
'.xul': 'application/vnd.mozilla.xul+xml'
142+
'.zip': 'application/zip'
143+
'.3gp': 'video/3gpp'
144+
'.3g2': 'video/3gpp2'
145+
'.7z': 'application/x-7z-compressed'
146+
'.m3u8': 'application/vnd.apple.mpegurl'
147+
'.vsh': 'text/x-vlang'
148+
'.v': 'text/x-vlang'
149+
}

0 commit comments

Comments
 (0)