@@ -7,10 +7,6 @@ const pool = @import("pool.zig");
7
7
8
8
const endpoints = @import ("endpoints.zig" );
9
9
10
- const RndGen = std .rand .DefaultPrng ;
11
- const Allocator = std .mem .Allocator ;
12
- const Pool = pg .Pool ;
13
-
14
10
var server : httpz .ServerCtx (* endpoints.Global , * endpoints .Global ) = undefined ;
15
11
16
12
pub fn main () ! void {
@@ -26,28 +22,16 @@ pub fn main() !void {
26
22
27
23
var prng = std .rand .DefaultPrng .init (@as (u64 , @bitCast (std .time .milliTimestamp ())));
28
24
25
+ var rand = prng .random ();
26
+
29
27
var global = endpoints.Global {
30
28
.pool = pg_pool ,
31
- .prng = & prng ,
29
+ .rand = & rand ,
32
30
};
33
31
34
- var httpz_port : []u8 = undefined ;
35
- var arg_string = try std .fmt .allocPrint (allocator , "{s}" , .{"0" });
36
- defer allocator .free (arg_string );
37
-
38
- var args = try std .process .argsWithAllocator (allocator );
39
- defer args .deinit ();
40
- while (args .next ()) | arg | {
41
- arg_string = try std .fmt .allocPrint (allocator , "{s}" , .{arg });
32
+ const args = try std .process .argsAlloc (allocator );
42
33
43
- httpz_port = arg_string ; // use arg
44
- }
45
-
46
- var port = try std .fmt .parseInt (u16 ,httpz_port , 0 );
47
-
48
- if (port == 0 ) {
49
- port = 3000 ;
50
- }
34
+ const port : u16 = if (args .len > 1 ) try std .fmt .parseInt (u16 , args [1 ], 0 ) else 3000 ;
51
35
52
36
const workers = @as (u16 , @intCast (16 * cpu_count ));
53
37
@@ -100,7 +84,7 @@ pub fn main() !void {
100
84
.buffer_size = 8192 ,
101
85
},
102
86
.request = .{
103
- // Maximum request body size that we'll process. We can allocate up
87
+ // Maximum request body size that we'll process. We can allocate up
104
88
// to this much memory per request for the body. Internally, we might
105
89
// keep this memory around for a number of requests as an optimization.
106
90
.max_body_size = 1_048_576 ,
@@ -109,17 +93,17 @@ pub fn main() !void {
109
93
// this space, else the request will be rejected.
110
94
.buffer_size = 4_096 ,
111
95
112
- // Maximum number of headers to accept.
96
+ // Maximum number of headers to accept.
113
97
// Additional headers will be silently ignored.
114
98
.max_header_count = 32 ,
115
99
116
100
// Maximum number of URL parameters to accept.
117
101
// Additional parameters will be silently ignored.
118
- .max_param_count = 10 ,
102
+ .max_param_count = 0 ,
119
103
120
104
// Maximum number of query string parameters to accept.
121
105
// Additional parameters will be silently ignored.
122
- .max_query_count = 32 ,
106
+ .max_query_count = 0 ,
123
107
124
108
// Maximum number of x-www-form-urlencoded fields to support.
125
109
// Additional parameters will be silently ignored. This must be
@@ -132,7 +116,7 @@ pub fn main() !void {
132
116
// set to a value greater than 0 (the default) if you're going
133
117
// to use the req.multiFormData() method.
134
118
.max_multiform_count = 0 ,
135
- },
119
+ },
136
120
}, & global );
137
121
defer server .deinit ();
138
122
0 commit comments