Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
nix::VerbatimURL Struct Reference

#include <url.hh>

Public Types

using Raw = std::variant<std::string, ParsedURL>

Public Member Functions

 VerbatimURL (std::string_view s)
 VerbatimURL (std::string s)
 VerbatimURL (ParsedURL url)
std::string to_string () const
const ParsedURL parsed () const
std::string_view scheme () const &
std::optional< std::string > lastPathSegment () const

Public Attributes

Raw raw

Detailed Description

Either a ParsedURL or a verbatim string. This is necessary because in certain cases URI must be passed verbatim (e.g. in builtin fetchers), since those are specified by the user. In those cases normalizations performed by the ParsedURL might be surprising and undesirable, since Nix must be a universal client that has to work with various broken services that might interpret URLs in quirky and non-standard ways.

One of those examples is space-as-plus encoding that is very widespread, but it's not strictly RFC3986 compliant. We must preserve that information verbatim.

Though we perform parsing and validation for internal needs.

Member Function Documentation

◆ lastPathSegment()

std::optional< std::string > nix::VerbatimURL::lastPathSegment ( ) const

Get the last non-empty path segment from the URL.

This is useful for extracting filenames from URLs. For example, "https://example.com/path/to/file.txt?query=value" returns "file.txt".

Returns
The last non-empty path segment, or std::nullopt if no such segment exists.

◆ to_string()

std::string nix::VerbatimURL::to_string ( ) const
inline

Get the encoded URL (if specified) verbatim or encode the parsed URL.


The documentation for this struct was generated from the following files:
  • libutil/include/nix/util/url.hh
  • libutil/url.cc