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:
@@ -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')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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() == ''
|
||||
|
||||
@@ -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' {
|
||||
|
||||
Reference in New Issue
Block a user