mirror of
https://codeberg.org/icewind/rfc7239.git
synced 2026-06-04 00:54:12 +02:00
Compare commits
10 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 821cf57882 | |||
| 3227c7151f | |||
| 5b55fcf721 | |||
| 35f3614685 | |||
| d82a9506b7 | |||
| 432d2393cb | |||
| b36dc994a1 | |||
| d06978a34a | |||
| 42c9c2abd6 | |||
| ef8c3b961d |
10 changed files with 193 additions and 53 deletions
1
.envrc
Normal file
1
.envrc
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
use flake
|
||||||
16
.forgejo/workflows/ci.yaml
Normal file
16
.forgejo/workflows/ci.yaml
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
name: "CI"
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
push:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
checks:
|
||||||
|
runs-on: nix
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: https://codeberg.org/icewind/attic-action@v1
|
||||||
|
with:
|
||||||
|
name: link
|
||||||
|
instance: https://cache.icewind.link
|
||||||
|
authToken: "${{ secrets.ATTIC_TOKEN }}"
|
||||||
|
- run: nix flake check --keep-going
|
||||||
33
.github/workflows/rust.yml
vendored
33
.github/workflows/rust.yml
vendored
|
|
@ -1,33 +0,0 @@
|
||||||
on: [push, pull_request]
|
|
||||||
|
|
||||||
name: CI
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
check:
|
|
||||||
name: Check
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- uses: actions-rs/toolchain@v1
|
|
||||||
with:
|
|
||||||
profile: minimal
|
|
||||||
toolchain: stable
|
|
||||||
override: true
|
|
||||||
- uses: Swatinem/rust-cache@v1
|
|
||||||
- uses: actions-rs/cargo@v1
|
|
||||||
with:
|
|
||||||
command: check
|
|
||||||
|
|
||||||
test:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
name: Tests
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- uses: actions-rs/toolchain@v1
|
|
||||||
with:
|
|
||||||
toolchain: stable
|
|
||||||
- uses: Swatinem/rust-cache@v1
|
|
||||||
- uses: actions-rs/cargo@v1
|
|
||||||
with:
|
|
||||||
command: test
|
|
||||||
5
.gitignore
vendored
5
.gitignore
vendored
|
|
@ -1 +1,4 @@
|
||||||
/target
|
.idea
|
||||||
|
target
|
||||||
|
result
|
||||||
|
.direnv
|
||||||
6
Cargo.lock
generated
6
Cargo.lock
generated
|
|
@ -4,7 +4,7 @@ version = 3
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rfc7239"
|
name = "rfc7239"
|
||||||
version = "0.1.1"
|
version = "0.1.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"uncased",
|
"uncased",
|
||||||
]
|
]
|
||||||
|
|
@ -20,6 +20,6 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "version_check"
|
name = "version_check"
|
||||||
version = "0.9.4"
|
version = "0.9.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,17 @@
|
||||||
[package]
|
[package]
|
||||||
name = "rfc7239"
|
name = "rfc7239"
|
||||||
version = "0.1.1"
|
version = "0.1.3"
|
||||||
authors = ["Robin Appelman <robin@icewind.nl>"]
|
authors = ["Robin Appelman <robin@icewind.nl>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "Parser for rfc7239 formatted Forwarded headers"
|
description = "Parser for rfc7239 formatted Forwarded headers"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
repository = "https://github.com/icewind1991/rfc7239"
|
repository = "https://codeberg.org/icewind/rfc7239"
|
||||||
documentation = "https://docs.rs/rfc7239"
|
documentation = "https://docs.rs/rfc7239"
|
||||||
|
rust-version = "1.56.1"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
uncased = "0.9.10"
|
uncased = "0.9.10"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
std = []
|
||||||
|
default = ["std"]
|
||||||
11
README.md
11
README.md
|
|
@ -18,4 +18,13 @@ for node_result in parse(header_value) {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
[rfc7239]: https://tools.ietf.org/html/rfc7239
|
## `no_std`
|
||||||
|
|
||||||
|
This crate can be used in a `no_std` environment by disabling the default `std`
|
||||||
|
feature.
|
||||||
|
|
||||||
|
The only impact disabling this feature has is using `core::error::Error` and
|
||||||
|
`core::net::IpAddr` instead of the `std` variants and increasing the msrv to
|
||||||
|
1.81.
|
||||||
|
|
||||||
|
[rfc7239]: https://tools.ietf.org/html/rfc7239
|
||||||
|
|
|
||||||
107
flake.lock
generated
Normal file
107
flake.lock
generated
Normal file
|
|
@ -0,0 +1,107 @@
|
||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"crane": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1742394900,
|
||||||
|
"narHash": "sha256-vVOAp9ahvnU+fQoKd4SEXB2JG2wbENkpqcwlkIXgUC0=",
|
||||||
|
"owner": "ipetkov",
|
||||||
|
"repo": "crane",
|
||||||
|
"rev": "70947c1908108c0c551ddfd73d4f750ff2ea67cd",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "ipetkov",
|
||||||
|
"repo": "crane",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"flakelight": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": [
|
||||||
|
"nixpkgs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1747659009,
|
||||||
|
"narHash": "sha256-3FFAthqh4rWKTClF+WgM+9CmMDlnfWcPdd3hGBFVNHc=",
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "flakelight",
|
||||||
|
"rev": "93d72adbe0b022791b0faadfb31cb6e98c37f0ad",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "flakelight",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"mill-scale": {
|
||||||
|
"inputs": {
|
||||||
|
"crane": "crane",
|
||||||
|
"flakelight": [
|
||||||
|
"flakelight"
|
||||||
|
],
|
||||||
|
"rust-overlay": "rust-overlay"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1747928985,
|
||||||
|
"narHash": "sha256-OGJvoEbcclL566m9PCq+SdOQ9vJzLfVCOkww9L/uZT8=",
|
||||||
|
"ref": "refs/heads/main",
|
||||||
|
"rev": "742b8596357b53bf437d504a87455f46edba8be2",
|
||||||
|
"revCount": 46,
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://codeberg.org/icewind/mill-scale.git"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://codeberg.org/icewind/mill-scale.git"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1747862697,
|
||||||
|
"narHash": "sha256-U4HaNZ1W26cbOVm0Eb5OdGSnfQVWQKbLSPrSSa78KC0=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "2baa12ff69913392faf0ace833bc54bba297ea95",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"id": "nixpkgs",
|
||||||
|
"ref": "nixos-24.11",
|
||||||
|
"type": "indirect"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"flakelight": "flakelight",
|
||||||
|
"mill-scale": "mill-scale",
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"rust-overlay": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": [
|
||||||
|
"mill-scale",
|
||||||
|
"flakelight",
|
||||||
|
"nixpkgs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1742697269,
|
||||||
|
"narHash": "sha256-Lpp0XyAtIl1oGJzNmTiTGLhTkcUjwSkEb0gOiNzYFGM=",
|
||||||
|
"owner": "oxalica",
|
||||||
|
"repo": "rust-overlay",
|
||||||
|
"rev": "01973c84732f9275c50c5f075dd1f54cc04b3316",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "oxalica",
|
||||||
|
"repo": "rust-overlay",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
||||||
14
flake.nix
Normal file
14
flake.nix
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = "nixpkgs/nixos-24.11";
|
||||||
|
flakelight = {
|
||||||
|
url = "github:nix-community/flakelight";
|
||||||
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
};
|
||||||
|
mill-scale = {
|
||||||
|
url = "git+https://codeberg.org/icewind/mill-scale.git";
|
||||||
|
inputs.flakelight.follows = "flakelight";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
outputs = {mill-scale, ...}: mill-scale ./. {};
|
||||||
|
}
|
||||||
44
src/lib.rs
44
src/lib.rs
|
|
@ -1,10 +1,12 @@
|
||||||
|
#![cfg_attr(not(feature = "std"), no_std)]
|
||||||
|
|
||||||
//! Parser for [rfc7239] formatted `Forwarded` headers.
|
//! Parser for [rfc7239] formatted `Forwarded` headers.
|
||||||
//!
|
//!
|
||||||
//! ## Usage
|
//! ## Usage
|
||||||
//!
|
//!
|
||||||
//! ```
|
//! ```
|
||||||
//! use rfc7239::parse;
|
//! use rfc7239::parse;
|
||||||
//! # use std::error::Error;
|
//! # use core::error::Error;
|
||||||
//!
|
//!
|
||||||
//! # fn main() -> Result<(), Box<dyn Error>> {
|
//! # fn main() -> Result<(), Box<dyn Error>> {
|
||||||
//! // get the header value from your favorite http server library
|
//! // get the header value from your favorite http server library
|
||||||
|
|
@ -21,10 +23,26 @@
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
//! [rfc7239]: https://tools.ietf.org/html/rfc7239
|
//! [rfc7239]: https://tools.ietf.org/html/rfc7239
|
||||||
use std::error::Error;
|
|
||||||
use std::fmt::{Debug, Display, Formatter};
|
#[cfg(all(test, not(feature = "std")))]
|
||||||
use std::net::IpAddr;
|
extern crate std;
|
||||||
use std::str::FromStr;
|
#[cfg(all(test, not(feature = "std")))]
|
||||||
|
use std::{format, vec, vec::Vec};
|
||||||
|
|
||||||
|
#[cfg(not(feature = "std"))]
|
||||||
|
use core::{
|
||||||
|
error::Error,
|
||||||
|
fmt::{Debug, Display, Formatter},
|
||||||
|
net::IpAddr,
|
||||||
|
str::FromStr,
|
||||||
|
};
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
use std::{
|
||||||
|
error::Error,
|
||||||
|
fmt::{Debug, Display, Formatter},
|
||||||
|
net::IpAddr,
|
||||||
|
str::FromStr,
|
||||||
|
};
|
||||||
use uncased::UncasedStr;
|
use uncased::UncasedStr;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
@ -36,7 +54,7 @@ pub enum RfcError {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for RfcError {
|
impl Display for RfcError {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
|
||||||
let str = match self {
|
let str = match self {
|
||||||
RfcError::InvalidIdentifier => "Invalid node identifier",
|
RfcError::InvalidIdentifier => "Invalid node identifier",
|
||||||
RfcError::InvalidPort => "Invalid node port",
|
RfcError::InvalidPort => "Invalid node port",
|
||||||
|
|
@ -50,7 +68,7 @@ impl Display for RfcError {
|
||||||
impl Error for RfcError {}
|
impl Error for RfcError {}
|
||||||
|
|
||||||
/// Parse an rfc7239 header value into a list of forwarded nodes
|
/// Parse an rfc7239 header value into a list of forwarded nodes
|
||||||
pub fn parse(header_value: &str) -> impl Iterator<Item = Result<Forwarded, RfcError>> {
|
pub fn parse(header_value: &str) -> impl DoubleEndedIterator<Item = Result<Forwarded, RfcError>> {
|
||||||
header_value.split(',').map(str::trim).map(Forwarded::parse)
|
header_value.split(',').map(str::trim).map(Forwarded::parse)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -114,8 +132,8 @@ impl<'a> Forwarded<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Display for Forwarded<'a> {
|
impl Display for Forwarded<'_> {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
|
||||||
let mut needs_delim = false;
|
let mut needs_delim = false;
|
||||||
if let Some(ident) = &self.forwarded_for {
|
if let Some(ident) = &self.forwarded_for {
|
||||||
if ident.display_needs_quote() {
|
if ident.display_needs_quote() {
|
||||||
|
|
@ -247,8 +265,8 @@ impl<'a> NodeIdentifier<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Display for NodeIdentifier<'a> {
|
impl Display for NodeIdentifier<'_> {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
|
||||||
match self.port {
|
match self.port {
|
||||||
Some(port) => write!(f, "{}:{}", self.name, port),
|
Some(port) => write!(f, "{}:{}", self.name, port),
|
||||||
None => write!(f, "{}", self.name),
|
None => write!(f, "{}", self.name),
|
||||||
|
|
@ -375,8 +393,8 @@ impl<'a> NodeName<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Display for NodeName<'a> {
|
impl Display for NodeName<'_> {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
NodeName::Ip(IpAddr::V4(ip)) => write!(f, "{}", ip),
|
NodeName::Ip(IpAddr::V4(ip)) => write!(f, "{}", ip),
|
||||||
NodeName::Ip(IpAddr::V6(ip)) => write!(f, "[{}]", ip),
|
NodeName::Ip(IpAddr::V6(ip)) => write!(f, "[{}]", ip),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue