Source
pub fn writeToStream(uri: *const Uri, writer: *Writer, flags: Format.Flags) Writer.Error!void {
if (flags.scheme) {
try writer.print("{s}:", .{uri.scheme});
if (flags.authority and uri.host != null) {
try writer.writeAll("//");
}
}
if (flags.authority) {
if (flags.authentication and uri.host != null) {
if (uri.user) |user| {
try user.formatUser(writer);
if (uri.password) |password| {
try writer.writeByte(':');
try password.formatPassword(writer);
}
try writer.writeByte('@');
}
}
if (uri.host) |host| {
try host.formatHost(writer);
if (flags.port) {
if (uri.port) |port| try writer.print(":{d}", .{port});
}
}
}
if (flags.path) {
const uri_path: Component = if (uri.path.isEmpty()) .{ .percent_encoded = "/" } else uri.path;
try uri_path.formatPath(writer);
if (flags.query) {
if (uri.query) |query| {
try writer.writeByte('?');
try query.formatQuery(writer);
}
}
if (flags.fragment) {
if (uri.fragment) |fragment| {
try writer.writeByte('#');
try fragment.formatFragment(writer);
}
}
}
}