pub enum WebError {
Http(HttpError),
Http2(Http2Error),
Ws(WsError),
Url(UrlError),
IntoError,
Extension(&'static str),
Serialize(&'static str),
Io(Error),
}
Variants§
Http(HttpError)
Http2(Http2Error)
Ws(WsError)
Url(UrlError)
IntoError
Extension(&'static str)
Serialize(&'static str)
Io(Error)
Implementations§
source§impl WebError
impl WebError
sourcepub fn is_partial(&self) -> bool
pub fn is_partial(&self) -> bool
Examples found in repository?
examples/demo.rs (line 162)
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
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::
}
Trait Implementations§
source§impl From<Infallible> for WebError
impl From<Infallible> for WebError
source§fn from(_: Infallible) -> Self
fn from(_: Infallible) -> Self
Converts to this type from the input type.
source§impl From<ParseIntError> for WebError
impl From<ParseIntError> for WebError
source§fn from(_: ParseIntError) -> Self
fn from(_: ParseIntError) -> Self
Converts to this type from the input type.
source§impl Into<WebError> for Http2Error
impl Into<WebError> for Http2Error
Auto Trait Implementations§
impl !RefUnwindSafe for WebError
impl Send for WebError
impl Sync for WebError
impl Unpin for WebError
impl !UnwindSafe for WebError
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