1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

examples: fix 404 status code for not found pages in examples/http_server.v

This commit is contained in:
Delyan Angelov 2021-08-31 12:13:58 +03:00
parent 37b4553f52
commit e72af5e2ee
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED

View File

@ -10,13 +10,23 @@ fn (h ExampleHandler) handle(req Request) Response {
CommonHeader.content_type: 'text/plain'
})
}
mut status_code := 200
res.text = match req.url {
'/foo' { 'bar\n' }
'/hello' { 'world\n' }
'/' { 'foo\nhello\n' }
else { 'Not found\n' }
'/foo' {
'bar\n'
}
res.status_code = if res.text == 'Not found' { 404 } else { 200 }
'/hello' {
'world\n'
}
'/' {
'foo\nhello\n'
}
else {
status_code = 404
'Not found\n'
}
}
res.status_code = status_code
return res
}