GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - tickbh/webparse: http1.1/http2 parse http解析库

BranchesTags
Open more actions menu

Latest commit

 

History

182 Commits
182 Commits

Folders and files

NameName
Last commit message
Last commit date
.vscode
.vscode
 
 
examples
examples
 
 
src
src
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
Cargo.toml
Cargo.toml
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 

Repository files navigation

webparse

一个包含http1.1及http2的解析库。极少的依赖

使用方法

http/1.1的解析示例

let mut req = webparse::Request::new();
let ret = req.parse(b"GET /index.html HTTP/1.1\r\nHost");
assert!(ret.err().unwrap().is_partial());

let buf = b"GET /index.html HTTP/1.1\r\nHost: example.domain\r\n\r\n";
let ret = req.parse(buf).unwrap();

assert!(ret == buf.len());
assert!(req.is_complete());

http2的头解析示例,包含huffman,rfc7541 C.4

use webparse::{Helper, http2::{frame::Headers, Decoder, DEFAULT_SETTINGS_HEADER_TABLE_SIZE}, BinaryMut, Method, Scheme};

fn parse_header() {
    let mut decoder = Decoder::new();
    // C.4.1
    let buf = Helper::hex_to_vec("8286 8441 8cf1 e3c2 e5f2 3a6b a0ab 90f4 ff");
    let buf_len = buf.len();
    let mut header = Headers::empty();
    let size = header.parse(BinaryMut::from(buf), &mut decoder, DEFAULT_SETTINGS_HEADER_TABLE_SIZE).unwrap();
    assert!(size == buf_len);
    assert!(header.method() == &Some(Method::Get));
    assert!(header.path() == &Some("/".to_string()));
    assert!(header.scheme() == &Some(Scheme::Http));
    assert!(header.authority() == &Some("www.example.com".to_string()));

    // C.4.2
    let buf = Helper::hex_to_vec("8286 84be 5886 a8eb 1064 9cbf");
    let buf_len = buf.len();
    let mut header = Headers::empty();
    let size = header.parse(BinaryMut::from(buf), &mut decoder, DEFAULT_SETTINGS_HEADER_TABLE_SIZE).unwrap();
    assert!(size == buf_len);
    assert!(header.method() == &Some(Method::Get));
    assert!(header.path() == &Some("/".to_string()));
    assert!(header.scheme() == &Some(Scheme::Http));
    assert!(header.authority() == &Some("www.example.com".to_string()));
    assert!(header.fields()["cache-control"] == "no-cache");

    // C.4.3
    let buf = Helper::hex_to_vec("8287 85bf 4088 25a8 49e9 5ba9 7d7f 8925 a849 e95b b8e8 b4bf ");
    let buf_len = buf.len();
    let mut header = Headers::empty();
    let size = header.parse(BinaryMut::from(buf), &mut decoder, DEFAULT_SETTINGS_HEADER_TABLE_SIZE).unwrap();
    assert!(size == buf_len);
    assert!(header.method() == &Some(Method::Get));
    assert!(header.path() == &Some("/index.html".to_string()));
    assert!(header.scheme() == &Some(Scheme::Https));
    assert!(header.authority() == &Some("www.example.com".to_string()));
    assert!(header.fields()["custom-key"] == "custom-value");
}

License

Apache License, Version 2.0 (LICENSE-APACHE or https://apache.org/licenses/LICENSE-2.0)

About

http1.1/http2 parse http解析库

Topics

httphttp2httpparsersocks5

Resources

Readme
Apache-2.0 license
Activity

Stars

7 stars

Watchers

1 watching

Forks

1 fork
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.