Skip to content

Commit 184883b

Browse files
committed
veb: use fasthttp by default
1 parent a7912e4 commit 184883b

14 files changed

Lines changed: 106 additions & 1468 deletions

vlib/fasthttp/request_parser.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module fasthttp
22

33
const empty_space = u8(` `)
4-
const cr_char = u8(`\r`)
5-
const lf_char = u8(`\n`)
4+
const cr_char = u8(0x0d)
5+
const lf_char = u8(0x0a)
66

77
// libc memchr is AVX2-accelerated via glibc IFUNC
88
@[inline]

vlib/veb/chunked_request_body_test.v

Lines changed: 0 additions & 33 deletions
This file was deleted.

vlib/veb/context.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ pub fn (mut ctx Context) takeover_conn() {
514514
write_timeout: 30 * time.second
515515
}
516516
} else if ctx.conn != unsafe { nil } {
517-
// For the picoev backend: the connection exists but uses non-blocking I/O.
517+
// The connection exists but uses non-blocking I/O.
518518
// Switch to blocking mode for reliable SSE writes.
519519
fd := ctx.conn.handle
520520
$if !windows {

vlib/veb/controller_static_regression_test.v

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
module veb
22

3-
import net
43
import net.http
54
import net.urllib
65
import os
@@ -104,25 +103,12 @@ fn regression_handle_app_request(mut app AppStaticRegressionApp, req http.Reques
104103
panic(err)
105104
}
106105

107-
$if new_veb ? {
108-
params := RequestParams{
109-
global_app: unsafe { voidptr(&app) }
110-
controllers_sorted: controllers_sorted
111-
routes: &routes
112-
benchmark_page_generation: false
113-
}
114-
return handle_request_and_route[AppStaticRegressionApp, RegressionContext](mut app, req, 0,
115-
params)
116-
} $else {
117-
params := &RequestParams{
118-
global_app: unsafe { voidptr(&app) }
119-
controllers: controllers_sorted
120-
routes: &routes
121-
timeout_in_seconds: 2
122-
}
123-
mut conn := net.TcpConn{}
124-
return handle_request[AppStaticRegressionApp, RegressionContext](mut conn, req, params) or {
125-
panic(err)
126-
}
106+
params := RequestParams{
107+
global_app: unsafe { voidptr(&app) }
108+
controllers_sorted: controllers_sorted
109+
routes: &routes
110+
benchmark_page_generation: false
127111
}
112+
return handle_request_and_route[AppStaticRegressionApp, RegressionContext](mut app, req, 0,
113+
params)
128114
}

vlib/veb/server_d_new_veb.v

Lines changed: 0 additions & 44 deletions
This file was deleted.

vlib/veb/server_notd_new_veb.v

Lines changed: 0 additions & 20 deletions
This file was deleted.

vlib/veb/sse/sse.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub mut:
3838
// start an SSE connection
3939
pub fn start_connection(mut ctx veb.Context) &SSEConnection {
4040
if ctx.conn == unsafe { nil } {
41-
eprintln('[veb.sse] WARNING: SSE requires a direct TCP connection (ctx.conn) which is not available with this server backend. Use the default (picoev) backend instead of `-d new_veb` for SSE support.')
41+
eprintln('[veb.sse] WARNING: SSE requires a direct TCP connection (ctx.conn) which is not available. Use `ctx.takeover_conn()` before starting an SSE connection.')
4242
return &SSEConnection{
4343
conn: unsafe { nil }
4444
}
Lines changed: 91 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,116 @@
1-
// vfmt off
2-
fn test_stub() {
3-
$if !new_veb ? {
4-
return
5-
}
6-
}
1+
import net
2+
import net.http
3+
import time
4+
import veb
75

8-
$if new_veb ? {
9-
import net
10-
import net.http
11-
import time
12-
import veb
6+
const graceful_shutdown_host = '127.0.0.1'
137

14-
const graceful_shutdown_host = '127.0.0.1'
15-
16-
struct GracefulShutdownContext {
17-
veb.Context
18-
}
8+
struct GracefulShutdownContext {
9+
veb.Context
10+
}
1911

20-
struct GracefulShutdownApp {
21-
mut:
22-
server &veb.Server = unsafe { nil }
23-
slow_started chan bool = chan bool{cap: 1}
24-
}
12+
struct GracefulShutdownApp {
13+
mut:
14+
server &veb.Server = unsafe { nil }
15+
slow_started chan bool = chan bool{cap: 1}
16+
}
2517

26-
pub fn (mut app GracefulShutdownApp) init_server(server &veb.Server) {
27-
app.server = server
28-
}
18+
pub fn (mut app GracefulShutdownApp) init_server(server &veb.Server) {
19+
app.server = server
20+
}
2921

30-
pub fn (mut app GracefulShutdownApp) index(mut ctx GracefulShutdownContext) veb.Result {
31-
return ctx.text('ready')
32-
}
22+
pub fn (mut app GracefulShutdownApp) index(mut ctx GracefulShutdownContext) veb.Result {
23+
return ctx.text('ready')
24+
}
3325

34-
@['/slow']
35-
pub fn (mut app GracefulShutdownApp) slow(mut ctx GracefulShutdownContext) veb.Result {
36-
app.slow_started <- true
37-
time.sleep(300 * time.millisecond)
38-
return ctx.text('slow done')
39-
}
26+
@['/slow']
27+
pub fn (mut app GracefulShutdownApp) slow(mut ctx GracefulShutdownContext) veb.Result {
28+
app.slow_started <- true
29+
time.sleep(300 * time.millisecond)
30+
return ctx.text('slow done')
31+
}
4032

41-
pub fn (mut app GracefulShutdownApp) shutdown(mut ctx GracefulShutdownContext) veb.Result {
42-
spawn app.shutdown_now()
43-
return ctx.text('shutting down')
44-
}
33+
pub fn (mut app GracefulShutdownApp) shutdown(mut ctx GracefulShutdownContext) veb.Result {
34+
spawn app.shutdown_now()
35+
return ctx.text('shutting down')
36+
}
4537

46-
fn (app &GracefulShutdownApp) shutdown_now() {
47-
mut server := app.server
48-
if server == unsafe { nil } {
49-
panic('veb server was not initialized')
50-
}
51-
server.shutdown() or { panic(err) }
38+
fn (app &GracefulShutdownApp) shutdown_now() {
39+
mut server := app.server
40+
if server == unsafe { nil } {
41+
panic('veb server was not initialized')
5242
}
43+
server.shutdown() or { panic(err) }
44+
}
5345

54-
fn run_graceful_shutdown_app(mut app GracefulShutdownApp, port int) {
55-
veb.run_at[GracefulShutdownApp, GracefulShutdownContext](mut app,
56-
host: graceful_shutdown_host
57-
port: port
58-
family: .ip
59-
show_startup_message: false
60-
) or { panic(err) }
61-
}
46+
fn run_graceful_shutdown_app(mut app GracefulShutdownApp, port int) {
47+
veb.run_at[GracefulShutdownApp, GracefulShutdownContext](mut app,
48+
host: graceful_shutdown_host
49+
port: port
50+
family: .ip
51+
show_startup_message: false
52+
) or { panic(err) }
53+
}
6254

63-
fn send_slow_request(port int, responses chan http.Response) {
64-
response := http.get('http://${graceful_shutdown_host}:${port}/slow') or { panic(err) }
65-
responses <- response
66-
}
55+
fn send_slow_request(port int, responses chan http.Response) {
56+
response := http.get('http://${graceful_shutdown_host}:${port}/slow') or { panic(err) }
57+
responses <- response
58+
}
6759

68-
fn wait_for_server(port int) ! {
69-
url := 'http://${graceful_shutdown_host}:${port}/'
70-
for _ in 0 .. 100 {
71-
response := http.get(url) or {
72-
time.sleep(20 * time.millisecond)
73-
continue
74-
}
75-
if response.status() == .ok && response.body == 'ready' {
76-
return
77-
}
60+
fn wait_for_server(port int) ! {
61+
url := 'http://${graceful_shutdown_host}:${port}/'
62+
for _ in 0 .. 100 {
63+
response := http.get(url) or {
7864
time.sleep(20 * time.millisecond)
65+
continue
7966
}
80-
return error('server did not start listening in time')
67+
if response.status() == .ok && response.body == 'ready' {
68+
return
69+
}
70+
time.sleep(20 * time.millisecond)
8171
}
72+
return error('server did not start listening in time')
73+
}
8274

83-
fn test_veb_graceful_shutdown_waits_for_in_flight_requests() {
84-
mut listener := net.listen_tcp(.ip, '${graceful_shutdown_host}:0') or { panic(err) }
85-
port := listener.addr()!.port()!
86-
listener.close() or {}
75+
fn test_veb_graceful_shutdown_waits_for_in_flight_requests() {
76+
mut listener := net.listen_tcp(.ip, '${graceful_shutdown_host}:0') or { panic(err) }
77+
port := listener.addr()!.port()!
78+
listener.close() or {}
8779

88-
mut app := &GracefulShutdownApp{}
89-
server_thread := spawn run_graceful_shutdown_app(mut app, int(port))
80+
mut app := &GracefulShutdownApp{}
81+
server_thread := spawn run_graceful_shutdown_app(mut app, int(port))
9082

91-
wait_for_server(int(port)) or {
92-
assert false, err.msg()
93-
return
94-
}
83+
wait_for_server(int(port)) or {
84+
assert false, err.msg()
85+
return
86+
}
9587

96-
slow_responses := chan http.Response{cap: 1}
97-
spawn send_slow_request(int(port), slow_responses)
98-
_ := <-app.slow_started or {
99-
assert false, 'slow request did not start'
100-
return
101-
}
88+
slow_responses := chan http.Response{cap: 1}
89+
spawn send_slow_request(int(port), slow_responses)
90+
_ := <-app.slow_started or {
91+
assert false, 'slow request did not start'
92+
return
93+
}
10294

103-
shutdown_response := http.get('http://${graceful_shutdown_host}:${port}/shutdown') or {
104-
assert false, err.msg()
105-
return
106-
}
107-
assert shutdown_response.status() == .ok
108-
assert shutdown_response.body == 'shutting down'
95+
shutdown_response := http.get('http://${graceful_shutdown_host}:${port}/shutdown') or {
96+
assert false, err.msg()
97+
return
98+
}
99+
assert shutdown_response.status() == .ok
100+
assert shutdown_response.body == 'shutting down'
109101

110-
slow_response := <-slow_responses or {
111-
assert false, err.msg()
112-
return
113-
}
114-
assert slow_response.status() == .ok
115-
assert slow_response.body == 'slow done'
102+
slow_response := <-slow_responses or {
103+
assert false, err.msg()
104+
return
105+
}
106+
assert slow_response.status() == .ok
107+
assert slow_response.body == 'slow done'
116108

117-
server_thread.wait()
109+
server_thread.wait()
118110

119-
http.get('http://${graceful_shutdown_host}:${port}/') or {
120-
assert true
121-
return
122-
}
123-
assert false, 'server still accepts new requests after shutdown'
111+
http.get('http://${graceful_shutdown_host}:${port}/') or {
112+
assert true
113+
return
124114
}
115+
assert false, 'server still accepts new requests after shutdown'
125116
}

vlib/veb/tests/large_payload_test.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fn testsuite_begin() {
5353

5454
fn test_large_request_body() {
5555
// string of a's of 8.96mb send over the connection
56-
// veb reads a maximum of 4096KB per picoev loop cycle
56+
// veb reads a maximum of 4096KB per read cycle
5757
// this test tests if veb is able to do multiple of these
5858
// cycles and updates the response body each cycle
5959
mut buf := []u8{len: veb.max_read * 10, init: `a`}

0 commit comments

Comments
 (0)