Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial version #1

Merged
merged 26 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: CI

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

env:
CARGO_TERM_COLOR: always

jobs:
tests:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
61 changes: 61 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "h11"
version = "0.1.0"
edition = "2021"
description = "A pure-Rust, bring-your-own-I/O implementation of HTTP/1.1"
license = "Apache-2.0"
license-file = "LICENSE"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
lazy_static = "1.4.0"
regex = "1.10.2"
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright 2023 abersheeran

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
45 changes: 45 additions & 0 deletions src/_abnf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use lazy_static::lazy_static;

pub static OWS: &str = r"[ \t]*";
pub static TOKEN: &str = r"[-!#$%&'*+.^_`|~0-9a-zA-Z]+";
pub static FIELD_NAME: &str = TOKEN;
pub static VCHAR: &str = r"[\x21-\x7e]";
pub static VCHAR_OR_OBS_TEXT: &str = r"[^\x00\s]";
pub static FIELD_VCHAR: &str = VCHAR_OR_OBS_TEXT;

lazy_static! {
pub static ref FIELD_CONTENT: String = format!(r"{}+(?:[ \t]+{}+)*", FIELD_VCHAR, FIELD_VCHAR);
pub static ref FIELD_VALUE: String = format!(r"({})?", *FIELD_CONTENT);
pub static ref HEADER_FIELD: String = format!(
r"(?P<field_name>{field_name}):{OWS}(?P<field_value>{field_value}){OWS}",
field_name = FIELD_NAME,
field_value = *FIELD_VALUE,
OWS = OWS
);
pub static ref METHOD: String = TOKEN.to_string();
pub static ref REQUEST_TARGET: String = format!("{}+", VCHAR);
pub static ref HTTP_VERSION: String = r"HTTP/(?P<http_version>[0-9]\.[0-9])".to_string();
pub static ref REQUEST_LINE: String = format!(
r"(?P<method>{method}) (?P<target>{request_target}) {http_version}",
method = *METHOD,
request_target = *REQUEST_TARGET,
http_version = *HTTP_VERSION
);
pub static ref STATUS_CODE: String = r"[0-9]{3}".to_string();
pub static ref REASON_PHRASE: String = format!(r"([ \t]|{})*", VCHAR_OR_OBS_TEXT);
pub static ref STATUS_LINE: String = format!(
r"{http_version} (?P<status_code>{status_code})(?: (?P<reason>{reason_phrase}))?",
http_version = *HTTP_VERSION,
status_code = *STATUS_CODE,
reason_phrase = *REASON_PHRASE
);
pub static ref HEXDIG: String = r"[0-9A-Fa-f]".to_string();
pub static ref CHUNK_SIZE: String = format!(r"({}){{1,20}}", *HEXDIG);
pub static ref CHUNK_EXT: String = ";.*".to_string();
pub static ref CHUNK_HEADER: String = format!(
r"(?P<chunk_size>{chunk_size})(?P<chunk_ext>{chunk_ext})?{OWS}\r\n",
chunk_size = *CHUNK_SIZE,
chunk_ext = *CHUNK_EXT,
OWS = OWS
);
}
Loading