Return an empty string if the requested segment is not valid.
Do not append the final nul byte.
Update the various segments' starting positions as the assembly advances.
Append the forward slash if there's no parsed path segment and the parsed URL scheme is http(s), otherwise append the encoded parsed path segment.
Set the starting position of the query and fragment segments before possibly appending them encoded (which is still wrong).
Stop setting the start position of the output segment in appendEncodedSegment.