Struct Url

Source
pub struct Url {
    pub scheme: Scheme,
    pub path: String,
    pub username: Option<String>,
    pub password: Option<String>,
    pub domain: Option<String>,
    pub port: Option<u16>,
    pub query: Option<String>,
}

Fields§

§scheme: Scheme§path: String§username: Option<String>§password: Option<String>§domain: Option<String>§port: Option<u16>§query: Option<String>

Implementations§

Source§

impl Url

Source

pub const DEFAULT_PATH: &'static str = "/"

Source

pub fn new() -> Url

Source

pub fn builder() -> Builder

Source

pub fn merge(&mut self, other: Url)

Source

pub fn parse(url: Vec<u8>) -> WebResult<Url>

Source

pub fn url_encode(val: &str) -> String

Source

pub fn url_decode(val: &str) -> WebResult<String>

Examples found in repository?
examples/demo.rs (line 249)
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}
Source

pub fn get_authority(&self) -> String

Source

pub fn get_scheme(&self) -> String

Source

pub fn get_connect_url(&self) -> Option<String>

Trait Implementations§

Source§

impl Clone for Url

Source§

fn clone(&self) -> Url

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Url

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Url

Source§

fn default() -> Url

Returns the “default value” for a type. Read more
Source§

impl Display for Url

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FromStr for Url

Source§

type Err = WebError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl PartialEq<Url> for str

Source§

fn eq(&self, url: &Url) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<str> for Url

Source§

fn eq(&self, other: &str) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq for Url

Source§

fn eq(&self, other: &Url) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<&[u8]> for Url

Source§

type Error = WebError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &[u8]) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&str> for Url

Source§

type Error = WebError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<String> for Url

Source§

type Error = WebError

The type returned in the event of a conversion error.
Source§

fn try_from(value: String) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for Url

Source§

impl StructuralPartialEq for Url

Auto Trait Implementations§

§

impl Freeze for Url

§

impl RefUnwindSafe for Url

§

impl Send for Url

§

impl Sync for Url

§

impl Unpin for Url

§

impl UnwindSafe for Url

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.