pub struct Request<T>where
T: Serialize,{ /* private fields */ }
Implementations§
source§impl Request<()>
impl Request<()>
sourcepub fn new() -> Request<()>
pub fn new() -> Request<()>
Examples found in repository?
examples/demo.rs (line 80)
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
fn debug_request_parse_full_http2() {
let http2: Vec<u8> = vec![
80, 82, 73, 32, 42, 32, 72, 84, 84, 80, 47, 50, 46, 48, 13, 10, 13, 10, 83, 77, 13, 10, 13,
10, 0, 0, 18, 4, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 100, 0, 4, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0,
0, 4, 8, 0, 0, 0, 0, 0, 1, 255, 0, 1, 0, 0, 55, 1, 5, 0, 0, 0, 1, 131, 132, 134, 65, 143,
11, 226, 92, 46, 60, 184, 93, 125, 112, 178, 205, 199, 128, 240, 63, 122, 136, 37, 182, 80,
195, 171, 186, 210, 224, 83, 3, 42, 47, 42, 64, 136, 37, 168, 73, 233, 91, 169, 125, 127,
137, 37, 168, 73, 233, 91, 184, 232, 180, 191, 0, 0, 25, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 83, 69, 84, 84, 73, 78, 71, 83, 32, 101, 120, 112, 101, 99, 116, 101, 100,
];
let mut req = Request::new();
let _size = req.parse(&http2).unwrap();
println!("req = {:?}", req);
}
// fn debug_request_parse_http2() {
// let mut decode = Decoder::new();
// let _http2 = vec![
// 0x82, 0x86, 0x84, 0x41, 0x8c, 0xf1, 0xe3, 0xc2, 0xe5, 0xf2, 0x3a, 0x6b, 0xa0, 0xab, 0x90,
// 0xf4, 0xff,
// ];
// let http2 = hexstr_to_vec("8286 8441 0f77 7777 2e65 7861 6d70 6c65 2e63 6f6d ");
// let mut buf = BinaryMut::from(http2);
// let _result = decode.decode_with_cb(&mut buf, |n, v| {
// println!("n = {:?}, v = {:?}", n, v);
// });
// // println!("result = {:?}", result);
// // let http2 = vec![
// // 0x82, 0x86, 0x84, 0xbe, 0x58, 0x08, 0x6e, 0x6f, 0x2d, 0x63, 0x61, 0x63, 0x68, 0x65,
// // ];
// // let http2 = hexstr_to_vec("8286 84be 5808 6e6f 2d63 6163 6865");
// // let mut buf = BinaryMut::from(http2);
// // let result = decode.decode_with_cb(&mut buf, |n, v| {
// // println!("n = {:?}, v = {:?}", n, v);
// // });
// // println!("result = {:?}", result);
// // {
// // // 8287 85bf 4088 25a8 49e9 5ba9 7d7f 8925 | ....@.%.I.[.}..%
// // // a849 e95b b8e8 b4bf
// // let http2 = vec![
// // 0x82, 0x87, 0x85, 0xbf, 0x40, 0x88, 0x25, 0xa8, 0x49, 0xe9, 0x5b, 0xa9, 0x7d, 0x7f,
// // 0x89, 0x25, 0xa8, 0x49, 0xe9, 0x5b, 0xb8, 0xe8, 0xb4, 0xbf,
// // ];
// // let http2 = hexstr_to_vec(
// // "8287 85bf 400a 6375 7374 6f6d 2d6b 6579 0c63 7573 746f 6d2d 7661 6c75 65",
// // );
// // let mut buf = BinaryMut::from(http2);
// // let result = decode.decode_with_cb(&mut buf, |n, v| {
// // println!("n = {:?}, v = {:?}", n, v);
// // });
// // println!("result = {:?}", result);
// // }
// }
fn debug_request_parse() {
let mut request = Request::new();
request.headers_mut().insert("Connection", "ok");
let _xx = request.headers().is_keep_alive();
return;
// // let value = url::Url::parse("/path");
let _bytes = [
80, 79, 83, 84, 32, 47, 112, 111, 115, 116, 32, 72, 84, 84, 80, 47, 49, 46, 49, 13, 10, 72,
111, 115, 116, 58, 32, 49, 57, 50, 46, 49, 54, 56, 46, 49, 55, 57, 46, 49, 51, 51, 58, 56,
48, 56, 48, 13, 10, 85, 115, 101, 114, 45, 65, 103, 101, 110, 116, 58, 32, 99, 117, 114,
108, 47, 55, 46, 55, 52, 46, 48, 13, 10, 65, 99, 99, 101, 112, 116, 58, 32, 42, 47, 42, 13,
10, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 58, 32, 85, 112, 103, 114, 97, 100,
101, 44, 32, 72, 84, 84, 80, 50, 45, 83, 101, 116, 116, 105, 110, 103, 115, 13, 10, 85,
112, 103, 114, 97, 100, 101, 58, 32, 104, 50, 99, 13, 10, 72, 84, 84, 80, 50, 45, 83, 101,
116, 116, 105, 110, 103, 115, 58, 32, 65, 65, 77, 65, 65, 65, 66, 107, 65, 65, 81, 67, 65,
65, 65, 65, 65, 65, 73, 65, 65, 65, 65, 65, 13, 10, 99, 117, 115, 116, 111, 109, 45, 107,
101, 121, 58, 99, 117, 115, 116, 111, 109, 45, 118, 97, 108, 117, 101, 13, 10, 67, 111,
110, 116, 101, 110, 116, 45, 76, 101, 110, 103, 116, 104, 58, 32, 50, 49, 13, 10, 67, 111,
110, 116, 101, 110, 116, 45, 84, 121, 112, 101, 58, 32, 97, 112, 112, 108, 105, 99, 97,
116, 105, 111, 110, 47, 120, 45, 119, 119, 119, 45, 102, 111, 114, 109, 45, 117, 114, 108,
101, 110, 99, 111, 100, 101, 100, 13, 10, 13, 10, 97, 97, 48, 48, 48, 48, 48, 48, 48, 48,
48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
];
let _result =
request.parse(b"GET //:///// HTTP/1.1\r\nHost: Upgrade, HTTP2-Settings \r\n\r\naaa");
// let _result = request.parse(&bytes);
println!("result = {:?}", request);
println!("is_partial = {}", request.is_partial());
println!("body len = {}", request.get_body_len());
println!("host len = {:?}", request.get_host());
println!("host len = {:?}", request.get_connect_url());
println!(
"http data = {}",
String::from_utf8_lossy(&request.http1_data().unwrap())
);
assert_eq!(
String::from_utf8_lossy(&request.http1_data().unwrap()).as_bytes(),
b"GET //:///// HTTP/1.1\r\nHost: \r\n\r\n"
);
let x = &request.headers()["Host"];
if x == &"foo" {
println!("111");
}
if &"foo" == x {
println!("111");
}
}
fn main() {
let mut req = crate::Request::new();
let ret = req.parse(b"GET / HTTP/1.1\r\nHost: 127.0.0.1\r");
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());
debug_request_parse();
// let mut binmut = BinaryMut::new();
// "aaa".serialize1(&mut binmut);
// let bin = Binary::new();
// let p = Pay::Data(bin);
// println!("bbb = {:?}", p);
// debug_request_parse_full_http2();
// debug_request_parse_http2();
// let req = request::Builder::new()
// .method("POST")
// .body(())
// .unwrap();
// debug_request_parse();
// let v = vec![1u8, 2, 3, 5, 7, 9, 10].into_boxed_slice();
// let mut b = Binary::from(v);
// {
// b.get_next();
// let c = b.clone_slice();
// drop(c);
// b.get_next();
// let d = b.clone_slice();
// drop(d);
// }
// drop(b);
println!("finish");
// let len = v.len();
// let raw = Box::into_raw(v) as *mut u8;
// // Layout::from_size_align(cap, 1);
// let value = unsafe { Vec::from_raw_parts(raw, len, len) };
// println!("value = {:?}", value);
if true {
return;
}
// let mut request = webparse::Request::builder().body("What is this".to_string()).unwrap();
// // let _result = request.parse(b"GET /index.html HTTP/1.1\r\nHost: example.domain\r\n\r\n").unwrap();
// // println!("result = {:?}", request);
// // println!("is_partial = {}", request.is_partial());
// let _result = request.parse(b"GET /index.html HTTP/1.1\r\nHost: example.domain1\r\ncontent-length: 1111\r\n");
// println!("result = {:?}", request);
// println!("is_partial = {}", request.is_partial());
// println!("body len = {}", request.get_body_len());
let url: Result<Url, webparse::WebError> =
Url::try_from("https://%4811:!%2011@www.baidu.com:88/path?aaa=222");
println!("value = {:?}", url);
println!("value = {}", url.ok().unwrap());
let url = Url::try_from("/path?qqq=222");
println!("value = {:?}", url);
println!("value = {}", url.ok().unwrap());
println!("decode = {:?}", Url::url_decode("%48%211111"));
println!("decode = {:?}", Url::url_decode("%48%21111%1"));
println!("decode = {:?}", Url::url_decode("%48%21111%4j"));
let value = Url::try_from("https://11:11@www.baidu.com/path").unwrap();
println!("value = {}", value);
// // let value = url::Url::parse("/path");
// let _result = request.parse(b"GET http://www.baidu.com/ HTTP/1.1\r\nHost: www.baidu.com\r\nUser-Agent: curl/7.74.0\r\nAccept: */*\r\nProxy-Connection: Keep-Alive\r\n\r\n");
// println!("result = {:?}", request);
// println!("is_partial = {}", request.is_partial());
// println!("body len = {}", request.get_body_len());
// println!("host len = {:?}", request.get_host());
// println!("host len = {:?}", request.get_connect_url());
// let mut buffer = Buffer::new();
// request.serialize(&mut buffer).expect("ok");
// println!("aaaaaaaaaaaaaaa {}", String::from_utf8_lossy(buffer.get_write_data()));
// println!("aaaaaaaaaaaaaaa11111 {}", String::from_utf8_lossy(&request.httpdata().unwrap()));
// let mut req = Request::builder();
// assert_eq!(req.url_ref().unwrap(), "/" );
// req = req.url("https://www.rust-lang.org/");
// assert_eq!(req.url_ref().unwrap(), "https://www.rust-lang.org/" );
// let mut req = Request::builder().version(Version::Http2).method("GET")
// .header("Accept", "text/html")
// .header("X-Custom-Foo", "bar");
// {
// let headers = req.headers_mut().unwrap();
// headers["AAAA"] = HeaderValue::Stand("ok");
// let xx = &headers["Accept"];
// let aaa = &headers["AAAA"];
// println!("xxx = {:?}", xx);
// println!("aaa = {:?}", aaa);
// for value in headers.iter() {
// println!("____={:?}", value.0);
// println!("____={:?}", value.1);
// }
// assert_eq!( &headers["Accept"], "text/html" );
// assert_eq!( &headers["X-Custom-Foo"], "bar" );
// }
let req = Request::builder()
.version(Version::Http2)
.method("GET")
.url("/")
.header(":scheme", "http")
.header(":authority", "www.example.com");
{
// let headers = req.headers_mut().unwrap();
// headers["AAAA"] = HeaderValue::Stand("ok");
// let xx = &headers["Accept"];
// let aaa = &headers["AAAA"];
// println!("xxx = {:?}", xx);
// println!("aaa = {:?}", aaa);
// for value in headers.iter() {
// println!("____={:?}", value.0);
// println!("____={:?}", value.1);
// }
// assert_eq!( &headers["Accept"], "text/html" );
// assert_eq!( &headers["X-Custom-Foo"], "bar" );
}
let _rrr = req.body(()).unwrap();
// let data = rrr.http2data().unwrap();
// println!("req.httpdata() = {:?}", hex_debug_print(&data));
// let mut decode = Decoder::new();
// let mut buf = BinaryMut::from(data);
// let result = decode.decode_with_cb(&mut buf, |n, v| {
// println!("n = {:?}, v = {}", n, v);
// });
// let mut index = Arc::new(HeaderIndex::new());
// Arc::get_mut(&mut index).map(|v| {
// v.add_header(
// HeaderName::from_static("aaa"),
// HeaderValue::from_static("aa"),
// );
// });
// let xx = Arc::get_mut(&mut index);
// println!("========={:?}", xx);
// let xx111 = Arc::get_mut(&mut index);
// println!("========={:?}", xx111);
// // rrr.extensions_mut().insert(index);
// // let new = rrr.extensions_mut().get_mut::<Arc<HeaderIndex>>();
// // println!("========={:?}", new);
// // if true {
// // return;
// // }
// let u = url::Builder::new()
// .scheme("https")
// .domain("www.baidu.com")
// .build()
// .unwrap();
// println!("u = {}", u);
// let response = Response::builder()
// .header("Accept", "text/html")
// .header("X-Custom-Foo", "bar")
// .body("my is web")
// .unwrap();
// println!(
// "ssssssssssss {}",
// String::from_utf8_lossy(&response.httpdata().unwrap())
// );
let mut xx = HashMap::<(u32, u8), u8>::new();
xx.insert((48, 5), 6);
// xx.get(&b"xx");
println!("aaa {:?}", xx.get(&(48, 5)));
// let response = url::Builder::
}
pub fn new_by_parts(parts: Parts) -> Request<()>
sourcepub fn builder() -> Builder
pub fn builder() -> Builder
Examples found in repository?
examples/demo.rs (line 293)
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
fn main() {
let mut req = crate::Request::new();
let ret = req.parse(b"GET / HTTP/1.1\r\nHost: 127.0.0.1\r");
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());
debug_request_parse();
// let mut binmut = BinaryMut::new();
// "aaa".serialize1(&mut binmut);
// let bin = Binary::new();
// let p = Pay::Data(bin);
// println!("bbb = {:?}", p);
// debug_request_parse_full_http2();
// debug_request_parse_http2();
// let req = request::Builder::new()
// .method("POST")
// .body(())
// .unwrap();
// debug_request_parse();
// let v = vec![1u8, 2, 3, 5, 7, 9, 10].into_boxed_slice();
// let mut b = Binary::from(v);
// {
// b.get_next();
// let c = b.clone_slice();
// drop(c);
// b.get_next();
// let d = b.clone_slice();
// drop(d);
// }
// drop(b);
println!("finish");
// let len = v.len();
// let raw = Box::into_raw(v) as *mut u8;
// // Layout::from_size_align(cap, 1);
// let value = unsafe { Vec::from_raw_parts(raw, len, len) };
// println!("value = {:?}", value);
if true {
return;
}
// let mut request = webparse::Request::builder().body("What is this".to_string()).unwrap();
// // let _result = request.parse(b"GET /index.html HTTP/1.1\r\nHost: example.domain\r\n\r\n").unwrap();
// // println!("result = {:?}", request);
// // println!("is_partial = {}", request.is_partial());
// let _result = request.parse(b"GET /index.html HTTP/1.1\r\nHost: example.domain1\r\ncontent-length: 1111\r\n");
// println!("result = {:?}", request);
// println!("is_partial = {}", request.is_partial());
// println!("body len = {}", request.get_body_len());
let url: Result<Url, webparse::WebError> =
Url::try_from("https://%4811:!%2011@www.baidu.com:88/path?aaa=222");
println!("value = {:?}", url);
println!("value = {}", url.ok().unwrap());
let url = Url::try_from("/path?qqq=222");
println!("value = {:?}", url);
println!("value = {}", url.ok().unwrap());
println!("decode = {:?}", Url::url_decode("%48%211111"));
println!("decode = {:?}", Url::url_decode("%48%21111%1"));
println!("decode = {:?}", Url::url_decode("%48%21111%4j"));
let value = Url::try_from("https://11:11@www.baidu.com/path").unwrap();
println!("value = {}", value);
// // let value = url::Url::parse("/path");
// let _result = request.parse(b"GET http://www.baidu.com/ HTTP/1.1\r\nHost: www.baidu.com\r\nUser-Agent: curl/7.74.0\r\nAccept: */*\r\nProxy-Connection: Keep-Alive\r\n\r\n");
// println!("result = {:?}", request);
// println!("is_partial = {}", request.is_partial());
// println!("body len = {}", request.get_body_len());
// println!("host len = {:?}", request.get_host());
// println!("host len = {:?}", request.get_connect_url());
// let mut buffer = Buffer::new();
// request.serialize(&mut buffer).expect("ok");
// println!("aaaaaaaaaaaaaaa {}", String::from_utf8_lossy(buffer.get_write_data()));
// println!("aaaaaaaaaaaaaaa11111 {}", String::from_utf8_lossy(&request.httpdata().unwrap()));
// let mut req = Request::builder();
// assert_eq!(req.url_ref().unwrap(), "/" );
// req = req.url("https://www.rust-lang.org/");
// assert_eq!(req.url_ref().unwrap(), "https://www.rust-lang.org/" );
// let mut req = Request::builder().version(Version::Http2).method("GET")
// .header("Accept", "text/html")
// .header("X-Custom-Foo", "bar");
// {
// let headers = req.headers_mut().unwrap();
// headers["AAAA"] = HeaderValue::Stand("ok");
// let xx = &headers["Accept"];
// let aaa = &headers["AAAA"];
// println!("xxx = {:?}", xx);
// println!("aaa = {:?}", aaa);
// for value in headers.iter() {
// println!("____={:?}", value.0);
// println!("____={:?}", value.1);
// }
// assert_eq!( &headers["Accept"], "text/html" );
// assert_eq!( &headers["X-Custom-Foo"], "bar" );
// }
let req = Request::builder()
.version(Version::Http2)
.method("GET")
.url("/")
.header(":scheme", "http")
.header(":authority", "www.example.com");
{
// let headers = req.headers_mut().unwrap();
// headers["AAAA"] = HeaderValue::Stand("ok");
// let xx = &headers["Accept"];
// let aaa = &headers["AAAA"];
// println!("xxx = {:?}", xx);
// println!("aaa = {:?}", aaa);
// for value in headers.iter() {
// println!("____={:?}", value.0);
// println!("____={:?}", value.1);
// }
// assert_eq!( &headers["Accept"], "text/html" );
// assert_eq!( &headers["X-Custom-Foo"], "bar" );
}
let _rrr = req.body(()).unwrap();
// let data = rrr.http2data().unwrap();
// println!("req.httpdata() = {:?}", hex_debug_print(&data));
// let mut decode = Decoder::new();
// let mut buf = BinaryMut::from(data);
// let result = decode.decode_with_cb(&mut buf, |n, v| {
// println!("n = {:?}, v = {}", n, v);
// });
// let mut index = Arc::new(HeaderIndex::new());
// Arc::get_mut(&mut index).map(|v| {
// v.add_header(
// HeaderName::from_static("aaa"),
// HeaderValue::from_static("aa"),
// );
// });
// let xx = Arc::get_mut(&mut index);
// println!("========={:?}", xx);
// let xx111 = Arc::get_mut(&mut index);
// println!("========={:?}", xx111);
// // rrr.extensions_mut().insert(index);
// // let new = rrr.extensions_mut().get_mut::<Arc<HeaderIndex>>();
// // println!("========={:?}", new);
// // if true {
// // return;
// // }
// let u = url::Builder::new()
// .scheme("https")
// .domain("www.baidu.com")
// .build()
// .unwrap();
// println!("u = {}", u);
// let response = Response::builder()
// .header("Accept", "text/html")
// .header("X-Custom-Foo", "bar")
// .body("my is web")
// .unwrap();
// println!(
// "ssssssssssss {}",
// String::from_utf8_lossy(&response.httpdata().unwrap())
// );
let mut xx = HashMap::<(u32, u8), u8>::new();
xx.insert((48, 5), 6);
// xx.get(&b"xx");
println!("aaa {:?}", xx.get(&(48, 5)));
// let response = url::Builder::
}
source§impl<T> Request<T>where
T: Serialize,
impl<T> Request<T>where
T: Serialize,
pub fn method(&self) -> &Method
pub fn set_method(&mut self, method: Method)
pub fn version(&self) -> Version
pub fn set_version(&mut self, version: Version)
pub fn path(&self) -> &String
pub fn set_path(&mut self, path: String)
pub fn scheme(&self) -> &Scheme
pub fn set_scheme(&mut self, scheme: Scheme)
sourcepub fn headers(&self) -> &HeaderMap
pub fn headers(&self) -> &HeaderMap
Examples found in repository?
examples/demo.rs (line 133)
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
fn debug_request_parse() {
let mut request = Request::new();
request.headers_mut().insert("Connection", "ok");
let _xx = request.headers().is_keep_alive();
return;
// // let value = url::Url::parse("/path");
let _bytes = [
80, 79, 83, 84, 32, 47, 112, 111, 115, 116, 32, 72, 84, 84, 80, 47, 49, 46, 49, 13, 10, 72,
111, 115, 116, 58, 32, 49, 57, 50, 46, 49, 54, 56, 46, 49, 55, 57, 46, 49, 51, 51, 58, 56,
48, 56, 48, 13, 10, 85, 115, 101, 114, 45, 65, 103, 101, 110, 116, 58, 32, 99, 117, 114,
108, 47, 55, 46, 55, 52, 46, 48, 13, 10, 65, 99, 99, 101, 112, 116, 58, 32, 42, 47, 42, 13,
10, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 58, 32, 85, 112, 103, 114, 97, 100,
101, 44, 32, 72, 84, 84, 80, 50, 45, 83, 101, 116, 116, 105, 110, 103, 115, 13, 10, 85,
112, 103, 114, 97, 100, 101, 58, 32, 104, 50, 99, 13, 10, 72, 84, 84, 80, 50, 45, 83, 101,
116, 116, 105, 110, 103, 115, 58, 32, 65, 65, 77, 65, 65, 65, 66, 107, 65, 65, 81, 67, 65,
65, 65, 65, 65, 65, 73, 65, 65, 65, 65, 65, 13, 10, 99, 117, 115, 116, 111, 109, 45, 107,
101, 121, 58, 99, 117, 115, 116, 111, 109, 45, 118, 97, 108, 117, 101, 13, 10, 67, 111,
110, 116, 101, 110, 116, 45, 76, 101, 110, 103, 116, 104, 58, 32, 50, 49, 13, 10, 67, 111,
110, 116, 101, 110, 116, 45, 84, 121, 112, 101, 58, 32, 97, 112, 112, 108, 105, 99, 97,
116, 105, 111, 110, 47, 120, 45, 119, 119, 119, 45, 102, 111, 114, 109, 45, 117, 114, 108,
101, 110, 99, 111, 100, 101, 100, 13, 10, 13, 10, 97, 97, 48, 48, 48, 48, 48, 48, 48, 48,
48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
];
let _result =
request.parse(b"GET //:///// HTTP/1.1\r\nHost: Upgrade, HTTP2-Settings \r\n\r\naaa");
// let _result = request.parse(&bytes);
println!("result = {:?}", request);
println!("is_partial = {}", request.is_partial());
println!("body len = {}", request.get_body_len());
println!("host len = {:?}", request.get_host());
println!("host len = {:?}", request.get_connect_url());
println!(
"http data = {}",
String::from_utf8_lossy(&request.http1_data().unwrap())
);
assert_eq!(
String::from_utf8_lossy(&request.http1_data().unwrap()).as_bytes(),
b"GET //:///// HTTP/1.1\r\nHost: \r\n\r\n"
);
let x = &request.headers()["Host"];
if x == &"foo" {
println!("111");
}
if &"foo" == x {
println!("111");
}
}
sourcepub fn headers_mut(&mut self) -> &mut HeaderMap
pub fn headers_mut(&mut self) -> &mut HeaderMap
Examples found in repository?
examples/demo.rs (line 132)
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
fn debug_request_parse() {
let mut request = Request::new();
request.headers_mut().insert("Connection", "ok");
let _xx = request.headers().is_keep_alive();
return;
// // let value = url::Url::parse("/path");
let _bytes = [
80, 79, 83, 84, 32, 47, 112, 111, 115, 116, 32, 72, 84, 84, 80, 47, 49, 46, 49, 13, 10, 72,
111, 115, 116, 58, 32, 49, 57, 50, 46, 49, 54, 56, 46, 49, 55, 57, 46, 49, 51, 51, 58, 56,
48, 56, 48, 13, 10, 85, 115, 101, 114, 45, 65, 103, 101, 110, 116, 58, 32, 99, 117, 114,
108, 47, 55, 46, 55, 52, 46, 48, 13, 10, 65, 99, 99, 101, 112, 116, 58, 32, 42, 47, 42, 13,
10, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 58, 32, 85, 112, 103, 114, 97, 100,
101, 44, 32, 72, 84, 84, 80, 50, 45, 83, 101, 116, 116, 105, 110, 103, 115, 13, 10, 85,
112, 103, 114, 97, 100, 101, 58, 32, 104, 50, 99, 13, 10, 72, 84, 84, 80, 50, 45, 83, 101,
116, 116, 105, 110, 103, 115, 58, 32, 65, 65, 77, 65, 65, 65, 66, 107, 65, 65, 81, 67, 65,
65, 65, 65, 65, 65, 73, 65, 65, 65, 65, 65, 13, 10, 99, 117, 115, 116, 111, 109, 45, 107,
101, 121, 58, 99, 117, 115, 116, 111, 109, 45, 118, 97, 108, 117, 101, 13, 10, 67, 111,
110, 116, 101, 110, 116, 45, 76, 101, 110, 103, 116, 104, 58, 32, 50, 49, 13, 10, 67, 111,
110, 116, 101, 110, 116, 45, 84, 121, 112, 101, 58, 32, 97, 112, 112, 108, 105, 99, 97,
116, 105, 111, 110, 47, 120, 45, 119, 119, 119, 45, 102, 111, 114, 109, 45, 117, 114, 108,
101, 110, 99, 111, 100, 101, 100, 13, 10, 13, 10, 97, 97, 48, 48, 48, 48, 48, 48, 48, 48,
48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
];
let _result =
request.parse(b"GET //:///// HTTP/1.1\r\nHost: Upgrade, HTTP2-Settings \r\n\r\naaa");
// let _result = request.parse(&bytes);
println!("result = {:?}", request);
println!("is_partial = {}", request.is_partial());
println!("body len = {}", request.get_body_len());
println!("host len = {:?}", request.get_host());
println!("host len = {:?}", request.get_connect_url());
println!(
"http data = {}",
String::from_utf8_lossy(&request.http1_data().unwrap())
);
assert_eq!(
String::from_utf8_lossy(&request.http1_data().unwrap()).as_bytes(),
b"GET //:///// HTTP/1.1\r\nHost: \r\n\r\n"
);
let x = &request.headers()["Host"];
if x == &"foo" {
println!("111");
}
if &"foo" == x {
println!("111");
}
}
pub fn headers_body(&mut self) -> (&HeaderMap, &T)
pub fn headers_body_mut(&mut self) -> (&mut HeaderMap, &mut T)
pub fn url(&self) -> &Url
sourcepub fn get_host(&self) -> Option<String>
pub fn get_host(&self) -> Option<String>
Examples found in repository?
examples/demo.rs (line 160)
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
fn debug_request_parse() {
let mut request = Request::new();
request.headers_mut().insert("Connection", "ok");
let _xx = request.headers().is_keep_alive();
return;
// // let value = url::Url::parse("/path");
let _bytes = [
80, 79, 83, 84, 32, 47, 112, 111, 115, 116, 32, 72, 84, 84, 80, 47, 49, 46, 49, 13, 10, 72,
111, 115, 116, 58, 32, 49, 57, 50, 46, 49, 54, 56, 46, 49, 55, 57, 46, 49, 51, 51, 58, 56,
48, 56, 48, 13, 10, 85, 115, 101, 114, 45, 65, 103, 101, 110, 116, 58, 32, 99, 117, 114,
108, 47, 55, 46, 55, 52, 46, 48, 13, 10, 65, 99, 99, 101, 112, 116, 58, 32, 42, 47, 42, 13,
10, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 58, 32, 85, 112, 103, 114, 97, 100,
101, 44, 32, 72, 84, 84, 80, 50, 45, 83, 101, 116, 116, 105, 110, 103, 115, 13, 10, 85,
112, 103, 114, 97, 100, 101, 58, 32, 104, 50, 99, 13, 10, 72, 84, 84, 80, 50, 45, 83, 101,
116, 116, 105, 110, 103, 115, 58, 32, 65, 65, 77, 65, 65, 65, 66, 107, 65, 65, 81, 67, 65,
65, 65, 65, 65, 65, 73, 65, 65, 65, 65, 65, 13, 10, 99, 117, 115, 116, 111, 109, 45, 107,
101, 121, 58, 99, 117, 115, 116, 111, 109, 45, 118, 97, 108, 117, 101, 13, 10, 67, 111,
110, 116, 101, 110, 116, 45, 76, 101, 110, 103, 116, 104, 58, 32, 50, 49, 13, 10, 67, 111,
110, 116, 101, 110, 116, 45, 84, 121, 112, 101, 58, 32, 97, 112, 112, 108, 105, 99, 97,
116, 105, 111, 110, 47, 120, 45, 119, 119, 119, 45, 102, 111, 114, 109, 45, 117, 114, 108,
101, 110, 99, 111, 100, 101, 100, 13, 10, 13, 10, 97, 97, 48, 48, 48, 48, 48, 48, 48, 48,
48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
];
let _result =
request.parse(b"GET //:///// HTTP/1.1\r\nHost: Upgrade, HTTP2-Settings \r\n\r\naaa");
// let _result = request.parse(&bytes);
println!("result = {:?}", request);
println!("is_partial = {}", request.is_partial());
println!("body len = {}", request.get_body_len());
println!("host len = {:?}", request.get_host());
println!("host len = {:?}", request.get_connect_url());
println!(
"http data = {}",
String::from_utf8_lossy(&request.http1_data().unwrap())
);
assert_eq!(
String::from_utf8_lossy(&request.http1_data().unwrap()).as_bytes(),
b"GET //:///// HTTP/1.1\r\nHost: \r\n\r\n"
);
let x = &request.headers()["Host"];
if x == &"foo" {
println!("111");
}
if &"foo" == x {
println!("111");
}
}
pub fn get_referer(&self) -> Option<String>
pub fn get_user_agent(&self) -> Option<String>
sourcepub fn get_connect_url(&self) -> Option<String>
pub fn get_connect_url(&self) -> Option<String>
返回完整的域名加上端口号信息 如wwww.baidu.com:80, wwww.google.com:443
Examples found in repository?
examples/demo.rs (line 161)
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
fn debug_request_parse() {
let mut request = Request::new();
request.headers_mut().insert("Connection", "ok");
let _xx = request.headers().is_keep_alive();
return;
// // let value = url::Url::parse("/path");
let _bytes = [
80, 79, 83, 84, 32, 47, 112, 111, 115, 116, 32, 72, 84, 84, 80, 47, 49, 46, 49, 13, 10, 72,
111, 115, 116, 58, 32, 49, 57, 50, 46, 49, 54, 56, 46, 49, 55, 57, 46, 49, 51, 51, 58, 56,
48, 56, 48, 13, 10, 85, 115, 101, 114, 45, 65, 103, 101, 110, 116, 58, 32, 99, 117, 114,
108, 47, 55, 46, 55, 52, 46, 48, 13, 10, 65, 99, 99, 101, 112, 116, 58, 32, 42, 47, 42, 13,
10, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 58, 32, 85, 112, 103, 114, 97, 100,
101, 44, 32, 72, 84, 84, 80, 50, 45, 83, 101, 116, 116, 105, 110, 103, 115, 13, 10, 85,
112, 103, 114, 97, 100, 101, 58, 32, 104, 50, 99, 13, 10, 72, 84, 84, 80, 50, 45, 83, 101,
116, 116, 105, 110, 103, 115, 58, 32, 65, 65, 77, 65, 65, 65, 66, 107, 65, 65, 81, 67, 65,
65, 65, 65, 65, 65, 73, 65, 65, 65, 65, 65, 13, 10, 99, 117, 115, 116, 111, 109, 45, 107,
101, 121, 58, 99, 117, 115, 116, 111, 109, 45, 118, 97, 108, 117, 101, 13, 10, 67, 111,
110, 116, 101, 110, 116, 45, 76, 101, 110, 103, 116, 104, 58, 32, 50, 49, 13, 10, 67, 111,
110, 116, 101, 110, 116, 45, 84, 121, 112, 101, 58, 32, 97, 112, 112, 108, 105, 99, 97,
116, 105, 111, 110, 47, 120, 45, 119, 119, 119, 45, 102, 111, 114, 109, 45, 117, 114, 108,
101, 110, 99, 111, 100, 101, 100, 13, 10, 13, 10, 97, 97, 48, 48, 48, 48, 48, 48, 48, 48,
48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
];
let _result =
request.parse(b"GET //:///// HTTP/1.1\r\nHost: Upgrade, HTTP2-Settings \r\n\r\naaa");
// let _result = request.parse(&bytes);
println!("result = {:?}", request);
println!("is_partial = {}", request.is_partial());
println!("body len = {}", request.get_body_len());
println!("host len = {:?}", request.get_host());
println!("host len = {:?}", request.get_connect_url());
println!(
"http data = {}",
String::from_utf8_lossy(&request.http1_data().unwrap())
);
assert_eq!(
String::from_utf8_lossy(&request.http1_data().unwrap()).as_bytes(),
b"GET //:///// HTTP/1.1\r\nHost: \r\n\r\n"
);
let x = &request.headers()["Host"];
if x == &"foo" {
println!("111");
}
if &"foo" == x {
println!("111");
}
}
sourcepub fn get_body_len(&self) -> isize
pub fn get_body_len(&self) -> isize
获取请求的body长度, 如果为0则表示不存在长度信息, 直到收到关闭信息则表示结束, http/1.1为关闭链接, http/2则是end_stream
Examples found in repository?
examples/demo.rs (line 159)
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
fn debug_request_parse() {
let mut request = Request::new();
request.headers_mut().insert("Connection", "ok");
let _xx = request.headers().is_keep_alive();
return;
// // let value = url::Url::parse("/path");
let _bytes = [
80, 79, 83, 84, 32, 47, 112, 111, 115, 116, 32, 72, 84, 84, 80, 47, 49, 46, 49, 13, 10, 72,
111, 115, 116, 58, 32, 49, 57, 50, 46, 49, 54, 56, 46, 49, 55, 57, 46, 49, 51, 51, 58, 56,
48, 56, 48, 13, 10, 85, 115, 101, 114, 45, 65, 103, 101, 110, 116, 58, 32, 99, 117, 114,
108, 47, 55, 46, 55, 52, 46, 48, 13, 10, 65, 99, 99, 101, 112, 116, 58, 32, 42, 47, 42, 13,
10, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 58, 32, 85, 112, 103, 114, 97, 100,
101, 44, 32, 72, 84, 84, 80, 50, 45, 83, 101, 116, 116, 105, 110, 103, 115, 13, 10, 85,
112, 103, 114, 97, 100, 101, 58, 32, 104, 50, 99, 13, 10, 72, 84, 84, 80, 50, 45, 83, 101,
116, 116, 105, 110, 103, 115, 58, 32, 65, 65, 77, 65, 65, 65, 66, 107, 65, 65, 81, 67, 65,
65, 65, 65, 65, 65, 73, 65, 65, 65, 65, 65, 13, 10, 99, 117, 115, 116, 111, 109, 45, 107,
101, 121, 58, 99, 117, 115, 116, 111, 109, 45, 118, 97, 108, 117, 101, 13, 10, 67, 111,
110, 116, 101, 110, 116, 45, 76, 101, 110, 103, 116, 104, 58, 32, 50, 49, 13, 10, 67, 111,
110, 116, 101, 110, 116, 45, 84, 121, 112, 101, 58, 32, 97, 112, 112, 108, 105, 99, 97,
116, 105, 111, 110, 47, 120, 45, 119, 119, 119, 45, 102, 111, 114, 109, 45, 117, 114, 108,
101, 110, 99, 111, 100, 101, 100, 13, 10, 13, 10, 97, 97, 48, 48, 48, 48, 48, 48, 48, 48,
48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
];
let _result =
request.parse(b"GET //:///// HTTP/1.1\r\nHost: Upgrade, HTTP2-Settings \r\n\r\naaa");
// let _result = request.parse(&bytes);
println!("result = {:?}", request);
println!("is_partial = {}", request.is_partial());
println!("body len = {}", request.get_body_len());
println!("host len = {:?}", request.get_host());
println!("host len = {:?}", request.get_connect_url());
println!(
"http data = {}",
String::from_utf8_lossy(&request.http1_data().unwrap())
);
assert_eq!(
String::from_utf8_lossy(&request.http1_data().unwrap()).as_bytes(),
b"GET //:///// HTTP/1.1\r\nHost: \r\n\r\n"
);
let x = &request.headers()["Host"];
if x == &"foo" {
println!("111");
}
if &"foo" == x {
println!("111");
}
}
获取请求的authority
sourcepub fn get_scheme(&self) -> String
pub fn get_scheme(&self) -> String
获取请求的scheme
sourcepub fn is_keep_alive(&self) -> bool
pub fn is_keep_alive(&self) -> bool
是否保持心跳活跃
sourcepub fn is_partial(&self) -> bool
pub fn is_partial(&self) -> bool
Examples found in repository?
examples/demo.rs (line 158)
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
fn debug_request_parse() {
let mut request = Request::new();
request.headers_mut().insert("Connection", "ok");
let _xx = request.headers().is_keep_alive();
return;
// // let value = url::Url::parse("/path");
let _bytes = [
80, 79, 83, 84, 32, 47, 112, 111, 115, 116, 32, 72, 84, 84, 80, 47, 49, 46, 49, 13, 10, 72,
111, 115, 116, 58, 32, 49, 57, 50, 46, 49, 54, 56, 46, 49, 55, 57, 46, 49, 51, 51, 58, 56,
48, 56, 48, 13, 10, 85, 115, 101, 114, 45, 65, 103, 101, 110, 116, 58, 32, 99, 117, 114,
108, 47, 55, 46, 55, 52, 46, 48, 13, 10, 65, 99, 99, 101, 112, 116, 58, 32, 42, 47, 42, 13,
10, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 58, 32, 85, 112, 103, 114, 97, 100,
101, 44, 32, 72, 84, 84, 80, 50, 45, 83, 101, 116, 116, 105, 110, 103, 115, 13, 10, 85,
112, 103, 114, 97, 100, 101, 58, 32, 104, 50, 99, 13, 10, 72, 84, 84, 80, 50, 45, 83, 101,
116, 116, 105, 110, 103, 115, 58, 32, 65, 65, 77, 65, 65, 65, 66, 107, 65, 65, 81, 67, 65,
65, 65, 65, 65, 65, 73, 65, 65, 65, 65, 65, 13, 10, 99, 117, 115, 116, 111, 109, 45, 107,
101, 121, 58, 99, 117, 115, 116, 111, 109, 45, 118, 97, 108, 117, 101, 13, 10, 67, 111,
110, 116, 101, 110, 116, 45, 76, 101, 110, 103, 116, 104, 58, 32, 50, 49, 13, 10, 67, 111,
110, 116, 101, 110, 116, 45, 84, 121, 112, 101, 58, 32, 97, 112, 112, 108, 105, 99, 97,
116, 105, 111, 110, 47, 120, 45, 119, 119, 119, 45, 102, 111, 114, 109, 45, 117, 114, 108,
101, 110, 99, 111, 100, 101, 100, 13, 10, 13, 10, 97, 97, 48, 48, 48, 48, 48, 48, 48, 48,
48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
];
let _result =
request.parse(b"GET //:///// HTTP/1.1\r\nHost: Upgrade, HTTP2-Settings \r\n\r\naaa");
// let _result = request.parse(&bytes);
println!("result = {:?}", request);
println!("is_partial = {}", request.is_partial());
println!("body len = {}", request.get_body_len());
println!("host len = {:?}", request.get_host());
println!("host len = {:?}", request.get_connect_url());
println!(
"http data = {}",
String::from_utf8_lossy(&request.http1_data().unwrap())
);
assert_eq!(
String::from_utf8_lossy(&request.http1_data().unwrap()).as_bytes(),
b"GET //:///// HTTP/1.1\r\nHost: \r\n\r\n"
);
let x = &request.headers()["Host"];
if x == &"foo" {
println!("111");
}
if &"foo" == x {
println!("111");
}
}
sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
Examples found in repository?
examples/demo.rs (line 188)
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
fn main() {
let mut req = crate::Request::new();
let ret = req.parse(b"GET / HTTP/1.1\r\nHost: 127.0.0.1\r");
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());
debug_request_parse();
// let mut binmut = BinaryMut::new();
// "aaa".serialize1(&mut binmut);
// let bin = Binary::new();
// let p = Pay::Data(bin);
// println!("bbb = {:?}", p);
// debug_request_parse_full_http2();
// debug_request_parse_http2();
// let req = request::Builder::new()
// .method("POST")
// .body(())
// .unwrap();
// debug_request_parse();
// let v = vec![1u8, 2, 3, 5, 7, 9, 10].into_boxed_slice();
// let mut b = Binary::from(v);
// {
// b.get_next();
// let c = b.clone_slice();
// drop(c);
// b.get_next();
// let d = b.clone_slice();
// drop(d);
// }
// drop(b);
println!("finish");
// let len = v.len();
// let raw = Box::into_raw(v) as *mut u8;
// // Layout::from_size_align(cap, 1);
// let value = unsafe { Vec::from_raw_parts(raw, len, len) };
// println!("value = {:?}", value);
if true {
return;
}
// let mut request = webparse::Request::builder().body("What is this".to_string()).unwrap();
// // let _result = request.parse(b"GET /index.html HTTP/1.1\r\nHost: example.domain\r\n\r\n").unwrap();
// // println!("result = {:?}", request);
// // println!("is_partial = {}", request.is_partial());
// let _result = request.parse(b"GET /index.html HTTP/1.1\r\nHost: example.domain1\r\ncontent-length: 1111\r\n");
// println!("result = {:?}", request);
// println!("is_partial = {}", request.is_partial());
// println!("body len = {}", request.get_body_len());
let url: Result<Url, webparse::WebError> =
Url::try_from("https://%4811:!%2011@www.baidu.com:88/path?aaa=222");
println!("value = {:?}", url);
println!("value = {}", url.ok().unwrap());
let url = Url::try_from("/path?qqq=222");
println!("value = {:?}", url);
println!("value = {}", url.ok().unwrap());
println!("decode = {:?}", Url::url_decode("%48%211111"));
println!("decode = {:?}", Url::url_decode("%48%21111%1"));
println!("decode = {:?}", Url::url_decode("%48%21111%4j"));
let value = Url::try_from("https://11:11@www.baidu.com/path").unwrap();
println!("value = {}", value);
// // let value = url::Url::parse("/path");
// let _result = request.parse(b"GET http://www.baidu.com/ HTTP/1.1\r\nHost: www.baidu.com\r\nUser-Agent: curl/7.74.0\r\nAccept: */*\r\nProxy-Connection: Keep-Alive\r\n\r\n");
// println!("result = {:?}", request);
// println!("is_partial = {}", request.is_partial());
// println!("body len = {}", request.get_body_len());
// println!("host len = {:?}", request.get_host());
// println!("host len = {:?}", request.get_connect_url());
// let mut buffer = Buffer::new();
// request.serialize(&mut buffer).expect("ok");
// println!("aaaaaaaaaaaaaaa {}", String::from_utf8_lossy(buffer.get_write_data()));
// println!("aaaaaaaaaaaaaaa11111 {}", String::from_utf8_lossy(&request.httpdata().unwrap()));
// let mut req = Request::builder();
// assert_eq!(req.url_ref().unwrap(), "/" );
// req = req.url("https://www.rust-lang.org/");
// assert_eq!(req.url_ref().unwrap(), "https://www.rust-lang.org/" );
// let mut req = Request::builder().version(Version::Http2).method("GET")
// .header("Accept", "text/html")
// .header("X-Custom-Foo", "bar");
// {
// let headers = req.headers_mut().unwrap();
// headers["AAAA"] = HeaderValue::Stand("ok");
// let xx = &headers["Accept"];
// let aaa = &headers["AAAA"];
// println!("xxx = {:?}", xx);
// println!("aaa = {:?}", aaa);
// for value in headers.iter() {
// println!("____={:?}", value.0);
// println!("____={:?}", value.1);
// }
// assert_eq!( &headers["Accept"], "text/html" );
// assert_eq!( &headers["X-Custom-Foo"], "bar" );
// }
let req = Request::builder()
.version(Version::Http2)
.method("GET")
.url("/")
.header(":scheme", "http")
.header(":authority", "www.example.com");
{
// let headers = req.headers_mut().unwrap();
// headers["AAAA"] = HeaderValue::Stand("ok");
// let xx = &headers["Accept"];
// let aaa = &headers["AAAA"];
// println!("xxx = {:?}", xx);
// println!("aaa = {:?}", aaa);
// for value in headers.iter() {
// println!("____={:?}", value.0);
// println!("____={:?}", value.1);
// }
// assert_eq!( &headers["Accept"], "text/html" );
// assert_eq!( &headers["X-Custom-Foo"], "bar" );
}
let _rrr = req.body(()).unwrap();
// let data = rrr.http2data().unwrap();
// println!("req.httpdata() = {:?}", hex_debug_print(&data));
// let mut decode = Decoder::new();
// let mut buf = BinaryMut::from(data);
// let result = decode.decode_with_cb(&mut buf, |n, v| {
// println!("n = {:?}, v = {}", n, v);
// });
// let mut index = Arc::new(HeaderIndex::new());
// Arc::get_mut(&mut index).map(|v| {
// v.add_header(
// HeaderName::from_static("aaa"),
// HeaderValue::from_static("aa"),
// );
// });
// let xx = Arc::get_mut(&mut index);
// println!("========={:?}", xx);
// let xx111 = Arc::get_mut(&mut index);
// println!("========={:?}", xx111);
// // rrr.extensions_mut().insert(index);
// // let new = rrr.extensions_mut().get_mut::<Arc<HeaderIndex>>();
// // println!("========={:?}", new);
// // if true {
// // return;
// // }
// let u = url::Builder::new()
// .scheme("https")
// .domain("www.baidu.com")
// .build()
// .unwrap();
// println!("u = {}", u);
// let response = Response::builder()
// .header("Accept", "text/html")
// .header("X-Custom-Foo", "bar")
// .body("my is web")
// .unwrap();
// println!(
// "ssssssssssss {}",
// String::from_utf8_lossy(&response.httpdata().unwrap())
// );
let mut xx = HashMap::<(u32, u8), u8>::new();
xx.insert((48, 5), 6);
// xx.get(&b"xx");
println!("aaa {:?}", xx.get(&(48, 5)));
// let response = url::Builder::
}
pub fn into<B: Serialize>(self, body: B) -> (Request<B>, T)
pub fn into_type<B: From<T> + Serialize>(self) -> Request<B>
pub fn parse_buffer<B: Bt>(&mut self, buffer: &mut B) -> WebResult<usize>
sourcepub fn parse(&mut self, buf: &[u8]) -> WebResult<usize>
pub fn parse(&mut self, buf: &[u8]) -> WebResult<usize>
Examples found in repository?
examples/demo.rs (line 81)
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
fn debug_request_parse_full_http2() {
let http2: Vec<u8> = vec![
80, 82, 73, 32, 42, 32, 72, 84, 84, 80, 47, 50, 46, 48, 13, 10, 13, 10, 83, 77, 13, 10, 13,
10, 0, 0, 18, 4, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 100, 0, 4, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0,
0, 4, 8, 0, 0, 0, 0, 0, 1, 255, 0, 1, 0, 0, 55, 1, 5, 0, 0, 0, 1, 131, 132, 134, 65, 143,
11, 226, 92, 46, 60, 184, 93, 125, 112, 178, 205, 199, 128, 240, 63, 122, 136, 37, 182, 80,
195, 171, 186, 210, 224, 83, 3, 42, 47, 42, 64, 136, 37, 168, 73, 233, 91, 169, 125, 127,
137, 37, 168, 73, 233, 91, 184, 232, 180, 191, 0, 0, 25, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 83, 69, 84, 84, 73, 78, 71, 83, 32, 101, 120, 112, 101, 99, 116, 101, 100,
];
let mut req = Request::new();
let _size = req.parse(&http2).unwrap();
println!("req = {:?}", req);
}
// fn debug_request_parse_http2() {
// let mut decode = Decoder::new();
// let _http2 = vec![
// 0x82, 0x86, 0x84, 0x41, 0x8c, 0xf1, 0xe3, 0xc2, 0xe5, 0xf2, 0x3a, 0x6b, 0xa0, 0xab, 0x90,
// 0xf4, 0xff,
// ];
// let http2 = hexstr_to_vec("8286 8441 0f77 7777 2e65 7861 6d70 6c65 2e63 6f6d ");
// let mut buf = BinaryMut::from(http2);
// let _result = decode.decode_with_cb(&mut buf, |n, v| {
// println!("n = {:?}, v = {:?}", n, v);
// });
// // println!("result = {:?}", result);
// // let http2 = vec![
// // 0x82, 0x86, 0x84, 0xbe, 0x58, 0x08, 0x6e, 0x6f, 0x2d, 0x63, 0x61, 0x63, 0x68, 0x65,
// // ];
// // let http2 = hexstr_to_vec("8286 84be 5808 6e6f 2d63 6163 6865");
// // let mut buf = BinaryMut::from(http2);
// // let result = decode.decode_with_cb(&mut buf, |n, v| {
// // println!("n = {:?}, v = {:?}", n, v);
// // });
// // println!("result = {:?}", result);
// // {
// // // 8287 85bf 4088 25a8 49e9 5ba9 7d7f 8925 | ....@.%.I.[.}..%
// // // a849 e95b b8e8 b4bf
// // let http2 = vec![
// // 0x82, 0x87, 0x85, 0xbf, 0x40, 0x88, 0x25, 0xa8, 0x49, 0xe9, 0x5b, 0xa9, 0x7d, 0x7f,
// // 0x89, 0x25, 0xa8, 0x49, 0xe9, 0x5b, 0xb8, 0xe8, 0xb4, 0xbf,
// // ];
// // let http2 = hexstr_to_vec(
// // "8287 85bf 400a 6375 7374 6f6d 2d6b 6579 0c63 7573 746f 6d2d 7661 6c75 65",
// // );
// // let mut buf = BinaryMut::from(http2);
// // let result = decode.decode_with_cb(&mut buf, |n, v| {
// // println!("n = {:?}, v = {:?}", n, v);
// // });
// // println!("result = {:?}", result);
// // }
// }
fn debug_request_parse() {
let mut request = Request::new();
request.headers_mut().insert("Connection", "ok");
let _xx = request.headers().is_keep_alive();
return;
// // let value = url::Url::parse("/path");
let _bytes = [
80, 79, 83, 84, 32, 47, 112, 111, 115, 116, 32, 72, 84, 84, 80, 47, 49, 46, 49, 13, 10, 72,
111, 115, 116, 58, 32, 49, 57, 50, 46, 49, 54, 56, 46, 49, 55, 57, 46, 49, 51, 51, 58, 56,
48, 56, 48, 13, 10, 85, 115, 101, 114, 45, 65, 103, 101, 110, 116, 58, 32, 99, 117, 114,
108, 47, 55, 46, 55, 52, 46, 48, 13, 10, 65, 99, 99, 101, 112, 116, 58, 32, 42, 47, 42, 13,
10, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 58, 32, 85, 112, 103, 114, 97, 100,
101, 44, 32, 72, 84, 84, 80, 50, 45, 83, 101, 116, 116, 105, 110, 103, 115, 13, 10, 85,
112, 103, 114, 97, 100, 101, 58, 32, 104, 50, 99, 13, 10, 72, 84, 84, 80, 50, 45, 83, 101,
116, 116, 105, 110, 103, 115, 58, 32, 65, 65, 77, 65, 65, 65, 66, 107, 65, 65, 81, 67, 65,
65, 65, 65, 65, 65, 73, 65, 65, 65, 65, 65, 13, 10, 99, 117, 115, 116, 111, 109, 45, 107,
101, 121, 58, 99, 117, 115, 116, 111, 109, 45, 118, 97, 108, 117, 101, 13, 10, 67, 111,
110, 116, 101, 110, 116, 45, 76, 101, 110, 103, 116, 104, 58, 32, 50, 49, 13, 10, 67, 111,
110, 116, 101, 110, 116, 45, 84, 121, 112, 101, 58, 32, 97, 112, 112, 108, 105, 99, 97,
116, 105, 111, 110, 47, 120, 45, 119, 119, 119, 45, 102, 111, 114, 109, 45, 117, 114, 108,
101, 110, 99, 111, 100, 101, 100, 13, 10, 13, 10, 97, 97, 48, 48, 48, 48, 48, 48, 48, 48,
48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
];
let _result =
request.parse(b"GET //:///// HTTP/1.1\r\nHost: Upgrade, HTTP2-Settings \r\n\r\naaa");
// let _result = request.parse(&bytes);
println!("result = {:?}", request);
println!("is_partial = {}", request.is_partial());
println!("body len = {}", request.get_body_len());
println!("host len = {:?}", request.get_host());
println!("host len = {:?}", request.get_connect_url());
println!(
"http data = {}",
String::from_utf8_lossy(&request.http1_data().unwrap())
);
assert_eq!(
String::from_utf8_lossy(&request.http1_data().unwrap()).as_bytes(),
b"GET //:///// HTTP/1.1\r\nHost: \r\n\r\n"
);
let x = &request.headers()["Host"];
if x == &"foo" {
println!("111");
}
if &"foo" == x {
println!("111");
}
}
fn main() {
let mut req = crate::Request::new();
let ret = req.parse(b"GET / HTTP/1.1\r\nHost: 127.0.0.1\r");
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());
debug_request_parse();
// let mut binmut = BinaryMut::new();
// "aaa".serialize1(&mut binmut);
// let bin = Binary::new();
// let p = Pay::Data(bin);
// println!("bbb = {:?}", p);
// debug_request_parse_full_http2();
// debug_request_parse_http2();
// let req = request::Builder::new()
// .method("POST")
// .body(())
// .unwrap();
// debug_request_parse();
// let v = vec![1u8, 2, 3, 5, 7, 9, 10].into_boxed_slice();
// let mut b = Binary::from(v);
// {
// b.get_next();
// let c = b.clone_slice();
// drop(c);
// b.get_next();
// let d = b.clone_slice();
// drop(d);
// }
// drop(b);
println!("finish");
// let len = v.len();
// let raw = Box::into_raw(v) as *mut u8;
// // Layout::from_size_align(cap, 1);
// let value = unsafe { Vec::from_raw_parts(raw, len, len) };
// println!("value = {:?}", value);
if true {
return;
}
// let mut request = webparse::Request::builder().body("What is this".to_string()).unwrap();
// // let _result = request.parse(b"GET /index.html HTTP/1.1\r\nHost: example.domain\r\n\r\n").unwrap();
// // println!("result = {:?}", request);
// // println!("is_partial = {}", request.is_partial());
// let _result = request.parse(b"GET /index.html HTTP/1.1\r\nHost: example.domain1\r\ncontent-length: 1111\r\n");
// println!("result = {:?}", request);
// println!("is_partial = {}", request.is_partial());
// println!("body len = {}", request.get_body_len());
let url: Result<Url, webparse::WebError> =
Url::try_from("https://%4811:!%2011@www.baidu.com:88/path?aaa=222");
println!("value = {:?}", url);
println!("value = {}", url.ok().unwrap());
let url = Url::try_from("/path?qqq=222");
println!("value = {:?}", url);
println!("value = {}", url.ok().unwrap());
println!("decode = {:?}", Url::url_decode("%48%211111"));
println!("decode = {:?}", Url::url_decode("%48%21111%1"));
println!("decode = {:?}", Url::url_decode("%48%21111%4j"));
let value = Url::try_from("https://11:11@www.baidu.com/path").unwrap();
println!("value = {}", value);
// // let value = url::Url::parse("/path");
// let _result = request.parse(b"GET http://www.baidu.com/ HTTP/1.1\r\nHost: www.baidu.com\r\nUser-Agent: curl/7.74.0\r\nAccept: */*\r\nProxy-Connection: Keep-Alive\r\n\r\n");
// println!("result = {:?}", request);
// println!("is_partial = {}", request.is_partial());
// println!("body len = {}", request.get_body_len());
// println!("host len = {:?}", request.get_host());
// println!("host len = {:?}", request.get_connect_url());
// let mut buffer = Buffer::new();
// request.serialize(&mut buffer).expect("ok");
// println!("aaaaaaaaaaaaaaa {}", String::from_utf8_lossy(buffer.get_write_data()));
// println!("aaaaaaaaaaaaaaa11111 {}", String::from_utf8_lossy(&request.httpdata().unwrap()));
// let mut req = Request::builder();
// assert_eq!(req.url_ref().unwrap(), "/" );
// req = req.url("https://www.rust-lang.org/");
// assert_eq!(req.url_ref().unwrap(), "https://www.rust-lang.org/" );
// let mut req = Request::builder().version(Version::Http2).method("GET")
// .header("Accept", "text/html")
// .header("X-Custom-Foo", "bar");
// {
// let headers = req.headers_mut().unwrap();
// headers["AAAA"] = HeaderValue::Stand("ok");
// let xx = &headers["Accept"];
// let aaa = &headers["AAAA"];
// println!("xxx = {:?}", xx);
// println!("aaa = {:?}", aaa);
// for value in headers.iter() {
// println!("____={:?}", value.0);
// println!("____={:?}", value.1);
// }
// assert_eq!( &headers["Accept"], "text/html" );
// assert_eq!( &headers["X-Custom-Foo"], "bar" );
// }
let req = Request::builder()
.version(Version::Http2)
.method("GET")
.url("/")
.header(":scheme", "http")
.header(":authority", "www.example.com");
{
// let headers = req.headers_mut().unwrap();
// headers["AAAA"] = HeaderValue::Stand("ok");
// let xx = &headers["Accept"];
// let aaa = &headers["AAAA"];
// println!("xxx = {:?}", xx);
// println!("aaa = {:?}", aaa);
// for value in headers.iter() {
// println!("____={:?}", value.0);
// println!("____={:?}", value.1);
// }
// assert_eq!( &headers["Accept"], "text/html" );
// assert_eq!( &headers["X-Custom-Foo"], "bar" );
}
let _rrr = req.body(()).unwrap();
// let data = rrr.http2data().unwrap();
// println!("req.httpdata() = {:?}", hex_debug_print(&data));
// let mut decode = Decoder::new();
// let mut buf = BinaryMut::from(data);
// let result = decode.decode_with_cb(&mut buf, |n, v| {
// println!("n = {:?}, v = {}", n, v);
// });
// let mut index = Arc::new(HeaderIndex::new());
// Arc::get_mut(&mut index).map(|v| {
// v.add_header(
// HeaderName::from_static("aaa"),
// HeaderValue::from_static("aa"),
// );
// });
// let xx = Arc::get_mut(&mut index);
// println!("========={:?}", xx);
// let xx111 = Arc::get_mut(&mut index);
// println!("========={:?}", xx111);
// // rrr.extensions_mut().insert(index);
// // let new = rrr.extensions_mut().get_mut::<Arc<HeaderIndex>>();
// // println!("========={:?}", new);
// // if true {
// // return;
// // }
// let u = url::Builder::new()
// .scheme("https")
// .domain("www.baidu.com")
// .build()
// .unwrap();
// println!("u = {}", u);
// let response = Response::builder()
// .header("Accept", "text/html")
// .header("X-Custom-Foo", "bar")
// .body("my is web")
// .unwrap();
// println!(
// "ssssssssssss {}",
// String::from_utf8_lossy(&response.httpdata().unwrap())
// );
let mut xx = HashMap::<(u32, u8), u8>::new();
xx.insert((48, 5), 6);
// xx.get(&b"xx");
println!("aaa {:?}", xx.get(&(48, 5)));
// let response = url::Builder::
}
sourcepub fn extensions(&self) -> &Extensions
pub fn extensions(&self) -> &Extensions
Returns a reference to the associated extensions.
§Examples
use webparse::*;
let request: Request<()> = Request::default();
assert!(request.extensions().get::<i32>().is_none());
pub fn extensions_mut(&mut self) -> &mut Extensions
sourcepub fn http1_data(&mut self) -> WebResult<Vec<u8>>
pub fn http1_data(&mut self) -> WebResult<Vec<u8>>
Examples found in repository?
examples/demo.rs (line 164)
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
fn debug_request_parse() {
let mut request = Request::new();
request.headers_mut().insert("Connection", "ok");
let _xx = request.headers().is_keep_alive();
return;
// // let value = url::Url::parse("/path");
let _bytes = [
80, 79, 83, 84, 32, 47, 112, 111, 115, 116, 32, 72, 84, 84, 80, 47, 49, 46, 49, 13, 10, 72,
111, 115, 116, 58, 32, 49, 57, 50, 46, 49, 54, 56, 46, 49, 55, 57, 46, 49, 51, 51, 58, 56,
48, 56, 48, 13, 10, 85, 115, 101, 114, 45, 65, 103, 101, 110, 116, 58, 32, 99, 117, 114,
108, 47, 55, 46, 55, 52, 46, 48, 13, 10, 65, 99, 99, 101, 112, 116, 58, 32, 42, 47, 42, 13,
10, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 58, 32, 85, 112, 103, 114, 97, 100,
101, 44, 32, 72, 84, 84, 80, 50, 45, 83, 101, 116, 116, 105, 110, 103, 115, 13, 10, 85,
112, 103, 114, 97, 100, 101, 58, 32, 104, 50, 99, 13, 10, 72, 84, 84, 80, 50, 45, 83, 101,
116, 116, 105, 110, 103, 115, 58, 32, 65, 65, 77, 65, 65, 65, 66, 107, 65, 65, 81, 67, 65,
65, 65, 65, 65, 65, 73, 65, 65, 65, 65, 65, 13, 10, 99, 117, 115, 116, 111, 109, 45, 107,
101, 121, 58, 99, 117, 115, 116, 111, 109, 45, 118, 97, 108, 117, 101, 13, 10, 67, 111,
110, 116, 101, 110, 116, 45, 76, 101, 110, 103, 116, 104, 58, 32, 50, 49, 13, 10, 67, 111,
110, 116, 101, 110, 116, 45, 84, 121, 112, 101, 58, 32, 97, 112, 112, 108, 105, 99, 97,
116, 105, 111, 110, 47, 120, 45, 119, 119, 119, 45, 102, 111, 114, 109, 45, 117, 114, 108,
101, 110, 99, 111, 100, 101, 100, 13, 10, 13, 10, 97, 97, 48, 48, 48, 48, 48, 48, 48, 48,
48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
];
let _result =
request.parse(b"GET //:///// HTTP/1.1\r\nHost: Upgrade, HTTP2-Settings \r\n\r\naaa");
// let _result = request.parse(&bytes);
println!("result = {:?}", request);
println!("is_partial = {}", request.is_partial());
println!("body len = {}", request.get_body_len());
println!("host len = {:?}", request.get_host());
println!("host len = {:?}", request.get_connect_url());
println!(
"http data = {}",
String::from_utf8_lossy(&request.http1_data().unwrap())
);
assert_eq!(
String::from_utf8_lossy(&request.http1_data().unwrap()).as_bytes(),
b"GET //:///// HTTP/1.1\r\nHost: \r\n\r\n"
);
let x = &request.headers()["Host"];
if x == &"foo" {
println!("111");
}
if &"foo" == x {
println!("111");
}
}
pub fn body(&self) -> &T
pub fn body_mut(&mut self) -> &mut T
pub fn encode_header<B: Bt + BtMut>( &mut self, buffer: &mut B, ) -> WebResult<usize>
pub fn replace_clone(&mut self, body: T) -> Request<T>
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Request<T>where
T: Freeze,
impl<T> !RefUnwindSafe for Request<T>
impl<T> Send for Request<T>where
T: Send,
impl<T> Sync for Request<T>where
T: Sync,
impl<T> Unpin for Request<T>where
T: Unpin,
impl<T> !UnwindSafe for Request<T>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more