@@ -113,7 +113,9 @@ pub const Page = struct {
113113 .cookie_jar = & session .cookie_jar ,
114114 .microtask_node = .{ .func = microtaskCallback },
115115 .window_clicked_event_node = .{ .func = windowClicked },
116- .request_factory = browser .http_client .requestFactory (browser .notification ),
116+ .request_factory = browser .http_client .requestFactory (.{
117+ .notification = browser .notification ,
118+ }),
117119 .scope = undefined ,
118120 .module_map = .empty ,
119121 };
@@ -205,58 +207,63 @@ pub const Page = struct {
205207 // redirect)
206208 self .url = request_url ;
207209
208- // load the data
209- var request = try self . newHTTPRequest ( opts . method , & self . url , .{ . navigation = true });
210- defer request . deinit ();
211- request . body = opts .body ;
212- request . notification = notification ;
210+ {
211+ // block exists to limit the lifetime of the request, which holds
212+ // onto a connection
213+ var request = try self . newHTTPRequest ( opts .method , & self . url , .{ . navigation = true }) ;
214+ defer request . deinit () ;
213215
214- notification .dispatch (.page_navigate , &.{
215- .opts = opts ,
216- .url = & self .url ,
217- .timestamp = timestamp (),
218- });
216+ request .body = opts .body ;
217+ request .notification = notification ;
219218
220- var response = try request .sendSync (.{});
219+ notification .dispatch (.page_navigate , &.{
220+ .opts = opts ,
221+ .url = & self .url ,
222+ .timestamp = timestamp (),
223+ });
221224
222- // would be different than self.url in the case of a redirect
223- self .url = try URL .fromURI (arena , request .request_uri );
225+ var response = try request .sendSync (.{});
224226
225- const header = response . header ;
226- try session . cookie_jar . populateFromResponse ( & self .url . uri , & header );
227+ // would be different than self.url in the case of a redirect
228+ self .url = try URL . fromURI ( arena , request . request_uri );
227229
228- // TODO handle fragment in url.
229- try self . window . replaceLocation (.{ . url = try self .url .toWebApi ( arena ) } );
230+ const header = response . header ;
231+ try session . cookie_jar . populateFromResponse ( & self .url .uri , & header );
230232
231- const content_type = header .get ("content-type" );
233+ // TODO handle fragment in url.
234+ try self .window .replaceLocation (.{ .url = try self .url .toWebApi (arena ) });
232235
233- const mime : Mime = blk : {
234- if (content_type ) | ct | {
235- break :blk try Mime .parse (arena , ct );
236- }
237- break :blk Mime .sniff (try response .peek ());
238- } orelse .unknown ;
236+ const content_type = header .get ("content-type" );
239237
240- log .info (.http , "navigation" , .{
241- .status = header .status ,
242- .content_type = content_type ,
243- .charset = mime .charset ,
244- .url = request_url ,
245- });
238+ const mime : Mime = blk : {
239+ if (content_type ) | ct | {
240+ break :blk try Mime .parse (arena , ct );
241+ }
242+ break :blk Mime .sniff (try response .peek ());
243+ } orelse .unknown ;
244+
245+ log .info (.http , "navigation" , .{
246+ .status = header .status ,
247+ .content_type = content_type ,
248+ .charset = mime .charset ,
249+ .url = request_url ,
250+ });
251+
252+ if (! mime .isHTML ()) {
253+ var arr : std .ArrayListUnmanaged (u8 ) = .{};
254+ while (try response .next ()) | data | {
255+ try arr .appendSlice (arena , try arena .dupe (u8 , data ));
256+ }
257+ // save the body into the page.
258+ self .raw_data = arr .items ;
259+ return ;
260+ }
246261
247- if (mime .isHTML ()) {
248- self .raw_data = null ;
249262 try self .loadHTMLDoc (& response , mime .charset orelse "utf-8" );
250- try self .processHTMLDoc ();
251- } else {
252- var arr : std .ArrayListUnmanaged (u8 ) = .{};
253- while (try response .next ()) | data | {
254- try arr .appendSlice (arena , try arena .dupe (u8 , data ));
255- }
256- // save the body into the page.
257- self .raw_data = arr .items ;
258263 }
259264
265+ try self .processHTMLDoc ();
266+
260267 notification .dispatch (.page_navigated , &.{
261268 .url = & self .url ,
262269 .timestamp = timestamp (),
0 commit comments