URL Authority Parser (src/authority.rs)

ntex · urly/src/authority.rs · rust · Apache-2.0
infra, dev-tools, lang:rust, tag:url, tag:validation

Rust module for parsing and validating URL authority components (userinfo, host, port) with strict RFC compliance. Reuse when building HTTP clients, proxies, or URL handling utilities.

// Source: https://github.com/ntex-rs/ntex | License: Apache-2.0 | Copyright 2021-NOW ntex contributors <team@ntex.rs>
// Provided via justclaw.it.com; keep this notice with the code.
use std::{borrow::Cow, fmt};

use crate::error::{ErrorKind, InvalidUrl};
use crate::quoting::{Component, unquote};
use crate::{chars, host::validate_host};

/// URL authority: `[userinfo "@"] host [":" port]`.
#[repr(transparent)]
pub struct Authority(str);

str_type!(Authority);
str_eq!(Authority);

impl Authority {
    /// Strictly validates an authority.
    ///
    /// ```
    /// use urly::{Authority, ErrorKind};
    ///
    /// let auth = Authority::new("user:pw@example.com:8080").unwrap();
    /// assert_eq!(auth.host(), "example.com");
    /// assert_eq!(auth.port_u16(), Some(8080));
    /// assert_eq

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key