@@ -1568,7 +1568,7 @@ impl HttpRequestType {
15681568 } else {
15691569 "" . to_string ( )
15701570 } ;
1571- info ! ( "Handle {} {}{}" , verb, decoded_path, query) ;
1571+ info ! ( "Handle HTTPRequest" ; "verb" => % verb, "peer_addr" => %protocol . peer_addr , "path" => % decoded_path, "query" => % query) ;
15721572 return Ok ( request) ;
15731573 }
15741574 None => {
@@ -3964,6 +3964,8 @@ struct HttpReplyData {
39643964/// There can be at most one HTTP request in-flight (i.e. we don't do pipelining)
39653965#[ derive( Debug , Clone , PartialEq ) ]
39663966pub struct StacksHttp {
3967+ /// Address of peer
3968+ peer_addr : SocketAddr ,
39673969 /// Version of client
39683970 request_version : Option < HttpVersion > ,
39693971 /// Path we requested
@@ -3977,8 +3979,9 @@ pub struct StacksHttp {
39773979}
39783980
39793981impl StacksHttp {
3980- pub fn new ( ) -> StacksHttp {
3982+ pub fn new ( peer_addr : SocketAddr ) -> StacksHttp {
39813983 StacksHttp {
3984+ peer_addr,
39823985 reply : None ,
39833986 request_version : None ,
39843987 request_path : None ,
@@ -4084,19 +4087,21 @@ impl StacksHttp {
40844087 }
40854088
40864089 /// Given a HTTP request, serialize it out
4090+ #[ cfg( test) ]
40874091 pub fn serialize_request ( req : & HttpRequestType ) -> Result < Vec < u8 > , net_error > {
4088- let mut http = StacksHttp :: new ( ) ;
4092+ let mut http = StacksHttp :: new ( "127.0.0.1:20443" . parse ( ) . unwrap ( ) ) ;
40894093 let mut ret = vec ! [ ] ;
40904094 req. send ( & mut http, & mut ret) ?;
40914095 Ok ( ret)
40924096 }
40934097
40944098 /// Given a fully-formed single HTTP response, parse it (used by clients).
4099+ #[ cfg( test) ]
40954100 pub fn parse_response (
40964101 request_path : & str ,
40974102 response_buf : & [ u8 ] ,
40984103 ) -> Result < StacksHttpMessage , net_error > {
4099- let mut http = StacksHttp :: new ( ) ;
4104+ let mut http = StacksHttp :: new ( "127.0.0.1:20443" . parse ( ) . unwrap ( ) ) ;
41004105 http. reset ( ) ;
41014106 http. begin_request ( HttpVersion :: Http11 , request_path. to_string ( ) ) ;
41024107
@@ -5437,7 +5442,7 @@ mod test {
54375442 expected_bytes. append ( & mut expected_http_body. clone ( ) ) ;
54385443
54395444 let mut bytes = vec ! [ ] ;
5440- let mut http = StacksHttp :: new ( ) ;
5445+ let mut http = StacksHttp :: new ( "127.0.0.1:20443" . parse ( ) . unwrap ( ) ) ;
54415446 http. write_message ( & mut bytes, & StacksHttpMessage :: Request ( test. clone ( ) ) )
54425447 . unwrap ( ) ;
54435448
@@ -5454,7 +5459,7 @@ mod test {
54545459 "POST /v2/transactions HTTP/1.1\r \n User-Agent: stacks/2.0\r \n Host: bad:123\r \n Content-Length: 0\r \n \r \n " ,
54555460 ] ;
54565461 for bad_content_length in bad_content_lengths {
5457- let mut http = StacksHttp :: new ( ) ;
5462+ let mut http = StacksHttp :: new ( "127.0.0.1:20443" . parse ( ) . unwrap ( ) ) ;
54585463 let ( preamble, offset) = http. read_preamble ( bad_content_length. as_bytes ( ) ) . unwrap ( ) ;
54595464 let e = http. read_payload ( & preamble, & bad_content_length. as_bytes ( ) [ offset..] ) ;
54605465 let estr = format ! ( "{:?}" , & e) ;
@@ -5473,7 +5478,7 @@ mod test {
54735478 "POST /v2/transactions HTTP/1.1\r \n User-Agent: stacks/2.0\r \n Host: bad:123\r \n Content-Length: 1\r \n \r \n b" ,
54745479 ] ;
54755480 for bad_content_type in bad_content_types {
5476- let mut http = StacksHttp :: new ( ) ;
5481+ let mut http = StacksHttp :: new ( "127.0.0.1:20443" . parse ( ) . unwrap ( ) ) ;
54775482 let ( preamble, offset) = http. read_preamble ( bad_content_type. as_bytes ( ) ) . unwrap ( ) ;
54785483 let e = http. read_payload ( & preamble, & bad_content_type. as_bytes ( ) [ offset..] ) ;
54795484 assert ! ( e. is_err( ) ) ;
@@ -5871,7 +5876,7 @@ mod test {
58715876 . zip ( expected_http_bodies. iter ( ) ) ,
58725877 )
58735878 {
5874- let mut http = StacksHttp :: new ( ) ;
5879+ let mut http = StacksHttp :: new ( "127.0.0.1:20443" . parse ( ) . unwrap ( ) ) ;
58755880 let mut bytes = vec ! [ ] ;
58765881 test_debug ! ( "write body:\n {:?}\n " , test) ;
58775882
@@ -5963,7 +5968,7 @@ mod test {
59635968 expected_error
59645969 ) ;
59655970
5966- let mut http = StacksHttp :: new ( ) ;
5971+ let mut http = StacksHttp :: new ( "127.0.0.1:20443" . parse ( ) . unwrap ( ) ) ;
59675972 http. begin_request ( HttpVersion :: Http11 , request_path. to_string ( ) ) ;
59685973
59695974 let ( preamble, offset) = http. read_preamble ( test. as_bytes ( ) ) . unwrap ( ) ;
@@ -6084,7 +6089,7 @@ mod test {
60846089 let invalid_neighbors_response = "HTTP/1.1 200 OK\r \n Server: stacks/v2.0\r \n X-Request-Id: 123\r \n Content-Type: application/json\r \n Transfer-Encoding: chunked\r \n \r \n 10\r \n xxxxxxxxxxxxxxxx\r \n 0\r \n \r \n " ;
60856090 let invalid_chunked_response = "HTTP/1.1 200 OK\r \n Server: stacks/v2.0\r \n X-Request-Id: 123\r \n Content-Type: application/json\r \n Transfer-Encoding: chunked\r \n \r \n 29\r \n {\" sample\" :[],\" inbound\" :[],\" outbound\" :[]}\r \n 0\r \n \r \n " ;
60866091
6087- let mut http = StacksHttp :: new ( ) ;
6092+ let mut http = StacksHttp :: new ( "127.0.0.1:20443" . parse ( ) . unwrap ( ) ) ;
60886093
60896094 http. begin_request ( HttpVersion :: Http11 , "/v2/neighbors" . to_string ( ) ) ;
60906095 let ( preamble, offset) = http
0 commit comments