@@ -22,6 +22,7 @@ const Allocator = std.mem.Allocator;
2222
2323const jsruntime = @import ("jsruntime" );
2424
25+ const App = @import ("app.zig" ).App ;
2526const Browser = @import ("browser/browser.zig" ).Browser ;
2627const server = @import ("server.zig" );
2728
@@ -69,9 +70,12 @@ pub fn main() !void {
6970 log .err ("address (host:port) {any}\n " , .{err });
7071 return args .printUsageAndExit (false );
7172 };
72-
73- var app = try @import ("app.zig" ).App .init (alloc , .serve );
73+ var app = try App .init (alloc , .{
74+ .run_mode = args .mode ,
75+ .tls_verify_host = opts .tls_verify_host ,
76+ });
7477 defer app .deinit ();
78+
7579 app .telemetry .record (.{ .run = {} });
7680
7781 const timeout = std .time .ns_per_s * @as (u64 , opts .timeout );
@@ -83,7 +87,10 @@ pub fn main() !void {
8387 .fetch = > | opts | {
8488 log .debug ("Fetch mode: url {s}, dump {any}" , .{ opts .url , opts .dump });
8589
86- var app = try @import ("app.zig" ).App .init (alloc , .fetch );
90+ var app = try App .init (alloc , .{
91+ .run_mode = args .mode ,
92+ .tls_verify_host = opts .tls_verify_host ,
93+ });
8794 defer app .deinit ();
8895 app .telemetry .record (.{ .run = {} });
8996
@@ -125,14 +132,7 @@ const Command = struct {
125132 mode : Mode ,
126133 exec_name : []const u8 ,
127134
128- const ModeType = enum {
129- help ,
130- fetch ,
131- serve ,
132- version ,
133- };
134-
135- const Mode = union (ModeType ) {
135+ const Mode = union (App .RunMode ) {
136136 help : bool , // false when being printed because of an error
137137 fetch : Fetch ,
138138 serve : Serve ,
@@ -143,11 +143,13 @@ const Command = struct {
143143 host : []const u8 ,
144144 port : u16 ,
145145 timeout : u16 ,
146+ tls_verify_host : bool ,
146147 };
147148
148149 const Fetch = struct {
149150 url : []const u8 ,
150151 dump : bool = false ,
152+ tls_verify_host : bool ,
151153 };
152154
153155 fn printUsageAndExit (self : * const Command , success : bool ) void {
@@ -164,6 +166,12 @@ const Command = struct {
164166 \\--dump Dumps document to stdout.
165167 \\ Defaults to false.
166168 \\
169+ \\--insecure_disable_tls_host_verification
170+ \\ Disables host verification on all HTTP requests.
171+ \\ This is an advanced option which should only be
172+ \\ set if you understand and accept the risk of
173+ \\ disabling host verification.
174+ \\
167175 \\serve command
168176 \\Starts a websocket CDP server
169177 \\Example: {s} serve --host 127.0.0.1 --port 9222
@@ -178,11 +186,18 @@ const Command = struct {
178186 \\--timeout Inactivity timeout in seconds before disconnecting clients
179187 \\ Defaults to 3 (seconds)
180188 \\
189+ \\--insecure_disable_tls_host_verification
190+ \\ Disables host verification on all HTTP requests.
191+ \\ This is an advanced option which should only be
192+ \\ set if you understand and accept the risk of
193+ \\ disabling host verification.
194+ \\
181195 \\version command
182196 \\Displays the version of {s}
183197 \\
184198 \\help command
185199 \\Displays this message
200+ \\
186201 ;
187202 std .debug .print (usage , .{ self .exec_name , self .exec_name , self .exec_name , self .exec_name });
188203 if (success ) {
@@ -204,7 +219,7 @@ fn parseArgs(allocator: Allocator) !Command {
204219 };
205220
206221 const mode_string = args .next () orelse "" ;
207- const mode = std .meta .stringToEnum (Command . ModeType , mode_string ) orelse blk : {
222+ const mode = std .meta .stringToEnum (App . RunMode , mode_string ) orelse blk : {
208223 const inferred_mode = inferMode (mode_string ) orelse return cmd ;
209224 // "command" wasn't a command but an option. We can't reset args, but
210225 // we can create a new one. Not great, but this fallback is temporary
@@ -227,7 +242,7 @@ fn parseArgs(allocator: Allocator) !Command {
227242 return cmd ;
228243}
229244
230- fn inferMode (opt : []const u8 ) ? Command.ModeType {
245+ fn inferMode (opt : []const u8 ) ? App.RunMode {
231246 if (opt .len == 0 ) {
232247 return .serve ;
233248 }
@@ -260,6 +275,7 @@ fn parseServeArgs(
260275 var host : []const u8 = "127.0.0.1" ;
261276 var port : u16 = 9222 ;
262277 var timeout : u16 = 3 ;
278+ var tls_verify_host = true ;
263279
264280 while (args .next ()) | opt | {
265281 if (std .mem .eql (u8 , "--host" , opt )) {
@@ -297,6 +313,11 @@ fn parseServeArgs(
297313 continue ;
298314 }
299315
316+ if (std .mem .eql (u8 , "--insecure_tls_verify_host" , opt )) {
317+ tls_verify_host = false ;
318+ continue ;
319+ }
320+
300321 log .err ("Unknown option to serve command: '{s}'" , .{opt });
301322 return error .UnkownOption ;
302323 }
@@ -305,6 +326,7 @@ fn parseServeArgs(
305326 .host = host ,
306327 .port = port ,
307328 .timeout = timeout ,
329+ .tls_verify_host = tls_verify_host ,
308330 };
309331}
310332
@@ -314,13 +336,19 @@ fn parseFetchArgs(
314336) ! Command.Fetch {
315337 var dump : bool = false ;
316338 var url : ? []const u8 = null ;
339+ var tls_verify_host = true ;
317340
318341 while (args .next ()) | opt | {
319342 if (std .mem .eql (u8 , "--dump" , opt )) {
320343 dump = true ;
321344 continue ;
322345 }
323346
347+ if (std .mem .eql (u8 , "--insecure_disable_tls_host_verification" , opt )) {
348+ tls_verify_host = false ;
349+ continue ;
350+ }
351+
324352 if (std .mem .startsWith (u8 , opt , "--" )) {
325353 log .err ("Unknown option to serve command: '{s}'" , .{opt });
326354 return error .UnkownOption ;
@@ -338,7 +366,11 @@ fn parseFetchArgs(
338366 return error .MissingURL ;
339367 }
340368
341- return .{ .url = url .? , .dump = dump };
369+ return .{
370+ .url = url .? ,
371+ .dump = dump ,
372+ .tls_verify_host = tls_verify_host ,
373+ };
342374}
343375
344376var verbose : bool = builtin .mode == .Debug ; // In debug mode, force verbose.
0 commit comments