From 2e61615da02329b97ea18d2e00d238d8fc43198b Mon Sep 17 00:00:00 2001 From: Scott Lamb Date: Sun, 23 May 2021 20:08:39 -0700 Subject: [PATCH] allow non-'static HTTP method names Background: RTSP uses HTTP digest authentication (see RFC 2326 section 1.4). I'm using the rtsp-types crate. It works fine with digest_auth, except that [rtsp_types::Method::Extension](https://docs.rs/rtsp-types/0.0.1/rtsp_types/enum.Method.html#variant.Extension) has a non-static lifetime. --- src/digest.rs | 4 ++-- src/enums.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/digest.rs b/src/digest.rs index 4e1e0b4..bd08941 100644 --- a/src/digest.rs +++ b/src/digest.rs @@ -161,7 +161,7 @@ pub struct AuthContext<'a> { /// May be left out if not using auth-int pub body: Option>, /// HTTP method used (defaults to GET) - pub method: HttpMethod, + pub method: HttpMethod<'a>, /// Spoofed client nonce (use only for tests; a random nonce is generated automatically) pub cnonce: Option>, } @@ -202,7 +202,7 @@ impl<'a> AuthContext<'a> { password: PW, uri: UR, body: Option, - method: HttpMethod, + method: HttpMethod<'a>, ) -> Self where UN: Into>, diff --git a/src/enums.rs b/src/enums.rs index 6c45e8c..9cfedc8 100644 --- a/src/enums.rs +++ b/src/enums.rs @@ -168,20 +168,20 @@ impl Display for Charset { /// HTTP method (used when generating the response hash for some Qop options) #[derive(Debug)] -pub enum HttpMethod { +pub enum HttpMethod<'a> { GET, POST, HEAD, - OTHER(&'static str), + OTHER(&'a str), } -impl Default for HttpMethod { +impl<'a> Default for HttpMethod<'a> { fn default() -> Self { HttpMethod::GET } } -impl Display for HttpMethod { +impl<'a> Display for HttpMethod<'a> { /// Convert to uppercase string fn fmt(&self, f: &mut Formatter) -> fmt::Result { f.write_str(match self {