Convert between HeaderValue and the declared type.
This commit is contained in:
		
							parent
							
								
									e3cf7a38a1
								
							
						
					
					
						commit
						ef32a2f9c1
					
				| @ -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 | ||||
|  | ||||
| @ -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) => { | ||||
|  | ||||
| @ -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<str>`.
 | ||||
| ///     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<str>`.
 | ||||
| ///     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`.
 | ||||
| ///
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user