diff --git a/src/api/request.rs b/src/api/request.rs index 505c6a14..3f90b093 100644 --- a/src/api/request.rs +++ b/src/api/request.rs @@ -20,7 +20,11 @@ impl Request { let header_name = Ident::from(header_name_string.as_ref()); header_tokens.append_all(quote! { - headers.append(::http::header::#header_name, request.#field_name); + headers.append( + ::http::header::#header_name, + ::http::header::HeaderValue::from_str(request.#field_name.as_ref()) + .expect("failed to convert value into HeaderValue"), + ); }); header_tokens diff --git a/src/api/response.rs b/src/api/response.rs index 3f08327e..12ac6c72 100644 --- a/src/api/response.rs +++ b/src/api/response.rs @@ -41,7 +41,10 @@ impl Response { tokens.append_all(quote_spanned! {span=> #field_name: headers.remove(::http::header::#header_name) - .expect("missing expected request header"), + .expect("response missing expected header") + .to_str() + .expect("failed to convert HeaderValue to str") + .to_owned(), }); } ResponseField::NewtypeBody(ref field) => { diff --git a/src/lib.rs b/src/lib.rs index bff2b4aa..6306380d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -80,8 +80,8 @@ mod api; /// /// * `#[ruma_api(header = "HEADER_NAME")]`: Fields with this attribute will be treated as HTTP /// headers on the request. -/// The value must implement `http::HttpTryFrom for http::header::HeaderValue`. -/// Generally this is a string. +/// The value must implement `AsRef`. +/// Generally this is a `String`. /// The attribute value shown above as `HEADER_NAME` must be a header name constant from /// `http::header`, e.g. `CONTENT_TYPE`. /// * `#[ruma_api(path)]`: Fields with this attribute will be inserted into the matching path @@ -101,8 +101,8 @@ mod api; /// /// * `#[ruma_api(header = "HEADER_NAME")]`: Fields with this attribute will be treated as HTTP /// headers on the response. -/// The value must implement `http::HttpTryFrom for http::header::HeaderValue`. -/// Generally this is a string. +/// The value must implement `AsRef`. +/// Generally this is a `String`. /// The attribute value shown above as `HEADER_NAME` must be a header name constant from /// `http::header`, e.g. `CONTENT_TYPE`. ///