| ... | @@ -7,7 +7,7 @@ const assert = std.debug.assert; | ... | @@ -7,7 +7,7 @@ const assert = std.debug.assert; |
| 7 | const http = std.http; | 7 | const http = std.http; |
| 8 | const net = std.net; | 8 | const net = std.net; |
| 9 | const Client = @This(); | 9 | const Client = @This(); |
| 10 | const Url = std.Url; | 10 | const Uri = std.Uri; |
| 11 | const Allocator = std.mem.Allocator; | 11 | const Allocator = std.mem.Allocator; |
| 12 | const testing = std.testing; | 12 | const testing = std.testing; |
| 13 | | 13 | |
| ... | @@ -569,7 +569,7 @@ pub const Request = struct { | ... | @@ -569,7 +569,7 @@ pub const Request = struct { |
| 569 | if (req.redirects_left == 0) return error.TooManyHttpRedirects; | 569 | if (req.redirects_left == 0) return error.TooManyHttpRedirects; |
| 570 | const location = req.response.headers.location orelse | 570 | const location = req.response.headers.location orelse |
| 571 | return error.HttpRedirectMissingLocation; | 571 | return error.HttpRedirectMissingLocation; |
| 572 | const new_url = try std.Url.parse(location); | 572 | const new_url = try std.Uri.parse(location); |
| 573 | const new_req = try req.client.request(new_url, req.headers, .{ | 573 | const new_req = try req.client.request(new_url, req.headers, .{ |
| 574 | .max_redirects = req.redirects_left - 1, | 574 | .max_redirects = req.redirects_left - 1, |
| 575 | .header_strategy = if (req.response.header_bytes_owned) .{ | 575 | .header_strategy = if (req.response.header_bytes_owned) .{ |
| ... | @@ -734,23 +734,26 @@ pub fn connect(client: *Client, host: []const u8, port: u16, protocol: Connectio | ... | @@ -734,23 +734,26 @@ pub fn connect(client: *Client, host: []const u8, port: u16, protocol: Connectio |
| 734 | return conn; | 734 | return conn; |
| 735 | } | 735 | } |
| 736 | | 736 | |
| 737 | pub fn request(client: *Client, url: Url, headers: Request.Headers, options: Request.Options) !Request { | 737 | pub fn request(client: *Client, uri: Uri, headers: Request.Headers, options: Request.Options) !Request { |
| 738 | const protocol: Connection.Protocol = if (mem.eql(u8, url.scheme, "http")) | 738 | const scheme = uri.scheme orelse return error.UnsupportedUrlScheme; |
| | 739 | const protocol: Connection.Protocol = if (mem.eql(u8, scheme, "http")) |
| 739 | .plain | 740 | .plain |
| 740 | else if (mem.eql(u8, url.scheme, "https")) | 741 | else if (mem.eql(u8, scheme, "https")) |
| 741 | .tls | 742 | .tls |
| 742 | else | 743 | else |
| 743 | return error.UnsupportedUrlScheme; | 744 | return error.UnsupportedUrlScheme; |
| 744 | | 745 | |
| 745 | const port: u16 = url.port orelse switch (protocol) { | 746 | const port: u16 = uri.port orelse switch (protocol) { |
| 746 | .plain => 80, | 747 | .plain => 80, |
| 747 | .tls => 443, | 748 | .tls => 443, |
| 748 | }; | 749 | }; |
| 749 | | 750 | |
| | 751 | const host = uri.host orelse return error.UriMissingHost; |
| | 752 | |
| 750 | var req: Request = .{ | 753 | var req: Request = .{ |
| 751 | .client = client, | 754 | .client = client, |
| 752 | .headers = headers, | 755 | .headers = headers, |
| 753 | .connection = try client.connect(url.host, port, protocol), | 756 | .connection = try client.connect(host, port, protocol), |
| 754 | .redirects_left = options.max_redirects, | 757 | .redirects_left = options.max_redirects, |
| 755 | .response = switch (options.header_strategy) { | 758 | .response = switch (options.header_strategy) { |
| 756 | .dynamic => |max| Request.Response.initDynamic(max), | 759 | .dynamic => |max| Request.Response.initDynamic(max), |
| ... | @@ -762,11 +765,11 @@ pub fn request(client: *Client, url: Url, headers: Request.Headers, options: Req | ... | @@ -762,11 +765,11 @@ pub fn request(client: *Client, url: Url, headers: Request.Headers, options: Req |
| 762 | var h = try std.BoundedArray(u8, 1000).init(0); | 765 | var h = try std.BoundedArray(u8, 1000).init(0); |
| 763 | try h.appendSlice(@tagName(headers.method)); | 766 | try h.appendSlice(@tagName(headers.method)); |
| 764 | try h.appendSlice(" "); | 767 | try h.appendSlice(" "); |
| 765 | try h.appendSlice(url.path); | 768 | try h.appendSlice(uri.path); |
| 766 | try h.appendSlice(" "); | 769 | try h.appendSlice(" "); |
| 767 | try h.appendSlice(@tagName(headers.version)); | 770 | try h.appendSlice(@tagName(headers.version)); |
| 768 | try h.appendSlice("\r\nHost: "); | 771 | try h.appendSlice("\r\nHost: "); |
| 769 | try h.appendSlice(url.host); | 772 | try h.appendSlice(host); |
| 770 | try h.appendSlice("\r\nConnection: close\r\n\r\n"); | 773 | try h.appendSlice("\r\nConnection: close\r\n\r\n"); |
| 771 | | 774 | |
| 772 | const header_bytes = h.slice(); | 775 | const header_bytes = h.slice(); |