Function resolveInPlace [src]

Resolves a URI against a base URI, conforming to RFC 3986, Section 5 Assumes new location is already copied to the beginning of aux_buf.*. Parses that new location as a URI, and then resolves the path in place. If a merge needs to take place, the newly constructed path will be stored in aux_buf.* just after the copied location, and aux_buf.* will be modified to only contain the remaining unused space.

Prototype

pub fn resolveInPlace(base: Uri, new_len: usize, aux_buf: *[]u8) ResolveInPlaceError!Uri

Parameters

base: Urinew_len: usizeaux_buf: *[]u8

Possible Errors

InvalidFormat ParseError
InvalidPort ParseError
NoSpaceLeft
UnexpectedCharacter ParseError

Source

pub fn resolveInPlace(base: Uri, new_len: usize, aux_buf: *[]u8) ResolveInPlaceError!Uri { const new = aux_buf.*[0..new_len]; const new_parsed = parse(new) catch |err| (parseAfterScheme("", new) catch return err); aux_buf.* = aux_buf.*[new_len..]; // As you can see above, `new` is not a const pointer. const new_path: []u8 = @constCast(new_parsed.path.percent_encoded); if (new_parsed.scheme.len > 0) return .{ .scheme = new_parsed.scheme, .user = new_parsed.user, .password = new_parsed.password, .host = new_parsed.host, .port = new_parsed.port, .path = remove_dot_segments(new_path), .query = new_parsed.query, .fragment = new_parsed.fragment, }; if (new_parsed.host) |host| return .{ .scheme = base.scheme, .user = new_parsed.user, .password = new_parsed.password, .host = host, .port = new_parsed.port, .path = remove_dot_segments(new_path), .query = new_parsed.query, .fragment = new_parsed.fragment, }; const path, const query = if (new_path.len == 0) .{ base.path, new_parsed.query orelse base.query, } else if (new_path[0] == '/') .{ remove_dot_segments(new_path), new_parsed.query, } else .{ try merge_paths(base.path, new_path, aux_buf), new_parsed.query, }; return .{ .scheme = base.scheme, .user = base.user, .password = base.password, .host = base.host, .port = base.port, .path = path, .query = query, .fragment = new_parsed.fragment, }; }