vweb: make mime_types a const

pull/1593/head
Alexander Medvednikov 2019-08-12 21:56:47 +03:00
parent bc563930f7
commit a11961b0d3
3 changed files with 18 additions and 17 deletions

View File

@ -0,0 +1 @@
test <b>app</b>

View File

@ -35,14 +35,14 @@ _ := header
//footer := \'footer\' //footer := \'footer\'
') ')
s.writeln(STR_START) s.writeln(STR_START)
mut in_css := false mut in_css :=true// false
for _line in lines { for _line in lines {
line := _line.trim_space() line := _line.trim_space()
if line == '<style>' { if line == '<style>' {
in_css = true in_css = true
} }
else if line == '</style>' { else if line == '</style>' {
in_css = false //in_css = false
} }
if line.contains('@if ') { if line.contains('@if ') {
s.writeln(STR_END) s.writeln(STR_END)

View File

@ -181,24 +181,24 @@ fn (ctx mut Context) parse_form(s string) {
} }
} }
} }
const (
mime_types = {
'.css': 'text/css; charset=utf-8',
'.gif': 'image/gif',
'.htm': 'text/html; charset=utf-8',
'.html': 'text/html; charset=utf-8',
'.jpg': 'image/jpeg',
'.js': 'application/javascript',
'.wasm': 'application/wasm',
'.pdf': 'application/pdf',
'.png': 'image/png',
'.svg': 'image/svg+xml',
'.xml': 'text/xml; charset=utf-8'
}
)
fn (ctx mut Context) scan_static_directory(directory_path, mount_path string) { fn (ctx mut Context) scan_static_directory(directory_path, mount_path string) {
// mime types
mut mime_types := map[string]string{}
mime_types['.css'] = 'text/css; charset=utf-8'
mime_types['.gif'] = 'image/gif'
mime_types['.htm'] = 'text/html; charset=utf-8'
mime_types['.html'] = 'text/html; charset=utf-8'
mime_types['.jpg'] = 'image/jpeg'
mime_types['.js'] = 'application/javascript'
mime_types['.wasm'] = 'application/wasm'
mime_types['.pdf'] = 'application/pdf'
mime_types['.png'] = 'image/png'
mime_types['.svg'] = 'image/svg+xml'
mime_types['.xml'] = 'text/xml; charset=utf-8'
files := os.ls(directory_path) files := os.ls(directory_path)
if files.len > 0 { if files.len > 0 {
for file in files { for file in files {
mut ext := '' mut ext := ''