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 182)
179fn main() {
180 let mut req = crate::Request::new();
181 let ret = req.parse(b"GET / HTTP/1.1\r\nHost: 127.0.0.1\r");
182 assert!(ret.err().unwrap().is_partial());
183
184 let buf = b"GET /index.html HTTP/1.1\r\nHost: example.domain\r\n\r\n";
185 let ret = req.parse(buf).unwrap();
186
187 assert!(ret == buf.len());
188 assert!(req.is_complete());
189
190 debug_request_parse();
191 // let mut binmut = BinaryMut::new();
192 // "aaa".serialize1(&mut binmut);
193
194 // let bin = Binary::new();
195 // let p = Pay::Data(bin);
196 // println!("bbb = {:?}", p);
197 // debug_request_parse_full_http2();
198 // debug_request_parse_http2();
199
200 // let req = request::Builder::new()
201 // .method("POST")
202 // .body(())
203 // .unwrap();
204
205 // debug_request_parse();
206 // let v = vec![1u8, 2, 3, 5, 7, 9, 10].into_boxed_slice();
207 // let mut b = Binary::from(v);
208 // {
209 // b.get_next();
210 // let c = b.clone_slice();
211 // drop(c);
212 // b.get_next();
213 // let d = b.clone_slice();
214 // drop(d);
215 // }
216 // drop(b);
217 println!("finish");
218 // let len = v.len();
219 // let raw = Box::into_raw(v) as *mut u8;
220
221 // // Layout::from_size_align(cap, 1);
222
223 // let value = unsafe { Vec::from_raw_parts(raw, len, len) };
224 // println!("value = {:?}", value);
225
226 if true {
227 return;
228 }
229
230 // let mut request = webparse::Request::builder().body("What is this".to_string()).unwrap();
231 // // let _result = request.parse(b"GET /index.html HTTP/1.1\r\nHost: example.domain\r\n\r\n").unwrap();
232 // // println!("result = {:?}", request);
233 // // println!("is_partial = {}", request.is_partial());
234
235 // let _result = request.parse(b"GET /index.html HTTP/1.1\r\nHost: example.domain1\r\ncontent-length: 1111\r\n");
236 // println!("result = {:?}", request);
237 // println!("is_partial = {}", request.is_partial());
238 // println!("body len = {}", request.get_body_len());
239
240 let url: Result<Url, webparse::WebError> =
241 Url::try_from("https://%4811:!%2011@www.baidu.com:88/path?aaa=222");
242 println!("value = {:?}", url);
243 println!("value = {}", url.ok().unwrap());
244
245 let url = Url::try_from("/path?qqq=222");
246 println!("value = {:?}", url);
247 println!("value = {}", url.ok().unwrap());
248
249 println!("decode = {:?}", Url::url_decode("%48%211111"));
250 println!("decode = {:?}", Url::url_decode("%48%21111%1"));
251 println!("decode = {:?}", Url::url_decode("%48%21111%4j"));
252 let value = Url::try_from("https://11:11@www.baidu.com/path").unwrap();
253 println!("value = {}", value);
254
255 // // let value = url::Url::parse("/path");
256 // 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");
257 // println!("result = {:?}", request);
258 // println!("is_partial = {}", request.is_partial());
259 // println!("body len = {}", request.get_body_len());
260 // println!("host len = {:?}", request.get_host());
261 // println!("host len = {:?}", request.get_connect_url());
262
263 // let mut buffer = Buffer::new();
264 // request.serialize(&mut buffer).expect("ok");
265 // println!("aaaaaaaaaaaaaaa {}", String::from_utf8_lossy(buffer.get_write_data()));
266
267 // println!("aaaaaaaaaaaaaaa11111 {}", String::from_utf8_lossy(&request.httpdata().unwrap()));
268
269 // let mut req = Request::builder();
270 // assert_eq!(req.url_ref().unwrap(), "/" );
271 // req = req.url("https://www.rust-lang.org/");
272 // assert_eq!(req.url_ref().unwrap(), "https://www.rust-lang.org/" );
273
274 // let mut req = Request::builder().version(Version::Http2).method("GET")
275 // .header("Accept", "text/html")
276 // .header("X-Custom-Foo", "bar");
277 // {
278 // let headers = req.headers_mut().unwrap();
279 // headers["AAAA"] = HeaderValue::Stand("ok");
280 // let xx = &headers["Accept"];
281 // let aaa = &headers["AAAA"];
282 // println!("xxx = {:?}", xx);
283 // println!("aaa = {:?}", aaa);
284
285 // for value in headers.iter() {
286 // println!("____={:?}", value.0);
287 // println!("____={:?}", value.1);
288 // }
289 // assert_eq!( &headers["Accept"], "text/html" );
290 // assert_eq!( &headers["X-Custom-Foo"], "bar" );
291 // }
292
293 let req = Request::builder()
294 .version(Version::Http2)
295 .method("GET")
296 .url("/")
297 .header(":scheme", "http")
298 .header(":authority", "www.example.com");
299 {
300 // let headers = req.headers_mut().unwrap();
301 // headers["AAAA"] = HeaderValue::Stand("ok");
302 // let xx = &headers["Accept"];
303 // let aaa = &headers["AAAA"];
304 // println!("xxx = {:?}", xx);
305 // println!("aaa = {:?}", aaa);
306
307 // for value in headers.iter() {
308 // println!("____={:?}", value.0);
309 // println!("____={:?}", value.1);
310 // }
311 // assert_eq!( &headers["Accept"], "text/html" );
312 // assert_eq!( &headers["X-Custom-Foo"], "bar" );
313 }
314
315 let _rrr = req.body(()).unwrap();
316
317 // let data = rrr.http2data().unwrap();
318
319 // println!("req.httpdata() = {:?}", hex_debug_print(&data));
320
321 // let mut decode = Decoder::new();
322 // let mut buf = BinaryMut::from(data);
323 // let result = decode.decode_with_cb(&mut buf, |n, v| {
324 // println!("n = {:?}, v = {}", n, v);
325 // });
326
327 // let mut index = Arc::new(HeaderIndex::new());
328 // Arc::get_mut(&mut index).map(|v| {
329 // v.add_header(
330 // HeaderName::from_static("aaa"),
331 // HeaderValue::from_static("aa"),
332 // );
333 // });
334
335 // let xx = Arc::get_mut(&mut index);
336 // println!("========={:?}", xx);
337 // let xx111 = Arc::get_mut(&mut index);
338 // println!("========={:?}", xx111);
339 // // rrr.extensions_mut().insert(index);
340 // // let new = rrr.extensions_mut().get_mut::<Arc<HeaderIndex>>();
341 // // println!("========={:?}", new);
342
343 // // if true {
344 // // return;
345 // // }
346
347 // let u = url::Builder::new()
348 // .scheme("https")
349 // .domain("www.baidu.com")
350 // .build()
351 // .unwrap();
352 // println!("u = {}", u);
353
354 // let response = Response::builder()
355 // .header("Accept", "text/html")
356 // .header("X-Custom-Foo", "bar")
357 // .body("my is web")
358 // .unwrap();
359
360 // println!(
361 // "ssssssssssss {}",
362 // String::from_utf8_lossy(&response.httpdata().unwrap())
363 // );
364
365 let mut xx = HashMap::<(u32, u8), u8>::new();
366 xx.insert((48, 5), 6);
367
368 // xx.get(&b"xx");
369
370 println!("aaa {:?}", xx.get(&(48, 5)));
371 // let response = url::Builder::
372}
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 Freeze for WebError
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