File tree Expand file tree Collapse file tree 6 files changed +36
-20
lines changed
Expand file tree Collapse file tree 6 files changed +36
-20
lines changed Original file line number Diff line number Diff line change 11# http_message
22
33``` rust
4- use std :: str :: FromStr ;
5-
64use http_message :: PartialHttpRequest ;
75
86fn main () {
@@ -19,6 +17,19 @@ fn main() {
1917
2018 assert_eq! (Some (& (24 .. 34 )), partial . header_span (" x-key" ));
2119 assert_eq! (Some (" x-key: 123" ), partial . header_str (" x-key" ));
20+
21+ let request : HttpRequest = partial . into ();
22+
23+ assert_eq! (
24+ HttpRequest {
25+ uri : Uri :: new (" https://example.com" ),
26+ method : " GET" . into (),
27+ http_version : " HTTP/1.1" . into (),
28+ headers : vec! [(" x-key" , " 123" ). into ()],
29+ body : None
30+ },
31+ request
32+ );
2233}
2334```
2435
Original file line number Diff line number Diff line change 1- use std:: str:: FromStr ;
2-
3- use http_message:: PartialHttpRequest ;
1+ use http_message:: {
2+ PartialHttpRequest ,
3+ models:: { request:: HttpRequest , uri:: Uri } ,
4+ } ;
45
56fn main ( ) {
67 let partial = PartialHttpRequest :: from_str ( "GET https://example.com\n x-key: 123" ) . unwrap ( ) ;
@@ -16,4 +17,17 @@ fn main() {
1617
1718 assert_eq ! ( Some ( & ( 24 ..34 ) ) , partial. header_span( "x-key" ) ) ;
1819 assert_eq ! ( Some ( "x-key: 123" ) , partial. header_str( "x-key" ) ) ;
20+
21+ let request: HttpRequest = partial. into ( ) ;
22+
23+ assert_eq ! (
24+ HttpRequest {
25+ uri: Uri :: new( "https://example.com" ) ,
26+ method: "GET" . into( ) ,
27+ http_version: "HTTP/1.1" . into( ) ,
28+ headers: vec![ ( "x-key" , "123" ) . into( ) ] ,
29+ body: None
30+ } ,
31+ request
32+ ) ;
1933}
Original file line number Diff line number Diff line change 1- use std:: str:: FromStr ;
2-
31fn main ( ) {
42 use std:: env;
53 use std:: fs;
Original file line number Diff line number Diff line change 11use core:: fmt;
2- use std:: { ops:: Range , str :: FromStr } ;
2+ use std:: ops:: Range ;
33
44use crate :: {
55 error:: Error ,
@@ -26,6 +26,10 @@ impl fmt::Display for PartialHttpRequest {
2626}
2727
2828impl PartialHttpRequest {
29+ pub fn from_str ( message : & str ) -> Result < Self , Error > {
30+ parse_request ( message, parse_first_line)
31+ }
32+
2933 pub fn parsed (
3034 message : & str ,
3135 method : Option < Range < usize > > ,
@@ -175,15 +179,6 @@ impl Default for PartialHttpRequest {
175179 }
176180}
177181
178- impl FromStr for PartialHttpRequest {
179- type Err = Error ;
180-
181- /// Parse a string in to a partial request
182- fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
183- parse_request ( s, parse_first_line)
184- }
185- }
186-
187182type FirstLineParts = (
188183 Option < Range < usize > > ,
189184 Option < Range < usize > > ,
Original file line number Diff line number Diff line change 1- use std:: { fs , str :: FromStr } ;
1+ use std:: fs ;
22
33use http_message:: PartialHttpRequest ;
44
Original file line number Diff line number Diff line change 1- use std:: str:: FromStr ;
2-
31use http_message:: PartialHttpRequest ;
42use http_message:: models:: { request:: HttpRequest , uri:: Uri } ;
53
You can’t perform that action at this time.
0 commit comments