Struct webparse::url::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 229)
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::
}
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

§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method 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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method 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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl TryFrom<&[u8]> for Url

§

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

§

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

§

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 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> 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,

§

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§

default 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>,

§

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>,

§

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.