DoxigAlpha

resolveInPlace

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.

Function parameters

Parameters

#
new_len:usize
aux_buf:*[]u8

Type definitions in this namespace

Types

#

Returned value may point into `buffer` or be the original string.

Functions

#
getHost
Returned value may point into `buffer` or be the original string.
getHostAlloc
Returned value may point into `buffer` or be the original string.
percentDecodeBackwards
Percent decodes all %XX where XX is a valid hex number.
percentDecodeInPlace
Percent decodes all %XX where XX is a valid hex number.
parseAfterScheme
Parses the URI or returns an error.
parse
The return value will contain strings pointing into the original `text`.
resolveInPlace
Resolves a URI against a base URI, conforming to

Error sets in this namespace

Error Sets

#

= 255

Values

#

Source

Implementation

#
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,
    };
}