@@ -27,10 +27,10 @@ use nom::{
2727fn content_type ( ) -> impl Fn ( & [ u8 ] ) -> IResult < & [ u8 ] , & [ u8 ] > {
2828 move |input| {
2929 map (
30- tuple ( (
30+ (
3131 take_ascii_whitespace ( ) ,
3232 take_till ( |c| c == b';' || c == b',' || c == b' ' ) ,
33- ) ) ,
33+ ) ,
3434 |( _, content_type) | content_type,
3535 )
3636 . parse ( input)
@@ -106,7 +106,7 @@ pub(crate) fn scheme() -> impl Fn(&[u8]) -> IResult<&[u8], &[u8]> {
106106 // Scheme test: if it doesn't start with a forward slash character (which it must
107107 // for the contents to be a path or an authority), then it must be the scheme part
108108 map (
109- tuple ( ( peek ( not ( tag ( "/" ) ) ) , take_until ( ":" ) , tag ( ":" ) ) ) ,
109+ ( peek ( not ( tag ( "/" ) ) ) , take_until ( ":" ) , tag ( ":" ) ) ,
110110 |( _, scheme, _) | scheme,
111111 )
112112 . parse ( input)
@@ -125,8 +125,8 @@ pub(crate) fn credentials() -> impl Fn(&[u8]) -> IResult<&[u8], ParsedCredential
125125 // One, three or more slash characters, and it's a path.
126126 // Note: we only attempt to parse authority if we've seen a scheme.
127127 let ( input, ( _, _, credentials, _) ) =
128- tuple ( ( tag ( "//" ) , peek ( not ( tag ( "/" ) ) ) , take_until ( "@" ) , tag ( "@" ) ) ) . parse ( input) ?;
129- let ( password, username) = opt ( tuple ( ( take_until ( ":" ) , tag ( ":" ) ) ) ) . parse ( credentials) ?;
128+ ( tag ( "//" ) , peek ( not ( tag ( "/" ) ) ) , take_until ( "@" ) , tag ( "@" ) ) . parse ( input) ?;
129+ let ( password, username) = opt ( ( take_until ( ":" ) , tag ( ":" ) ) ) . parse ( credentials) ?;
130130 if let Some ( ( username, _) ) = username {
131131 Ok ( ( input, ( username, Some ( password) ) ) )
132132 } else {
@@ -141,7 +141,7 @@ pub(crate) fn credentials() -> impl Fn(&[u8]) -> IResult<&[u8], ParsedCredential
141141/// Returns a tuple of the remaining unconsumed data and the matched ipv6 hostname.
142142pub ( crate ) fn ipv6 ( ) -> impl Fn ( & [ u8 ] ) -> IResult < & [ u8 ] , & [ u8 ] > {
143143 move |input| -> IResult < & [ u8 ] , & [ u8 ] > {
144- let ( rest, _) = tuple ( ( tag ( "[" ) , is_not ( "/?#]" ) , opt ( tag ( "]" ) ) ) ) . parse ( input) ?;
144+ let ( rest, _) = ( tag ( "[" ) , is_not ( "/?#]" ) , opt ( tag ( "]" ) ) ) . parse ( input) ?;
145145 Ok ( ( rest, & input[ ..input. len ( ) - rest. len ( ) ] ) )
146146 }
147147}
@@ -152,12 +152,12 @@ pub(crate) fn ipv6() -> impl Fn(&[u8]) -> IResult<&[u8], &[u8]> {
152152pub ( crate ) fn hostname ( ) -> impl Fn ( & [ u8 ] ) -> IResult < & [ u8 ] , & [ u8 ] > {
153153 move |input| {
154154 let ( input, mut hostname) = map (
155- tuple ( (
155+ (
156156 opt ( tag ( "//" ) ) , //If it starts with "//", skip (might have parsed a scheme and no creds)
157157 peek ( not ( tag ( "/" ) ) ) , //If it starts with '/', this is a path, not a hostname
158158 many0 ( tag ( " " ) ) ,
159159 alt ( ( ipv6 ( ) , is_not ( "/?#:" ) ) ) ,
160- ) ) ,
160+ ) ,
161161 |( _, _, _, hostname) | hostname,
162162 )
163163 . parse ( input) ?;
@@ -177,7 +177,7 @@ pub(crate) fn port() -> impl Fn(&[u8]) -> IResult<&[u8], &[u8]> {
177177 move |input| {
178178 // Must start with ":" for there to be a port to parse
179179 let ( input, ( _, _, port, _) ) =
180- tuple ( ( tag ( ":" ) , many0 ( tag ( " " ) ) , is_not ( "/?#" ) , many0 ( tag ( " " ) ) ) ) . parse ( input) ?;
180+ ( tag ( ":" ) , many0 ( tag ( " " ) ) , is_not ( "/?#" ) , many0 ( tag ( " " ) ) ) . parse ( input) ?;
181181 let ( _, port) = is_not ( " " ) ( port) ?; //we assume there never will be a space in the middle of a port
182182 Ok ( ( input, port) )
183183 }
@@ -198,10 +198,7 @@ pub(crate) fn path() -> impl Fn(&[u8]) -> IResult<&[u8], &[u8]> {
198198pub ( crate ) fn query ( ) -> impl Fn ( & [ u8 ] ) -> IResult < & [ u8 ] , & [ u8 ] > {
199199 move |input| {
200200 // Skip the starting '?'
201- map ( tuple ( ( tag ( "?" ) , take_till ( |c| c == b'#' ) ) ) , |( _, query) | {
202- query
203- } )
204- . parse ( input)
201+ map ( ( tag ( "?" ) , take_till ( |c| c == b'#' ) ) , |( _, query) | query) . parse ( input)
205202 }
206203}
207204
@@ -245,15 +242,15 @@ pub(crate) fn parse_hostport(input: &[u8]) -> IResult<&[u8], parsed_hostport<'_>
245242/// Returns (any unparsed trailing data, (version_number, flag indicating whether input contains trailing and/or leading whitespace and/or leading zeros))
246243fn protocol_version ( input : & [ u8 ] ) -> IResult < & [ u8 ] , ( & [ u8 ] , bool ) > {
247244 map (
248- tuple ( (
245+ (
249246 take_ascii_whitespace ( ) ,
250247 tag_no_case ( "HTTP" ) ,
251248 take_ascii_whitespace ( ) ,
252249 tag ( "/" ) ,
253250 take_while ( |c : u8 | c. is_ascii_whitespace ( ) || c == b'0' ) ,
254251 alt ( ( tag ( ".9" ) , tag ( "1.0" ) , tag ( "1.1" ) ) ) ,
255252 take_ascii_whitespace ( ) ,
256- ) ) ,
253+ ) ,
257254 |( _, _, leading, _, trailing, version, _) | {
258255 ( version, !leading. is_empty ( ) || !trailing. is_empty ( ) )
259256 } ,
@@ -311,17 +308,17 @@ pub(crate) fn parse_status(status: &[u8]) -> HtpResponseNumber {
311308/// Parses Digest Authorization request header.
312309fn parse_authorization_digest ( auth_header_value : & [ u8 ] ) -> IResult < & [ u8 ] , Vec < u8 > > {
313310 // Extract the username
314- let ( mut remaining_input, _) = tuple ( (
311+ let ( mut remaining_input, _) = (
315312 take_until ( "username=" ) ,
316313 tag ( "username=" ) ,
317314 take_ascii_whitespace ( ) , // allow lws
318315 tag ( "\" " ) , // First character after LWS must be a double quote
319- ) ) ( auth_header_value) ?;
316+ )
317+ . parse ( auth_header_value) ?;
320318 let mut result = Vec :: new ( ) ;
321319 // Unescape any escaped double quotes and find the closing quote
322320 loop {
323- let ( remaining, ( auth_header, _) ) =
324- tuple ( ( take_until ( "\" " ) , tag ( "\" " ) ) ) . parse ( remaining_input) ?;
321+ let ( remaining, ( auth_header, _) ) = ( take_until ( "\" " ) , tag ( "\" " ) ) . parse ( remaining_input) ?;
325322 remaining_input = remaining;
326323 result. extend_from_slice ( auth_header) ;
327324 if result. last ( ) == Some ( & ( b'\\' ) ) {
@@ -339,9 +336,9 @@ fn parse_authorization_digest(auth_header_value: &[u8]) -> IResult<&[u8], Vec<u8
339336/// Parses Basic Authorization request header.
340337fn parse_authorization_basic ( request_tx : & mut Transaction , auth_header : & Header ) -> Result < ( ) > {
341338 // Skip 'Basic<lws>'
342- let ( remaining_input, _) =
343- tuple ( ( tag_no_case ( "basic" ) , take_ascii_whitespace ( ) ) ) ( auth_header. value . as_slice ( ) )
344- . map_err ( |_| HtpStatus :: DECLINED ) ?;
339+ let ( remaining_input, _) = ( tag_no_case ( "basic" ) , take_ascii_whitespace ( ) )
340+ . parse ( auth_header. value . as_slice ( ) )
341+ . map_err ( |_| HtpStatus :: DECLINED ) ?;
345342 // Decode base64-encoded data
346343 let decoded = STANDARD
347344 . decode ( remaining_input)
@@ -383,11 +380,12 @@ pub(crate) fn parse_authorization(request_tx: &mut Transaction) -> Result<()> {
383380 }
384381 } else if auth_header. value . starts_with_nocase ( "bearer" ) {
385382 request_tx. request_auth_type = HtpAuthType :: BEARER ;
386- let ( token, _) = tuple ( (
383+ let ( token, _) = (
387384 tag_no_case ( "bearer" ) ,
388385 take_ascii_whitespace ( ) , // allow lws
389- ) ) ( auth_header. value . as_slice ( ) )
390- . map_err ( |_| HtpStatus :: DECLINED ) ?;
386+ )
387+ . parse ( auth_header. value . as_slice ( ) )
388+ . map_err ( |_| HtpStatus :: DECLINED ) ?;
391389 request_tx. request_auth_token = Some ( Bstr :: from ( token) ) ;
392390 } else {
393391 // Unrecognized authentication method
0 commit comments