# Header info parser for surf crate [![Crates.io](https://img.shields.io/crates/v/surf-header.svg)](https://crates.io/crates/surf-header) [![Rust](https://img.shields.io/badge/rust-1.56.1%2B-blue.svg?maxAge=3600)](https://gitlab.com/andrew_ryan/surf-header) [![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://gitlab.com/andrew_ryan/surf-header/-/raw/master/LICENSE) ```sh cargo add tokio -F full cargo add surf_header cargo add surf ``` ```rust #[tokio::main] async fn main() { use std::collections::BTreeMap; use surf_header::Header; use surf_header::parse_to_surf_header; let h = r##" GET / HTTP/1.1 Host: crates.io Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.5249.119 Safari/537.36 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9 Referer: https://crates.io/ Accept-Encoding: gzip, deflate Accept-Language: en-US,en;q=0.9 Connection: close "##; let info = parse_to_surf_header(h).unwrap(); let mut req = surf::get(info.url).build(); req.headers(info.headers); let client = surf::Client::new(); let mut res = client.send(req).await.unwrap(); println!("{:?}",res.body_string().await.unwrap()); } ``` ```rust pub async fn ctf(){ use surf_header::Print; use surf_header::DebugPrint; use surf_header::Str; use surf_header::HttpSend; let get = async move |url:&str|url.to_string().send("GET").await.unwrap().body_string().await.unwrap().print(); get("url/?id=-1'union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'--+").await; } ``` ## implment print println eprint eprintln for impl Display, impl Debug ```rust use surf_header::Print; use surf_header::DebugPrint; "printable text".print();//impl Display "printable text".println(); "printable text".eprintln(); #[derive(Debug)] struct DebugPrintDemo{} let d = DebugPrintDemo{}; d.print(); d.println(); d.eprintln(); ``` ## implment format for impl ToString ```rust fn main() { use surf_header::Print; use surf_header::Str; "this is a {s},I like Trait Object {p}%" .format(vec![(Box::new("{s}"),Box::new("demo")),(Box::new("{p}"),Box::new(100))]).println();//this is a demo,I like Trait Object 100% use surf_header::targets; "this is a {d},I like Trait Object {p}}%" .format(targets!{"{d}"=>"demo","{p}"=>100}) .println(); //this is a demo,I like Trait Object 100% } ``` ## implment targets! for return Vec<(Box\,Box\)> ```rust fn main() { use surf_header::Print; use surf_header::Str; "this is a {s},I like Trait Object {p}%" .format(vec![(Box::new("{s}"),Box::new("demo")),(Box::new("{p}"),Box::new(100))]).println();//this is a demo,I like Trait Object 100% use surf_header::targets; "this is a {d},I like Trait Object {p}}%" .format(targets!{"{d}"=>"demo","{p}"=>100}) .println(); //this is a demo,I like Trait Object 100% } ```