Skip to content

Commit 2902933

Browse files
committed
veb: static handler fix
1 parent 154812e commit 2902933

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

vlib/veb/tests/static_handler_test.v

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// vtest vflags: -prod
12
import veb
23
import net.http
34
import os
@@ -19,6 +20,7 @@ pub fn (mut app App) before_accept_loop() {
1920
app.started <- true
2021
}
2122

23+
@['/']
2224
pub fn (mut app App) index(mut ctx Context) veb.Result {
2325
return ctx.text('Hello V!')
2426
}
@@ -95,6 +97,13 @@ fn test_static_root() {
9597
assert x.body == 'root'
9698
}
9799

100+
fn test_route_attribute_root_with_static_handler() {
101+
x := http.get('${localserver}/')!
102+
103+
assert x.status() == .ok
104+
assert x.body == 'Hello V!'
105+
}
106+
98107
fn test_redirect_to_static_root() {
99108
x := http.get('${localserver}/redirect_root')!
100109

vlib/veb/veb.v

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,10 +678,9 @@ fn route_matches(url_words []string, route_words []string) ?[]string {
678678

679679
// check if request is for a static file and serves it
680680
// returns true if we served a static file, false otherwise
681-
@[manualfree]
682681
fn serve_if_static[X](app StaticHandler, mut user_context X, url urllib.URL, host string) bool {
683682
// TODO: handle url parameters properly - for now, ignore them
684-
mut asked_path := url.path
683+
mut asked_path := url.path.clone()
685684
static_handler := app
686685

687686
// Content negotiation for markdown files (if enabled)

0 commit comments

Comments
 (0)