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

vweb: add host option to controller (#18303)

This commit is contained in:
Casper Kuethe
2023-05-30 14:22:23 +02:00
committed by GitHub
parent 05b832a317
commit 4174048f96
6 changed files with 92 additions and 7 deletions

View File

@@ -137,9 +137,9 @@ fn test_duplicate_route() {
$if windows {
task := spawn os.execute(server_exec_cmd)
res := task.wait()
assert res.output.contains('V panic: method "duplicate" with route "/admin/duplicate" should be handled by the Controller of "/admin"')
assert res.output.contains('V panic: conflicting paths')
} $else {
res := os.execute(server_exec_cmd)
assert res.output.contains('V panic: method "duplicate" with route "/admin/duplicate" should be handled by the Controller of "/admin"')
assert res.output.contains('V panic: conflicting paths')
}
}

View File

@@ -238,6 +238,20 @@ fn test_http_client_multipart_form_data() {
assert x.body == files[0].data
}
fn test_host() {
mut req := http.Request{
url: 'http://${localserver}/with_host'
method: .get
}
mut x := req.do()!
assert x.status() == .not_found
req.add_header(.host, 'example.com')
x = req.do()!
assert x.status() == .ok
}
fn test_http_client_shutdown_does_not_work_without_a_cookie() {
x := http.get('http://${localserver}/shutdown') or {
assert err.msg() == ''

View File

@@ -119,6 +119,12 @@ pub fn (mut app App) not_found() vweb.Result {
return app.html('404 on "${app.req.url}"')
}
[host: 'example.com']
['/with_host']
pub fn (mut app App) with_host() vweb.Result {
return app.ok('')
}
pub fn (mut app App) shutdown() vweb.Result {
session_key := app.get_cookie('skey') or { return app.not_found() }
if session_key != 'superman' {