@@ -7,7 +7,7 @@ const assert = std.debug.assert;
77const http = std .http ;
88const net = std .net ;
99const Client = @This ();
10- const Url = std .Url ;
10+ const Uri = std .Uri ;
1111const Allocator = std .mem .Allocator ;
1212const testing = std .testing ;
1313
@@ -569,7 +569,7 @@ pub const Request = struct {
569569 if (req .redirects_left == 0 ) return error .TooManyHttpRedirects ;
570570 const location = req .response .headers .location orelse
571571 return error .HttpRedirectMissingLocation ;
572- const new_url = try std .Url .parse (location );
572+ const new_url = try std .Uri .parse (location );
573573 const new_req = try req .client .request (new_url , req .headers , .{
574574 .max_redirects = req .redirects_left - 1 ,
575575 .header_strategy = if (req .response .header_bytes_owned ) .{
@@ -734,23 +734,26 @@ pub fn connect(client: *Client, host: []const u8, port: u16, protocol: Connectio
734734 return conn ;
735735}
736736
737- pub fn request (client : * Client , url : Url , headers : Request.Headers , options : Request.Options ) ! Request {
738- const protocol : Connection.Protocol = if (mem .eql (u8 , url .scheme , "http" ))
737+ pub fn request (client : * Client , uri : Uri , headers : Request.Headers , options : Request.Options ) ! Request {
738+ const scheme = uri .scheme orelse return error .UnsupportedUrlScheme ;
739+ const protocol : Connection.Protocol = if (mem .eql (u8 , scheme , "http" ))
739740 .plain
740- else if (mem .eql (u8 , url . scheme , "https" ))
741+ else if (mem .eql (u8 , scheme , "https" ))
741742 .tls
742743 else
743744 return error .UnsupportedUrlScheme ;
744745
745- const port : u16 = url .port orelse switch (protocol ) {
746+ const port : u16 = uri .port orelse switch (protocol ) {
746747 .plain = > 80 ,
747748 .tls = > 443 ,
748749 };
749750
751+ const host = uri .host orelse return error .UriMissingHost ;
752+
750753 var req : Request = .{
751754 .client = client ,
752755 .headers = headers ,
753- .connection = try client .connect (url . host , port , protocol ),
756+ .connection = try client .connect (host , port , protocol ),
754757 .redirects_left = options .max_redirects ,
755758 .response = switch (options .header_strategy ) {
756759 .dynamic = > | max | Request .Response .initDynamic (max ),
@@ -762,11 +765,11 @@ pub fn request(client: *Client, url: Url, headers: Request.Headers, options: Req
762765 var h = try std .BoundedArray (u8 , 1000 ).init (0 );
763766 try h .appendSlice (@tagName (headers .method ));
764767 try h .appendSlice (" " );
765- try h .appendSlice (url .path );
768+ try h .appendSlice (uri .path );
766769 try h .appendSlice (" " );
767770 try h .appendSlice (@tagName (headers .version ));
768771 try h .appendSlice ("\r \n Host: " );
769- try h .appendSlice (url . host );
772+ try h .appendSlice (host );
770773 try h .appendSlice ("\r \n Connection: close\r \n \r \n " );
771774
772775 const header_bytes = h .slice ();
0 commit comments