forked from loafle/openapi-generator-original
Merge remote-tracking branch 'origin/5.0.x'
This commit is contained in:
commit
98e54f0cc1
@ -8,6 +8,7 @@ use hyper::{Body, Uri, Response};
|
||||
use hyper_openssl::HttpsConnector;
|
||||
use serde_json;
|
||||
use std::borrow::Cow;
|
||||
use std::convert::TryInto;
|
||||
use std::io::{Read, Error, ErrorKind};
|
||||
use std::error;
|
||||
use std::fmt;
|
||||
|
@ -332,15 +332,23 @@
|
||||
// Header parameters
|
||||
{{/-first}}
|
||||
{{^isMapContainer}}
|
||||
{{#required}}
|
||||
{{^required}}
|
||||
match param_{{{paramName}}} {
|
||||
Some(param_{{{paramName}}}) => {
|
||||
{{/required}}
|
||||
request.headers_mut().append(
|
||||
HeaderName::from_static("{{{nameInLowerCase}}}"),
|
||||
header::IntoHeaderValue(param_{{{paramName}}}.clone()).into());
|
||||
{{/required}}
|
||||
match header::IntoHeaderValue(param_{{{paramName}}}.clone()).try_into() {
|
||||
Ok(header) => header,
|
||||
Err(e) => {
|
||||
return Box::new(future::err(ApiError(format!(
|
||||
"Invalid header {{{paramName}}} - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
|
||||
},
|
||||
});
|
||||
{{^required}}
|
||||
param_{{{paramName}}}.map(|value| request.headers_mut().append(
|
||||
HeaderName::from_static("{{{nameInLowerCase}}}"),
|
||||
header::IntoHeaderValue(value.clone()).into()));
|
||||
},
|
||||
None => {}
|
||||
}
|
||||
{{/required}}
|
||||
{{/isMapContainer}}
|
||||
{{#isMapContainer}}
|
||||
@ -359,6 +367,14 @@
|
||||
Some(response_{{{name}}}) => response_{{{name}}}.clone(),
|
||||
None => return Box::new(future::err(ApiError(String::from("Required response header {{{baseName}}} for response {{{code}}} was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
|
||||
};
|
||||
let response_{{{name}}} = match TryInto::<header::IntoHeaderValue<{{{dataType}}}>>::try_into(response_{{{name}}}) {
|
||||
Ok(value) => value,
|
||||
Err(e) => {
|
||||
return Box::new(future::err(ApiError(format!("Invalid response header {{baseName}} for response {{code}} - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
|
||||
},
|
||||
};
|
||||
let response_{{{name}}} = response_{{{name}}}.0;
|
||||
|
||||
{{/headers}}
|
||||
let body = response.into_body();
|
||||
Box::new(
|
||||
@ -402,7 +418,7 @@
|
||||
{
|
||||
body: body,
|
||||
{{/-first}}
|
||||
{{{name}}}: (*Into::<header::IntoHeaderValue<{{{dataType}}}>>::into(response_{{{name}}})).clone(),
|
||||
{{{name}}}: response_{{name}},
|
||||
{{#-last}}
|
||||
}
|
||||
{{/-last}}
|
||||
@ -416,7 +432,7 @@
|
||||
{{#-first}}
|
||||
{
|
||||
{{/-first}}
|
||||
{{{name}}}: (*Into::<header::IntoHeaderValue<{{{dataType}}}>>::into(response_{{{name}}})).clone(),
|
||||
{{{name}}}: response_{{name}},
|
||||
{{#-last}}
|
||||
}
|
||||
{{/-last}}
|
||||
|
@ -1,5 +1,6 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use hyper::header::HeaderValue;
|
||||
use std::convert::TryFrom;
|
||||
use std::fmt;
|
||||
use std::ops::Deref;
|
||||
|
||||
@ -19,19 +20,31 @@ impl<T> Deref for IntoHeaderValue<T> {
|
||||
}
|
||||
}
|
||||
|
||||
// Derive for each From<T> in hyper::header::HeaderValue
|
||||
// Derive for each TryFrom<T> in hyper::header::HeaderValue
|
||||
|
||||
macro_rules! ihv_generate {
|
||||
($t:ident) => {
|
||||
impl From<HeaderValue> for IntoHeaderValue<$t> {
|
||||
fn from(hdr_value: HeaderValue) -> Self {
|
||||
IntoHeaderValue(hdr_value.to_str().unwrap().parse::<$t>().unwrap())
|
||||
impl TryFrom<HeaderValue> for IntoHeaderValue<$t> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: HeaderValue) -> Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
Ok(hdr_value) => match hdr_value.parse::<$t>() {
|
||||
Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value)),
|
||||
Err(e) => Err(format!("Unable to parse {} as a string: {}",
|
||||
stringify!($t), e)),
|
||||
},
|
||||
Err(e) => Err(format!("Unable to parse header {:?} as a string - {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IntoHeaderValue<$t>> for HeaderValue {
|
||||
fn from(hdr_value: IntoHeaderValue<$t>) -> Self {
|
||||
hdr_value.0.into()
|
||||
impl TryFrom<IntoHeaderValue<$t>> for HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: IntoHeaderValue<$t>) -> Result<Self, Self::Error> {
|
||||
Ok(hdr_value.0.into())
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -48,52 +61,120 @@ ihv_generate!(i32);
|
||||
|
||||
// Custom derivations
|
||||
|
||||
impl From<HeaderValue> for IntoHeaderValue<Vec<String>> {
|
||||
fn from(hdr_value: HeaderValue) -> Self {
|
||||
IntoHeaderValue(
|
||||
hdr_value
|
||||
.to_str()
|
||||
.unwrap()
|
||||
// Vec<String>
|
||||
|
||||
impl TryFrom<HeaderValue> for IntoHeaderValue<Vec<String>> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: HeaderValue) -> Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
Ok(hdr_value) => Ok(IntoHeaderValue(
|
||||
hdr_value
|
||||
.split(',')
|
||||
.filter_map(|x| match x.trim() {
|
||||
"" => None,
|
||||
y => Some(y.to_string()),
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
.collect())),
|
||||
Err(e) => Err(format!("Unable to parse header: {:?} as a string - {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IntoHeaderValue<Vec<String>>> for HeaderValue {
|
||||
fn from(hdr_value: IntoHeaderValue<Vec<String>>) -> Self {
|
||||
HeaderValue::from_str(&hdr_value.0.join(", ")).unwrap()
|
||||
impl TryFrom<IntoHeaderValue<Vec<String>>> for HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: IntoHeaderValue<Vec<String>>) -> Result<Self, Self::Error> {
|
||||
match HeaderValue::from_str(&hdr_value.0.join(", ")) {
|
||||
Ok(hdr_value) => Ok(hdr_value),
|
||||
Err(e) => Err(format!("Unable to convert {:?} into a header - {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<HeaderValue> for IntoHeaderValue<String> {
|
||||
fn from(hdr_value: HeaderValue) -> Self {
|
||||
IntoHeaderValue(hdr_value.to_str().unwrap().to_string())
|
||||
// String
|
||||
|
||||
impl TryFrom<HeaderValue> for IntoHeaderValue<String> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: HeaderValue) -> Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value.to_string())),
|
||||
Err(e) => Err(format!("Unable to convert header {:?} to {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IntoHeaderValue<String>> for HeaderValue {
|
||||
fn from(hdr_value: IntoHeaderValue<String>) -> Self {
|
||||
HeaderValue::from_str(&hdr_value.0).unwrap()
|
||||
impl TryFrom<IntoHeaderValue<String>> for HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: IntoHeaderValue<String>) -> Result<Self, Self::Error> {
|
||||
match HeaderValue::from_str(&hdr_value.0) {
|
||||
Ok(hdr_value) => Ok(hdr_value),
|
||||
Err(e) => Err(format!("Unable to convert {:?} from a header {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<HeaderValue> for IntoHeaderValue<DateTime<Utc>> {
|
||||
fn from(hdr_value: HeaderValue) -> Self {
|
||||
IntoHeaderValue(
|
||||
DateTime::parse_from_rfc3339(hdr_value.to_str().unwrap())
|
||||
.unwrap()
|
||||
.with_timezone(&Utc),
|
||||
)
|
||||
// bool
|
||||
impl TryFrom<HeaderValue> for IntoHeaderValue<bool> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: HeaderValue) -> Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
Ok(hdr_value) => match hdr_value.parse() {
|
||||
Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value)),
|
||||
Err(e) => Err(format!("Unable to parse bool from {} - {}",
|
||||
hdr_value, e)),
|
||||
},
|
||||
Err(e) => Err(format!("Unable to convert {:?} from a header {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IntoHeaderValue<DateTime<Utc>>> for HeaderValue {
|
||||
fn from(hdr_value: IntoHeaderValue<DateTime<Utc>>) -> Self {
|
||||
HeaderValue::from_str(hdr_value.0.to_rfc3339().as_str()).unwrap()
|
||||
impl TryFrom<IntoHeaderValue<bool>> for HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: IntoHeaderValue<bool>) -> Result<Self, Self::Error> {
|
||||
match HeaderValue::from_str(&hdr_value.0.to_string()) {
|
||||
Ok(hdr_value) => Ok(hdr_value),
|
||||
Err(e) => Err(format!("Unable to convert: {:?} into a header: {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// DateTime
|
||||
|
||||
impl TryFrom<HeaderValue> for IntoHeaderValue<DateTime<Utc>> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: HeaderValue) -> Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
Ok(hdr_value) => match DateTime::parse_from_rfc3339(hdr_value) {
|
||||
Ok(date) => Ok(IntoHeaderValue(date.with_timezone(&Utc))),
|
||||
Err(e) => Err(format!("Unable to parse: {} as date - {}",
|
||||
hdr_value, e)),
|
||||
},
|
||||
Err(e) => Err(format!("Unable to convert header {:?} to string {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<IntoHeaderValue<DateTime<Utc>>> for HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: IntoHeaderValue<DateTime<Utc>>) -> Result<Self, Self::Error> {
|
||||
match HeaderValue::from_str(hdr_value.0.to_rfc3339().as_str()) {
|
||||
Ok(hdr_value) => Ok(hdr_value),
|
||||
Err(e) => Err(format!("Unable to convert {:?} to a header: {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -124,16 +124,38 @@ impl ::std::str::FromStr for {{{classname}}} {
|
||||
// Methods for converting between header::IntoHeaderValue<{{{classname}}}> and hyper::header::HeaderValue
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<header::IntoHeaderValue<{{{classname}}}>> for hyper::header::HeaderValue {
|
||||
fn from(hdr_value: header::IntoHeaderValue<{{{classname}}}>) -> Self {
|
||||
hyper::header::HeaderValue::from_str(&hdr_value.to_string()).unwrap()
|
||||
impl std::convert::TryFrom<header::IntoHeaderValue<{{{classname}}}>> for hyper::header::HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: header::IntoHeaderValue<{{{classname}}}>) -> std::result::Result<Self, Self::Error> {
|
||||
let hdr_value = hdr_value.to_string();
|
||||
match hyper::header::HeaderValue::from_str(&hdr_value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(value),
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Invalid header value for {{classname}} - value: {} is invalid {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<hyper::header::HeaderValue> for header::IntoHeaderValue<{{{classname}}}> {
|
||||
fn from(hdr_value: hyper::header::HeaderValue) -> Self {
|
||||
header::IntoHeaderValue(<{{{classname}}} as std::str::FromStr>::from_str(hdr_value.to_str().unwrap()).unwrap())
|
||||
impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderValue<{{{classname}}}> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
std::result::Result::Ok(value) => {
|
||||
match <{{{classname}}} as std::str::FromStr>::from_str(value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)),
|
||||
std::result::Result::Err(err) => std::result::Result::Err(
|
||||
format!("Unable to convert header value '{}' into {{classname}} - {}",
|
||||
value, err))
|
||||
}
|
||||
},
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Unable to convert header: {:?} to string: {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,8 @@ use hyper::{Request, Response, Error, StatusCode, Body, HeaderMap};
|
||||
use hyper::header::{HeaderName, HeaderValue, CONTENT_TYPE};
|
||||
use log::warn;
|
||||
use serde_json;
|
||||
#[allow(unused_imports)]
|
||||
use std::convert::{TryFrom, TryInto};
|
||||
use std::io;
|
||||
use url::form_urlencoded;
|
||||
#[allow(unused_imports)]
|
||||
|
@ -87,20 +87,35 @@
|
||||
{{/-first}}
|
||||
let param_{{{paramName}}} = headers.get(HeaderName::from_static("{{{nameInLowerCase}}}"));
|
||||
|
||||
{{#required}}
|
||||
let param_{{{paramName}}} = match param_{{{paramName}}} {
|
||||
Some(v) => header::IntoHeaderValue::<{{{dataType}}}>::from((*v).clone()).0,
|
||||
None => return Box::new(future::ok(Response::builder()
|
||||
.status(StatusCode::BAD_REQUEST)
|
||||
.body(Body::from("Missing or invalid required header {{{baseName}}}"))
|
||||
.expect("Unable to create Bad Request response for missing required header {{{baseName}}}"))),
|
||||
};
|
||||
Some(v) => match header::IntoHeaderValue::<{{{dataType}}}>::try_from((*v).clone()) {
|
||||
Ok(result) =>
|
||||
{{#required}}
|
||||
result.0,
|
||||
{{/required}}
|
||||
{{^required}}
|
||||
let param_{{{paramName}}} = param_{{{paramName}}}.map(|p| {
|
||||
header::IntoHeaderValue::<{{{dataType}}}>::from((*p).clone()).0
|
||||
});
|
||||
Some(result.0),
|
||||
{{/required}}
|
||||
Err(err) => {
|
||||
return Box::new(future::ok(Response::builder()
|
||||
.status(StatusCode::BAD_REQUEST)
|
||||
.body(Body::from(format!("Invalid header {{{baseName}}} - {}", err)))
|
||||
.expect("Unable to create Bad Request response for invalid header {{{baseName}}}")));
|
||||
|
||||
},
|
||||
},
|
||||
None => {
|
||||
{{#required}}
|
||||
return Box::new(future::ok(Response::builder()
|
||||
.status(StatusCode::BAD_REQUEST)
|
||||
.body(Body::from("Missing required header {{{baseName}}}"))
|
||||
.expect("Unable to create Bad Request response for missing required header {{{baseName}}}")));
|
||||
{{/required}}
|
||||
{{^required}}
|
||||
None
|
||||
{{/required}}
|
||||
}
|
||||
};
|
||||
{{#-last}}
|
||||
|
||||
{{/-last}}
|
||||
@ -486,11 +501,23 @@
|
||||
{{/headers}}
|
||||
{{/dataType}}
|
||||
=> {
|
||||
{{#headers}}
|
||||
let {{{name}}} = match header::IntoHeaderValue({{{name}}}).try_into() {
|
||||
Ok(val) => val,
|
||||
Err(e) => {
|
||||
return future::ok(Response::builder()
|
||||
.status(StatusCode::INTERNAL_SERVER_ERROR)
|
||||
.body(Body::from(format!("An internal server error occurred handling {{name}} header - {}", e)))
|
||||
.expect("Unable to create Internal Server Error for invalid response header"))
|
||||
}
|
||||
};
|
||||
|
||||
{{/headers}}
|
||||
*response.status_mut() = StatusCode::from_u16({{{code}}}).expect("Unable to turn {{{code}}} into a StatusCode");
|
||||
{{#headers}}
|
||||
response.headers_mut().insert(
|
||||
HeaderName::from_static("{{{nameInLowerCase}}}"),
|
||||
header::IntoHeaderValue({{name}}).into()
|
||||
{{name}}
|
||||
);
|
||||
{{/headers}}
|
||||
{{#produces}}
|
||||
|
@ -227,6 +227,9 @@ paths:
|
||||
Success-Info:
|
||||
schema:
|
||||
type: String
|
||||
Bool-Header:
|
||||
schema:
|
||||
type: bool
|
||||
Object-Header:
|
||||
schema:
|
||||
$ref: "#/components/schemas/ObjectHeader"
|
||||
|
@ -8,6 +8,7 @@ use hyper::{Body, Uri, Response};
|
||||
use hyper_openssl::HttpsConnector;
|
||||
use serde_json;
|
||||
use std::borrow::Cow;
|
||||
use std::convert::TryInto;
|
||||
use std::io::{Read, Error, ErrorKind};
|
||||
use std::error;
|
||||
use std::fmt;
|
||||
|
@ -1,5 +1,6 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use hyper::header::HeaderValue;
|
||||
use std::convert::TryFrom;
|
||||
use std::fmt;
|
||||
use std::ops::Deref;
|
||||
|
||||
@ -19,19 +20,31 @@ impl<T> Deref for IntoHeaderValue<T> {
|
||||
}
|
||||
}
|
||||
|
||||
// Derive for each From<T> in hyper::header::HeaderValue
|
||||
// Derive for each TryFrom<T> in hyper::header::HeaderValue
|
||||
|
||||
macro_rules! ihv_generate {
|
||||
($t:ident) => {
|
||||
impl From<HeaderValue> for IntoHeaderValue<$t> {
|
||||
fn from(hdr_value: HeaderValue) -> Self {
|
||||
IntoHeaderValue(hdr_value.to_str().unwrap().parse::<$t>().unwrap())
|
||||
impl TryFrom<HeaderValue> for IntoHeaderValue<$t> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: HeaderValue) -> Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
Ok(hdr_value) => match hdr_value.parse::<$t>() {
|
||||
Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value)),
|
||||
Err(e) => Err(format!("Unable to parse {} as a string: {}",
|
||||
stringify!($t), e)),
|
||||
},
|
||||
Err(e) => Err(format!("Unable to parse header {:?} as a string - {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IntoHeaderValue<$t>> for HeaderValue {
|
||||
fn from(hdr_value: IntoHeaderValue<$t>) -> Self {
|
||||
hdr_value.0.into()
|
||||
impl TryFrom<IntoHeaderValue<$t>> for HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: IntoHeaderValue<$t>) -> Result<Self, Self::Error> {
|
||||
Ok(hdr_value.0.into())
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -48,52 +61,120 @@ ihv_generate!(i32);
|
||||
|
||||
// Custom derivations
|
||||
|
||||
impl From<HeaderValue> for IntoHeaderValue<Vec<String>> {
|
||||
fn from(hdr_value: HeaderValue) -> Self {
|
||||
IntoHeaderValue(
|
||||
hdr_value
|
||||
.to_str()
|
||||
.unwrap()
|
||||
// Vec<String>
|
||||
|
||||
impl TryFrom<HeaderValue> for IntoHeaderValue<Vec<String>> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: HeaderValue) -> Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
Ok(hdr_value) => Ok(IntoHeaderValue(
|
||||
hdr_value
|
||||
.split(',')
|
||||
.filter_map(|x| match x.trim() {
|
||||
"" => None,
|
||||
y => Some(y.to_string()),
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
.collect())),
|
||||
Err(e) => Err(format!("Unable to parse header: {:?} as a string - {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IntoHeaderValue<Vec<String>>> for HeaderValue {
|
||||
fn from(hdr_value: IntoHeaderValue<Vec<String>>) -> Self {
|
||||
HeaderValue::from_str(&hdr_value.0.join(", ")).unwrap()
|
||||
impl TryFrom<IntoHeaderValue<Vec<String>>> for HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: IntoHeaderValue<Vec<String>>) -> Result<Self, Self::Error> {
|
||||
match HeaderValue::from_str(&hdr_value.0.join(", ")) {
|
||||
Ok(hdr_value) => Ok(hdr_value),
|
||||
Err(e) => Err(format!("Unable to convert {:?} into a header - {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<HeaderValue> for IntoHeaderValue<String> {
|
||||
fn from(hdr_value: HeaderValue) -> Self {
|
||||
IntoHeaderValue(hdr_value.to_str().unwrap().to_string())
|
||||
// String
|
||||
|
||||
impl TryFrom<HeaderValue> for IntoHeaderValue<String> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: HeaderValue) -> Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value.to_string())),
|
||||
Err(e) => Err(format!("Unable to convert header {:?} to {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IntoHeaderValue<String>> for HeaderValue {
|
||||
fn from(hdr_value: IntoHeaderValue<String>) -> Self {
|
||||
HeaderValue::from_str(&hdr_value.0).unwrap()
|
||||
impl TryFrom<IntoHeaderValue<String>> for HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: IntoHeaderValue<String>) -> Result<Self, Self::Error> {
|
||||
match HeaderValue::from_str(&hdr_value.0) {
|
||||
Ok(hdr_value) => Ok(hdr_value),
|
||||
Err(e) => Err(format!("Unable to convert {:?} from a header {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<HeaderValue> for IntoHeaderValue<DateTime<Utc>> {
|
||||
fn from(hdr_value: HeaderValue) -> Self {
|
||||
IntoHeaderValue(
|
||||
DateTime::parse_from_rfc3339(hdr_value.to_str().unwrap())
|
||||
.unwrap()
|
||||
.with_timezone(&Utc),
|
||||
)
|
||||
// bool
|
||||
impl TryFrom<HeaderValue> for IntoHeaderValue<bool> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: HeaderValue) -> Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
Ok(hdr_value) => match hdr_value.parse() {
|
||||
Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value)),
|
||||
Err(e) => Err(format!("Unable to parse bool from {} - {}",
|
||||
hdr_value, e)),
|
||||
},
|
||||
Err(e) => Err(format!("Unable to convert {:?} from a header {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IntoHeaderValue<DateTime<Utc>>> for HeaderValue {
|
||||
fn from(hdr_value: IntoHeaderValue<DateTime<Utc>>) -> Self {
|
||||
HeaderValue::from_str(hdr_value.0.to_rfc3339().as_str()).unwrap()
|
||||
impl TryFrom<IntoHeaderValue<bool>> for HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: IntoHeaderValue<bool>) -> Result<Self, Self::Error> {
|
||||
match HeaderValue::from_str(&hdr_value.0.to_string()) {
|
||||
Ok(hdr_value) => Ok(hdr_value),
|
||||
Err(e) => Err(format!("Unable to convert: {:?} into a header: {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// DateTime
|
||||
|
||||
impl TryFrom<HeaderValue> for IntoHeaderValue<DateTime<Utc>> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: HeaderValue) -> Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
Ok(hdr_value) => match DateTime::parse_from_rfc3339(hdr_value) {
|
||||
Ok(date) => Ok(IntoHeaderValue(date.with_timezone(&Utc))),
|
||||
Err(e) => Err(format!("Unable to parse: {} as date - {}",
|
||||
hdr_value, e)),
|
||||
},
|
||||
Err(e) => Err(format!("Unable to convert header {:?} to string {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<IntoHeaderValue<DateTime<Utc>>> for HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: IntoHeaderValue<DateTime<Utc>>) -> Result<Self, Self::Error> {
|
||||
match HeaderValue::from_str(hdr_value.0.to_rfc3339().as_str()) {
|
||||
Ok(hdr_value) => Ok(hdr_value),
|
||||
Err(e) => Err(format!("Unable to convert {:?} to a header: {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,16 +8,38 @@ use crate::header;
|
||||
// Methods for converting between header::IntoHeaderValue<InlineObject> and hyper::header::HeaderValue
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<header::IntoHeaderValue<InlineObject>> for hyper::header::HeaderValue {
|
||||
fn from(hdr_value: header::IntoHeaderValue<InlineObject>) -> Self {
|
||||
hyper::header::HeaderValue::from_str(&hdr_value.to_string()).unwrap()
|
||||
impl std::convert::TryFrom<header::IntoHeaderValue<InlineObject>> for hyper::header::HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: header::IntoHeaderValue<InlineObject>) -> std::result::Result<Self, Self::Error> {
|
||||
let hdr_value = hdr_value.to_string();
|
||||
match hyper::header::HeaderValue::from_str(&hdr_value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(value),
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Invalid header value for InlineObject - value: {} is invalid {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<hyper::header::HeaderValue> for header::IntoHeaderValue<InlineObject> {
|
||||
fn from(hdr_value: hyper::header::HeaderValue) -> Self {
|
||||
header::IntoHeaderValue(<InlineObject as std::str::FromStr>::from_str(hdr_value.to_str().unwrap()).unwrap())
|
||||
impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderValue<InlineObject> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
std::result::Result::Ok(value) => {
|
||||
match <InlineObject as std::str::FromStr>::from_str(value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)),
|
||||
std::result::Result::Err(err) => std::result::Result::Err(
|
||||
format!("Unable to convert header value '{}' into InlineObject - {}",
|
||||
value, err))
|
||||
}
|
||||
},
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Unable to convert header: {:?} to string: {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -111,16 +133,38 @@ impl std::str::FromStr for InlineObject {
|
||||
// Methods for converting between header::IntoHeaderValue<MultipartRelatedRequest> and hyper::header::HeaderValue
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<header::IntoHeaderValue<MultipartRelatedRequest>> for hyper::header::HeaderValue {
|
||||
fn from(hdr_value: header::IntoHeaderValue<MultipartRelatedRequest>) -> Self {
|
||||
hyper::header::HeaderValue::from_str(&hdr_value.to_string()).unwrap()
|
||||
impl std::convert::TryFrom<header::IntoHeaderValue<MultipartRelatedRequest>> for hyper::header::HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: header::IntoHeaderValue<MultipartRelatedRequest>) -> std::result::Result<Self, Self::Error> {
|
||||
let hdr_value = hdr_value.to_string();
|
||||
match hyper::header::HeaderValue::from_str(&hdr_value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(value),
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Invalid header value for MultipartRelatedRequest - value: {} is invalid {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<hyper::header::HeaderValue> for header::IntoHeaderValue<MultipartRelatedRequest> {
|
||||
fn from(hdr_value: hyper::header::HeaderValue) -> Self {
|
||||
header::IntoHeaderValue(<MultipartRelatedRequest as std::str::FromStr>::from_str(hdr_value.to_str().unwrap()).unwrap())
|
||||
impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderValue<MultipartRelatedRequest> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
std::result::Result::Ok(value) => {
|
||||
match <MultipartRelatedRequest as std::str::FromStr>::from_str(value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)),
|
||||
std::result::Result::Err(err) => std::result::Result::Err(
|
||||
format!("Unable to convert header value '{}' into MultipartRelatedRequest - {}",
|
||||
value, err))
|
||||
}
|
||||
},
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Unable to convert header: {:?} to string: {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -223,16 +267,38 @@ impl std::str::FromStr for MultipartRelatedRequest {
|
||||
// Methods for converting between header::IntoHeaderValue<MultipartRequest> and hyper::header::HeaderValue
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<header::IntoHeaderValue<MultipartRequest>> for hyper::header::HeaderValue {
|
||||
fn from(hdr_value: header::IntoHeaderValue<MultipartRequest>) -> Self {
|
||||
hyper::header::HeaderValue::from_str(&hdr_value.to_string()).unwrap()
|
||||
impl std::convert::TryFrom<header::IntoHeaderValue<MultipartRequest>> for hyper::header::HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: header::IntoHeaderValue<MultipartRequest>) -> std::result::Result<Self, Self::Error> {
|
||||
let hdr_value = hdr_value.to_string();
|
||||
match hyper::header::HeaderValue::from_str(&hdr_value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(value),
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Invalid header value for MultipartRequest - value: {} is invalid {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<hyper::header::HeaderValue> for header::IntoHeaderValue<MultipartRequest> {
|
||||
fn from(hdr_value: hyper::header::HeaderValue) -> Self {
|
||||
header::IntoHeaderValue(<MultipartRequest as std::str::FromStr>::from_str(hdr_value.to_str().unwrap()).unwrap())
|
||||
impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderValue<MultipartRequest> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
std::result::Result::Ok(value) => {
|
||||
match <MultipartRequest as std::str::FromStr>::from_str(value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)),
|
||||
std::result::Result::Err(err) => std::result::Result::Err(
|
||||
format!("Unable to convert header value '{}' into MultipartRequest - {}",
|
||||
value, err))
|
||||
}
|
||||
},
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Unable to convert header: {:?} to string: {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -349,16 +415,38 @@ impl std::str::FromStr for MultipartRequest {
|
||||
// Methods for converting between header::IntoHeaderValue<MultipartRequestObjectField> and hyper::header::HeaderValue
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<header::IntoHeaderValue<MultipartRequestObjectField>> for hyper::header::HeaderValue {
|
||||
fn from(hdr_value: header::IntoHeaderValue<MultipartRequestObjectField>) -> Self {
|
||||
hyper::header::HeaderValue::from_str(&hdr_value.to_string()).unwrap()
|
||||
impl std::convert::TryFrom<header::IntoHeaderValue<MultipartRequestObjectField>> for hyper::header::HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: header::IntoHeaderValue<MultipartRequestObjectField>) -> std::result::Result<Self, Self::Error> {
|
||||
let hdr_value = hdr_value.to_string();
|
||||
match hyper::header::HeaderValue::from_str(&hdr_value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(value),
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Invalid header value for MultipartRequestObjectField - value: {} is invalid {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<hyper::header::HeaderValue> for header::IntoHeaderValue<MultipartRequestObjectField> {
|
||||
fn from(hdr_value: hyper::header::HeaderValue) -> Self {
|
||||
header::IntoHeaderValue(<MultipartRequestObjectField as std::str::FromStr>::from_str(hdr_value.to_str().unwrap()).unwrap())
|
||||
impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderValue<MultipartRequestObjectField> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
std::result::Result::Ok(value) => {
|
||||
match <MultipartRequestObjectField as std::str::FromStr>::from_str(value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)),
|
||||
std::result::Result::Err(err) => std::result::Result::Err(
|
||||
format!("Unable to convert header value '{}' into MultipartRequestObjectField - {}",
|
||||
value, err))
|
||||
}
|
||||
},
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Unable to convert header: {:?} to string: {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,8 @@ use hyper::{Request, Response, Error, StatusCode, Body, HeaderMap};
|
||||
use hyper::header::{HeaderName, HeaderValue, CONTENT_TYPE};
|
||||
use log::warn;
|
||||
use serde_json;
|
||||
#[allow(unused_imports)]
|
||||
use std::convert::{TryFrom, TryInto};
|
||||
use std::io;
|
||||
use url::form_urlencoded;
|
||||
#[allow(unused_imports)]
|
||||
|
@ -8,6 +8,7 @@ use hyper::{Body, Uri, Response};
|
||||
use hyper_openssl::HttpsConnector;
|
||||
use serde_json;
|
||||
use std::borrow::Cow;
|
||||
use std::convert::TryInto;
|
||||
use std::io::{Read, Error, ErrorKind};
|
||||
use std::error;
|
||||
use std::fmt;
|
||||
|
@ -1,5 +1,6 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use hyper::header::HeaderValue;
|
||||
use std::convert::TryFrom;
|
||||
use std::fmt;
|
||||
use std::ops::Deref;
|
||||
|
||||
@ -19,19 +20,31 @@ impl<T> Deref for IntoHeaderValue<T> {
|
||||
}
|
||||
}
|
||||
|
||||
// Derive for each From<T> in hyper::header::HeaderValue
|
||||
// Derive for each TryFrom<T> in hyper::header::HeaderValue
|
||||
|
||||
macro_rules! ihv_generate {
|
||||
($t:ident) => {
|
||||
impl From<HeaderValue> for IntoHeaderValue<$t> {
|
||||
fn from(hdr_value: HeaderValue) -> Self {
|
||||
IntoHeaderValue(hdr_value.to_str().unwrap().parse::<$t>().unwrap())
|
||||
impl TryFrom<HeaderValue> for IntoHeaderValue<$t> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: HeaderValue) -> Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
Ok(hdr_value) => match hdr_value.parse::<$t>() {
|
||||
Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value)),
|
||||
Err(e) => Err(format!("Unable to parse {} as a string: {}",
|
||||
stringify!($t), e)),
|
||||
},
|
||||
Err(e) => Err(format!("Unable to parse header {:?} as a string - {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IntoHeaderValue<$t>> for HeaderValue {
|
||||
fn from(hdr_value: IntoHeaderValue<$t>) -> Self {
|
||||
hdr_value.0.into()
|
||||
impl TryFrom<IntoHeaderValue<$t>> for HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: IntoHeaderValue<$t>) -> Result<Self, Self::Error> {
|
||||
Ok(hdr_value.0.into())
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -48,52 +61,120 @@ ihv_generate!(i32);
|
||||
|
||||
// Custom derivations
|
||||
|
||||
impl From<HeaderValue> for IntoHeaderValue<Vec<String>> {
|
||||
fn from(hdr_value: HeaderValue) -> Self {
|
||||
IntoHeaderValue(
|
||||
hdr_value
|
||||
.to_str()
|
||||
.unwrap()
|
||||
// Vec<String>
|
||||
|
||||
impl TryFrom<HeaderValue> for IntoHeaderValue<Vec<String>> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: HeaderValue) -> Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
Ok(hdr_value) => Ok(IntoHeaderValue(
|
||||
hdr_value
|
||||
.split(',')
|
||||
.filter_map(|x| match x.trim() {
|
||||
"" => None,
|
||||
y => Some(y.to_string()),
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
.collect())),
|
||||
Err(e) => Err(format!("Unable to parse header: {:?} as a string - {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IntoHeaderValue<Vec<String>>> for HeaderValue {
|
||||
fn from(hdr_value: IntoHeaderValue<Vec<String>>) -> Self {
|
||||
HeaderValue::from_str(&hdr_value.0.join(", ")).unwrap()
|
||||
impl TryFrom<IntoHeaderValue<Vec<String>>> for HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: IntoHeaderValue<Vec<String>>) -> Result<Self, Self::Error> {
|
||||
match HeaderValue::from_str(&hdr_value.0.join(", ")) {
|
||||
Ok(hdr_value) => Ok(hdr_value),
|
||||
Err(e) => Err(format!("Unable to convert {:?} into a header - {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<HeaderValue> for IntoHeaderValue<String> {
|
||||
fn from(hdr_value: HeaderValue) -> Self {
|
||||
IntoHeaderValue(hdr_value.to_str().unwrap().to_string())
|
||||
// String
|
||||
|
||||
impl TryFrom<HeaderValue> for IntoHeaderValue<String> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: HeaderValue) -> Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value.to_string())),
|
||||
Err(e) => Err(format!("Unable to convert header {:?} to {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IntoHeaderValue<String>> for HeaderValue {
|
||||
fn from(hdr_value: IntoHeaderValue<String>) -> Self {
|
||||
HeaderValue::from_str(&hdr_value.0).unwrap()
|
||||
impl TryFrom<IntoHeaderValue<String>> for HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: IntoHeaderValue<String>) -> Result<Self, Self::Error> {
|
||||
match HeaderValue::from_str(&hdr_value.0) {
|
||||
Ok(hdr_value) => Ok(hdr_value),
|
||||
Err(e) => Err(format!("Unable to convert {:?} from a header {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<HeaderValue> for IntoHeaderValue<DateTime<Utc>> {
|
||||
fn from(hdr_value: HeaderValue) -> Self {
|
||||
IntoHeaderValue(
|
||||
DateTime::parse_from_rfc3339(hdr_value.to_str().unwrap())
|
||||
.unwrap()
|
||||
.with_timezone(&Utc),
|
||||
)
|
||||
// bool
|
||||
impl TryFrom<HeaderValue> for IntoHeaderValue<bool> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: HeaderValue) -> Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
Ok(hdr_value) => match hdr_value.parse() {
|
||||
Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value)),
|
||||
Err(e) => Err(format!("Unable to parse bool from {} - {}",
|
||||
hdr_value, e)),
|
||||
},
|
||||
Err(e) => Err(format!("Unable to convert {:?} from a header {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IntoHeaderValue<DateTime<Utc>>> for HeaderValue {
|
||||
fn from(hdr_value: IntoHeaderValue<DateTime<Utc>>) -> Self {
|
||||
HeaderValue::from_str(hdr_value.0.to_rfc3339().as_str()).unwrap()
|
||||
impl TryFrom<IntoHeaderValue<bool>> for HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: IntoHeaderValue<bool>) -> Result<Self, Self::Error> {
|
||||
match HeaderValue::from_str(&hdr_value.0.to_string()) {
|
||||
Ok(hdr_value) => Ok(hdr_value),
|
||||
Err(e) => Err(format!("Unable to convert: {:?} into a header: {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// DateTime
|
||||
|
||||
impl TryFrom<HeaderValue> for IntoHeaderValue<DateTime<Utc>> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: HeaderValue) -> Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
Ok(hdr_value) => match DateTime::parse_from_rfc3339(hdr_value) {
|
||||
Ok(date) => Ok(IntoHeaderValue(date.with_timezone(&Utc))),
|
||||
Err(e) => Err(format!("Unable to parse: {} as date - {}",
|
||||
hdr_value, e)),
|
||||
},
|
||||
Err(e) => Err(format!("Unable to convert header {:?} to string {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<IntoHeaderValue<DateTime<Utc>>> for HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: IntoHeaderValue<DateTime<Utc>>) -> Result<Self, Self::Error> {
|
||||
match HeaderValue::from_str(hdr_value.0.to_rfc3339().as_str()) {
|
||||
Ok(hdr_value) => Ok(hdr_value),
|
||||
Err(e) => Err(format!("Unable to convert {:?} to a header: {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,16 +8,38 @@ use crate::header;
|
||||
// Methods for converting between header::IntoHeaderValue<InlineObject> and hyper::header::HeaderValue
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<header::IntoHeaderValue<InlineObject>> for hyper::header::HeaderValue {
|
||||
fn from(hdr_value: header::IntoHeaderValue<InlineObject>) -> Self {
|
||||
hyper::header::HeaderValue::from_str(&hdr_value.to_string()).unwrap()
|
||||
impl std::convert::TryFrom<header::IntoHeaderValue<InlineObject>> for hyper::header::HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: header::IntoHeaderValue<InlineObject>) -> std::result::Result<Self, Self::Error> {
|
||||
let hdr_value = hdr_value.to_string();
|
||||
match hyper::header::HeaderValue::from_str(&hdr_value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(value),
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Invalid header value for InlineObject - value: {} is invalid {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<hyper::header::HeaderValue> for header::IntoHeaderValue<InlineObject> {
|
||||
fn from(hdr_value: hyper::header::HeaderValue) -> Self {
|
||||
header::IntoHeaderValue(<InlineObject as std::str::FromStr>::from_str(hdr_value.to_str().unwrap()).unwrap())
|
||||
impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderValue<InlineObject> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
std::result::Result::Ok(value) => {
|
||||
match <InlineObject as std::str::FromStr>::from_str(value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)),
|
||||
std::result::Result::Err(err) => std::result::Result::Err(
|
||||
format!("Unable to convert header value '{}' into InlineObject - {}",
|
||||
value, err))
|
||||
}
|
||||
},
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Unable to convert header: {:?} to string: {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,8 @@ use hyper::{Request, Response, Error, StatusCode, Body, HeaderMap};
|
||||
use hyper::header::{HeaderName, HeaderValue, CONTENT_TYPE};
|
||||
use log::warn;
|
||||
use serde_json;
|
||||
#[allow(unused_imports)]
|
||||
use std::convert::{TryFrom, TryInto};
|
||||
use std::io;
|
||||
use url::form_urlencoded;
|
||||
#[allow(unused_imports)]
|
||||
|
@ -214,6 +214,11 @@ paths:
|
||||
schema:
|
||||
type: String
|
||||
style: simple
|
||||
Bool-Header:
|
||||
explode: false
|
||||
schema:
|
||||
type: bool
|
||||
style: simple
|
||||
Object-Header:
|
||||
explode: false
|
||||
schema:
|
||||
|
@ -5,6 +5,8 @@ use hyper::{Request, Response, Error, StatusCode, Body, HeaderMap};
|
||||
use hyper::header::{HeaderName, HeaderValue, CONTENT_TYPE};
|
||||
use log::warn;
|
||||
use serde_json;
|
||||
#[allow(unused_imports)]
|
||||
use std::convert::{TryFrom, TryInto};
|
||||
use std::io;
|
||||
use url::form_urlencoded;
|
||||
#[allow(unused_imports)]
|
||||
@ -151,9 +153,22 @@ where
|
||||
// Header parameters
|
||||
let param_information = headers.get(HeaderName::from_static("information"));
|
||||
|
||||
let param_information = param_information.map(|p| {
|
||||
header::IntoHeaderValue::<String>::from((*p).clone()).0
|
||||
});
|
||||
let param_information = match param_information {
|
||||
Some(v) => match header::IntoHeaderValue::<String>::try_from((*v).clone()) {
|
||||
Ok(result) =>
|
||||
Some(result.0),
|
||||
Err(err) => {
|
||||
return Box::new(future::ok(Response::builder()
|
||||
.status(StatusCode::BAD_REQUEST)
|
||||
.body(Body::from(format!("Invalid header Information - {}", err)))
|
||||
.expect("Unable to create Bad Request response for invalid header Information")));
|
||||
|
||||
},
|
||||
},
|
||||
None => {
|
||||
None
|
||||
}
|
||||
};
|
||||
|
||||
Box::new({
|
||||
{{
|
||||
|
@ -8,6 +8,7 @@ use hyper::{Body, Uri, Response};
|
||||
use hyper_openssl::HttpsConnector;
|
||||
use serde_json;
|
||||
use std::borrow::Cow;
|
||||
use std::convert::TryInto;
|
||||
use std::io::{Read, Error, ErrorKind};
|
||||
use std::error;
|
||||
use std::fmt;
|
||||
@ -537,7 +538,13 @@ impl<C, F> Api<C> for Client<F> where
|
||||
// Header parameters
|
||||
request.headers_mut().append(
|
||||
HeaderName::from_static("x-header"),
|
||||
header::IntoHeaderValue(param_x_header.clone()).into());
|
||||
match header::IntoHeaderValue(param_x_header.clone()).try_into() {
|
||||
Ok(header) => header,
|
||||
Err(e) => {
|
||||
return Box::new(future::err(ApiError(format!(
|
||||
"Invalid header x_header - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
|
||||
},
|
||||
});
|
||||
|
||||
Box::new(self.client_service.request(request)
|
||||
.map_err(|e| ApiError(format!("No response received: {}", e)))
|
||||
@ -1396,10 +1403,38 @@ impl<C, F> Api<C> for Client<F> where
|
||||
Some(response_success_info) => response_success_info.clone(),
|
||||
None => return Box::new(future::err(ApiError(String::from("Required response header Success-Info for response 200 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
|
||||
};
|
||||
let response_success_info = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_success_info) {
|
||||
Ok(value) => value,
|
||||
Err(e) => {
|
||||
return Box::new(future::err(ApiError(format!("Invalid response header Success-Info for response 200 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
|
||||
},
|
||||
};
|
||||
let response_success_info = response_success_info.0;
|
||||
|
||||
let response_bool_header = match response.headers().get(HeaderName::from_static("bool-header")) {
|
||||
Some(response_bool_header) => response_bool_header.clone(),
|
||||
None => return Box::new(future::err(ApiError(String::from("Required response header Bool-Header for response 200 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
|
||||
};
|
||||
let response_bool_header = match TryInto::<header::IntoHeaderValue<bool>>::try_into(response_bool_header) {
|
||||
Ok(value) => value,
|
||||
Err(e) => {
|
||||
return Box::new(future::err(ApiError(format!("Invalid response header Bool-Header for response 200 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
|
||||
},
|
||||
};
|
||||
let response_bool_header = response_bool_header.0;
|
||||
|
||||
let response_object_header = match response.headers().get(HeaderName::from_static("object-header")) {
|
||||
Some(response_object_header) => response_object_header.clone(),
|
||||
None => return Box::new(future::err(ApiError(String::from("Required response header Object-Header for response 200 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
|
||||
};
|
||||
let response_object_header = match TryInto::<header::IntoHeaderValue<models::ObjectHeader>>::try_into(response_object_header) {
|
||||
Ok(value) => value,
|
||||
Err(e) => {
|
||||
return Box::new(future::err(ApiError(format!("Invalid response header Object-Header for response 200 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
|
||||
},
|
||||
};
|
||||
let response_object_header = response_object_header.0;
|
||||
|
||||
let body = response.into_body();
|
||||
Box::new(
|
||||
body
|
||||
@ -1417,8 +1452,9 @@ impl<C, F> Api<C> for Client<F> where
|
||||
ResponsesWithHeadersGetResponse::Success
|
||||
{
|
||||
body: body,
|
||||
success_info: (*Into::<header::IntoHeaderValue<String>>::into(response_success_info)).clone(),
|
||||
object_header: (*Into::<header::IntoHeaderValue<models::ObjectHeader>>::into(response_object_header)).clone(),
|
||||
success_info: response_success_info,
|
||||
bool_header: response_bool_header,
|
||||
object_header: response_object_header,
|
||||
}
|
||||
})
|
||||
) as Box<dyn Future<Item=_, Error=_> + Send>
|
||||
@ -1428,17 +1464,33 @@ impl<C, F> Api<C> for Client<F> where
|
||||
Some(response_further_info) => response_further_info.clone(),
|
||||
None => return Box::new(future::err(ApiError(String::from("Required response header Further-Info for response 412 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
|
||||
};
|
||||
let response_further_info = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_further_info) {
|
||||
Ok(value) => value,
|
||||
Err(e) => {
|
||||
return Box::new(future::err(ApiError(format!("Invalid response header Further-Info for response 412 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
|
||||
},
|
||||
};
|
||||
let response_further_info = response_further_info.0;
|
||||
|
||||
let response_failure_info = match response.headers().get(HeaderName::from_static("failure-info")) {
|
||||
Some(response_failure_info) => response_failure_info.clone(),
|
||||
None => return Box::new(future::err(ApiError(String::from("Required response header Failure-Info for response 412 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
|
||||
};
|
||||
let response_failure_info = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_failure_info) {
|
||||
Ok(value) => value,
|
||||
Err(e) => {
|
||||
return Box::new(future::err(ApiError(format!("Invalid response header Failure-Info for response 412 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
|
||||
},
|
||||
};
|
||||
let response_failure_info = response_failure_info.0;
|
||||
|
||||
let body = response.into_body();
|
||||
Box::new(
|
||||
future::ok(
|
||||
ResponsesWithHeadersGetResponse::PreconditionFailed
|
||||
{
|
||||
further_info: (*Into::<header::IntoHeaderValue<String>>::into(response_further_info)).clone(),
|
||||
failure_info: (*Into::<header::IntoHeaderValue<String>>::into(response_failure_info)).clone(),
|
||||
further_info: response_further_info,
|
||||
failure_info: response_failure_info,
|
||||
}
|
||||
)
|
||||
) as Box<dyn Future<Item=_, Error=_> + Send>
|
||||
|
@ -1,5 +1,6 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use hyper::header::HeaderValue;
|
||||
use std::convert::TryFrom;
|
||||
use std::fmt;
|
||||
use std::ops::Deref;
|
||||
|
||||
@ -19,19 +20,31 @@ impl<T> Deref for IntoHeaderValue<T> {
|
||||
}
|
||||
}
|
||||
|
||||
// Derive for each From<T> in hyper::header::HeaderValue
|
||||
// Derive for each TryFrom<T> in hyper::header::HeaderValue
|
||||
|
||||
macro_rules! ihv_generate {
|
||||
($t:ident) => {
|
||||
impl From<HeaderValue> for IntoHeaderValue<$t> {
|
||||
fn from(hdr_value: HeaderValue) -> Self {
|
||||
IntoHeaderValue(hdr_value.to_str().unwrap().parse::<$t>().unwrap())
|
||||
impl TryFrom<HeaderValue> for IntoHeaderValue<$t> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: HeaderValue) -> Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
Ok(hdr_value) => match hdr_value.parse::<$t>() {
|
||||
Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value)),
|
||||
Err(e) => Err(format!("Unable to parse {} as a string: {}",
|
||||
stringify!($t), e)),
|
||||
},
|
||||
Err(e) => Err(format!("Unable to parse header {:?} as a string - {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IntoHeaderValue<$t>> for HeaderValue {
|
||||
fn from(hdr_value: IntoHeaderValue<$t>) -> Self {
|
||||
hdr_value.0.into()
|
||||
impl TryFrom<IntoHeaderValue<$t>> for HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: IntoHeaderValue<$t>) -> Result<Self, Self::Error> {
|
||||
Ok(hdr_value.0.into())
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -48,52 +61,120 @@ ihv_generate!(i32);
|
||||
|
||||
// Custom derivations
|
||||
|
||||
impl From<HeaderValue> for IntoHeaderValue<Vec<String>> {
|
||||
fn from(hdr_value: HeaderValue) -> Self {
|
||||
IntoHeaderValue(
|
||||
hdr_value
|
||||
.to_str()
|
||||
.unwrap()
|
||||
// Vec<String>
|
||||
|
||||
impl TryFrom<HeaderValue> for IntoHeaderValue<Vec<String>> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: HeaderValue) -> Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
Ok(hdr_value) => Ok(IntoHeaderValue(
|
||||
hdr_value
|
||||
.split(',')
|
||||
.filter_map(|x| match x.trim() {
|
||||
"" => None,
|
||||
y => Some(y.to_string()),
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
.collect())),
|
||||
Err(e) => Err(format!("Unable to parse header: {:?} as a string - {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IntoHeaderValue<Vec<String>>> for HeaderValue {
|
||||
fn from(hdr_value: IntoHeaderValue<Vec<String>>) -> Self {
|
||||
HeaderValue::from_str(&hdr_value.0.join(", ")).unwrap()
|
||||
impl TryFrom<IntoHeaderValue<Vec<String>>> for HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: IntoHeaderValue<Vec<String>>) -> Result<Self, Self::Error> {
|
||||
match HeaderValue::from_str(&hdr_value.0.join(", ")) {
|
||||
Ok(hdr_value) => Ok(hdr_value),
|
||||
Err(e) => Err(format!("Unable to convert {:?} into a header - {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<HeaderValue> for IntoHeaderValue<String> {
|
||||
fn from(hdr_value: HeaderValue) -> Self {
|
||||
IntoHeaderValue(hdr_value.to_str().unwrap().to_string())
|
||||
// String
|
||||
|
||||
impl TryFrom<HeaderValue> for IntoHeaderValue<String> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: HeaderValue) -> Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value.to_string())),
|
||||
Err(e) => Err(format!("Unable to convert header {:?} to {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IntoHeaderValue<String>> for HeaderValue {
|
||||
fn from(hdr_value: IntoHeaderValue<String>) -> Self {
|
||||
HeaderValue::from_str(&hdr_value.0).unwrap()
|
||||
impl TryFrom<IntoHeaderValue<String>> for HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: IntoHeaderValue<String>) -> Result<Self, Self::Error> {
|
||||
match HeaderValue::from_str(&hdr_value.0) {
|
||||
Ok(hdr_value) => Ok(hdr_value),
|
||||
Err(e) => Err(format!("Unable to convert {:?} from a header {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<HeaderValue> for IntoHeaderValue<DateTime<Utc>> {
|
||||
fn from(hdr_value: HeaderValue) -> Self {
|
||||
IntoHeaderValue(
|
||||
DateTime::parse_from_rfc3339(hdr_value.to_str().unwrap())
|
||||
.unwrap()
|
||||
.with_timezone(&Utc),
|
||||
)
|
||||
// bool
|
||||
impl TryFrom<HeaderValue> for IntoHeaderValue<bool> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: HeaderValue) -> Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
Ok(hdr_value) => match hdr_value.parse() {
|
||||
Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value)),
|
||||
Err(e) => Err(format!("Unable to parse bool from {} - {}",
|
||||
hdr_value, e)),
|
||||
},
|
||||
Err(e) => Err(format!("Unable to convert {:?} from a header {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IntoHeaderValue<DateTime<Utc>>> for HeaderValue {
|
||||
fn from(hdr_value: IntoHeaderValue<DateTime<Utc>>) -> Self {
|
||||
HeaderValue::from_str(hdr_value.0.to_rfc3339().as_str()).unwrap()
|
||||
impl TryFrom<IntoHeaderValue<bool>> for HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: IntoHeaderValue<bool>) -> Result<Self, Self::Error> {
|
||||
match HeaderValue::from_str(&hdr_value.0.to_string()) {
|
||||
Ok(hdr_value) => Ok(hdr_value),
|
||||
Err(e) => Err(format!("Unable to convert: {:?} into a header: {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// DateTime
|
||||
|
||||
impl TryFrom<HeaderValue> for IntoHeaderValue<DateTime<Utc>> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: HeaderValue) -> Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
Ok(hdr_value) => match DateTime::parse_from_rfc3339(hdr_value) {
|
||||
Ok(date) => Ok(IntoHeaderValue(date.with_timezone(&Utc))),
|
||||
Err(e) => Err(format!("Unable to parse: {} as date - {}",
|
||||
hdr_value, e)),
|
||||
},
|
||||
Err(e) => Err(format!("Unable to convert header {:?} to string {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<IntoHeaderValue<DateTime<Utc>>> for HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: IntoHeaderValue<DateTime<Utc>>) -> Result<Self, Self::Error> {
|
||||
match HeaderValue::from_str(hdr_value.0.to_rfc3339().as_str()) {
|
||||
Ok(hdr_value) => Ok(hdr_value),
|
||||
Err(e) => Err(format!("Unable to convert {:?} to a header: {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -119,6 +119,7 @@ pub enum ResponsesWithHeadersGetResponse {
|
||||
{
|
||||
body: String,
|
||||
success_info: String,
|
||||
bool_header: bool,
|
||||
object_header: models::ObjectHeader
|
||||
}
|
||||
,
|
||||
|
@ -8,16 +8,38 @@ use crate::header;
|
||||
// Methods for converting between header::IntoHeaderValue<AnotherXmlArray> and hyper::header::HeaderValue
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<header::IntoHeaderValue<AnotherXmlArray>> for hyper::header::HeaderValue {
|
||||
fn from(hdr_value: header::IntoHeaderValue<AnotherXmlArray>) -> Self {
|
||||
hyper::header::HeaderValue::from_str(&hdr_value.to_string()).unwrap()
|
||||
impl std::convert::TryFrom<header::IntoHeaderValue<AnotherXmlArray>> for hyper::header::HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: header::IntoHeaderValue<AnotherXmlArray>) -> std::result::Result<Self, Self::Error> {
|
||||
let hdr_value = hdr_value.to_string();
|
||||
match hyper::header::HeaderValue::from_str(&hdr_value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(value),
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Invalid header value for AnotherXmlArray - value: {} is invalid {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<hyper::header::HeaderValue> for header::IntoHeaderValue<AnotherXmlArray> {
|
||||
fn from(hdr_value: hyper::header::HeaderValue) -> Self {
|
||||
header::IntoHeaderValue(<AnotherXmlArray as std::str::FromStr>::from_str(hdr_value.to_str().unwrap()).unwrap())
|
||||
impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderValue<AnotherXmlArray> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
std::result::Result::Ok(value) => {
|
||||
match <AnotherXmlArray as std::str::FromStr>::from_str(value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)),
|
||||
std::result::Result::Err(err) => std::result::Result::Err(
|
||||
format!("Unable to convert header value '{}' into AnotherXmlArray - {}",
|
||||
value, err))
|
||||
}
|
||||
},
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Unable to convert header: {:?} to string: {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -187,16 +209,38 @@ impl AnotherXmlInner {
|
||||
// Methods for converting between header::IntoHeaderValue<AnotherXmlObject> and hyper::header::HeaderValue
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<header::IntoHeaderValue<AnotherXmlObject>> for hyper::header::HeaderValue {
|
||||
fn from(hdr_value: header::IntoHeaderValue<AnotherXmlObject>) -> Self {
|
||||
hyper::header::HeaderValue::from_str(&hdr_value.to_string()).unwrap()
|
||||
impl std::convert::TryFrom<header::IntoHeaderValue<AnotherXmlObject>> for hyper::header::HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: header::IntoHeaderValue<AnotherXmlObject>) -> std::result::Result<Self, Self::Error> {
|
||||
let hdr_value = hdr_value.to_string();
|
||||
match hyper::header::HeaderValue::from_str(&hdr_value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(value),
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Invalid header value for AnotherXmlObject - value: {} is invalid {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<hyper::header::HeaderValue> for header::IntoHeaderValue<AnotherXmlObject> {
|
||||
fn from(hdr_value: hyper::header::HeaderValue) -> Self {
|
||||
header::IntoHeaderValue(<AnotherXmlObject as std::str::FromStr>::from_str(hdr_value.to_str().unwrap()).unwrap())
|
||||
impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderValue<AnotherXmlObject> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
std::result::Result::Ok(value) => {
|
||||
match <AnotherXmlObject as std::str::FromStr>::from_str(value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)),
|
||||
std::result::Result::Err(err) => std::result::Result::Err(
|
||||
format!("Unable to convert header value '{}' into AnotherXmlObject - {}",
|
||||
value, err))
|
||||
}
|
||||
},
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Unable to convert header: {:?} to string: {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -301,16 +345,38 @@ impl AnotherXmlObject {
|
||||
// Methods for converting between header::IntoHeaderValue<DuplicateXmlObject> and hyper::header::HeaderValue
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<header::IntoHeaderValue<DuplicateXmlObject>> for hyper::header::HeaderValue {
|
||||
fn from(hdr_value: header::IntoHeaderValue<DuplicateXmlObject>) -> Self {
|
||||
hyper::header::HeaderValue::from_str(&hdr_value.to_string()).unwrap()
|
||||
impl std::convert::TryFrom<header::IntoHeaderValue<DuplicateXmlObject>> for hyper::header::HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: header::IntoHeaderValue<DuplicateXmlObject>) -> std::result::Result<Self, Self::Error> {
|
||||
let hdr_value = hdr_value.to_string();
|
||||
match hyper::header::HeaderValue::from_str(&hdr_value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(value),
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Invalid header value for DuplicateXmlObject - value: {} is invalid {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<hyper::header::HeaderValue> for header::IntoHeaderValue<DuplicateXmlObject> {
|
||||
fn from(hdr_value: hyper::header::HeaderValue) -> Self {
|
||||
header::IntoHeaderValue(<DuplicateXmlObject as std::str::FromStr>::from_str(hdr_value.to_str().unwrap()).unwrap())
|
||||
impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderValue<DuplicateXmlObject> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
std::result::Result::Ok(value) => {
|
||||
match <DuplicateXmlObject as std::str::FromStr>::from_str(value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)),
|
||||
std::result::Result::Err(err) => std::result::Result::Err(
|
||||
format!("Unable to convert header value '{}' into DuplicateXmlObject - {}",
|
||||
value, err))
|
||||
}
|
||||
},
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Unable to convert header: {:?} to string: {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -577,16 +643,38 @@ impl Error {
|
||||
// Methods for converting between header::IntoHeaderValue<InlineResponse201> and hyper::header::HeaderValue
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<header::IntoHeaderValue<InlineResponse201>> for hyper::header::HeaderValue {
|
||||
fn from(hdr_value: header::IntoHeaderValue<InlineResponse201>) -> Self {
|
||||
hyper::header::HeaderValue::from_str(&hdr_value.to_string()).unwrap()
|
||||
impl std::convert::TryFrom<header::IntoHeaderValue<InlineResponse201>> for hyper::header::HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: header::IntoHeaderValue<InlineResponse201>) -> std::result::Result<Self, Self::Error> {
|
||||
let hdr_value = hdr_value.to_string();
|
||||
match hyper::header::HeaderValue::from_str(&hdr_value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(value),
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Invalid header value for InlineResponse201 - value: {} is invalid {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<hyper::header::HeaderValue> for header::IntoHeaderValue<InlineResponse201> {
|
||||
fn from(hdr_value: hyper::header::HeaderValue) -> Self {
|
||||
header::IntoHeaderValue(<InlineResponse201 as std::str::FromStr>::from_str(hdr_value.to_str().unwrap()).unwrap())
|
||||
impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderValue<InlineResponse201> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
std::result::Result::Ok(value) => {
|
||||
match <InlineResponse201 as std::str::FromStr>::from_str(value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)),
|
||||
std::result::Result::Err(err) => std::result::Result::Err(
|
||||
format!("Unable to convert header value '{}' into InlineResponse201 - {}",
|
||||
value, err))
|
||||
}
|
||||
},
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Unable to convert header: {:?} to string: {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -720,16 +808,38 @@ impl MyId {
|
||||
// Methods for converting between header::IntoHeaderValue<MyIdList> and hyper::header::HeaderValue
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<header::IntoHeaderValue<MyIdList>> for hyper::header::HeaderValue {
|
||||
fn from(hdr_value: header::IntoHeaderValue<MyIdList>) -> Self {
|
||||
hyper::header::HeaderValue::from_str(&hdr_value.to_string()).unwrap()
|
||||
impl std::convert::TryFrom<header::IntoHeaderValue<MyIdList>> for hyper::header::HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: header::IntoHeaderValue<MyIdList>) -> std::result::Result<Self, Self::Error> {
|
||||
let hdr_value = hdr_value.to_string();
|
||||
match hyper::header::HeaderValue::from_str(&hdr_value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(value),
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Invalid header value for MyIdList - value: {} is invalid {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<hyper::header::HeaderValue> for header::IntoHeaderValue<MyIdList> {
|
||||
fn from(hdr_value: hyper::header::HeaderValue) -> Self {
|
||||
header::IntoHeaderValue(<MyIdList as std::str::FromStr>::from_str(hdr_value.to_str().unwrap()).unwrap())
|
||||
impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderValue<MyIdList> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
std::result::Result::Ok(value) => {
|
||||
match <MyIdList as std::str::FromStr>::from_str(value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)),
|
||||
std::result::Result::Err(err) => std::result::Result::Err(
|
||||
format!("Unable to convert header value '{}' into MyIdList - {}",
|
||||
value, err))
|
||||
}
|
||||
},
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Unable to convert header: {:?} to string: {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -835,16 +945,38 @@ impl MyIdList {
|
||||
// Methods for converting between header::IntoHeaderValue<NullableTest> and hyper::header::HeaderValue
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<header::IntoHeaderValue<NullableTest>> for hyper::header::HeaderValue {
|
||||
fn from(hdr_value: header::IntoHeaderValue<NullableTest>) -> Self {
|
||||
hyper::header::HeaderValue::from_str(&hdr_value.to_string()).unwrap()
|
||||
impl std::convert::TryFrom<header::IntoHeaderValue<NullableTest>> for hyper::header::HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: header::IntoHeaderValue<NullableTest>) -> std::result::Result<Self, Self::Error> {
|
||||
let hdr_value = hdr_value.to_string();
|
||||
match hyper::header::HeaderValue::from_str(&hdr_value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(value),
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Invalid header value for NullableTest - value: {} is invalid {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<hyper::header::HeaderValue> for header::IntoHeaderValue<NullableTest> {
|
||||
fn from(hdr_value: hyper::header::HeaderValue) -> Self {
|
||||
header::IntoHeaderValue(<NullableTest as std::str::FromStr>::from_str(hdr_value.to_str().unwrap()).unwrap())
|
||||
impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderValue<NullableTest> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
std::result::Result::Ok(value) => {
|
||||
match <NullableTest as std::str::FromStr>::from_str(value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)),
|
||||
std::result::Result::Err(err) => std::result::Result::Err(
|
||||
format!("Unable to convert header value '{}' into NullableTest - {}",
|
||||
value, err))
|
||||
}
|
||||
},
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Unable to convert header: {:?} to string: {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -999,16 +1131,38 @@ impl NullableTest {
|
||||
// Methods for converting between header::IntoHeaderValue<ObjectHeader> and hyper::header::HeaderValue
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<header::IntoHeaderValue<ObjectHeader>> for hyper::header::HeaderValue {
|
||||
fn from(hdr_value: header::IntoHeaderValue<ObjectHeader>) -> Self {
|
||||
hyper::header::HeaderValue::from_str(&hdr_value.to_string()).unwrap()
|
||||
impl std::convert::TryFrom<header::IntoHeaderValue<ObjectHeader>> for hyper::header::HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: header::IntoHeaderValue<ObjectHeader>) -> std::result::Result<Self, Self::Error> {
|
||||
let hdr_value = hdr_value.to_string();
|
||||
match hyper::header::HeaderValue::from_str(&hdr_value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(value),
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Invalid header value for ObjectHeader - value: {} is invalid {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<hyper::header::HeaderValue> for header::IntoHeaderValue<ObjectHeader> {
|
||||
fn from(hdr_value: hyper::header::HeaderValue) -> Self {
|
||||
header::IntoHeaderValue(<ObjectHeader as std::str::FromStr>::from_str(hdr_value.to_str().unwrap()).unwrap())
|
||||
impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderValue<ObjectHeader> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
std::result::Result::Ok(value) => {
|
||||
match <ObjectHeader as std::str::FromStr>::from_str(value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)),
|
||||
std::result::Result::Err(err) => std::result::Result::Err(
|
||||
format!("Unable to convert header value '{}' into ObjectHeader - {}",
|
||||
value, err))
|
||||
}
|
||||
},
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Unable to convert header: {:?} to string: {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1113,16 +1267,38 @@ impl ObjectHeader {
|
||||
// Methods for converting between header::IntoHeaderValue<ObjectParam> and hyper::header::HeaderValue
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<header::IntoHeaderValue<ObjectParam>> for hyper::header::HeaderValue {
|
||||
fn from(hdr_value: header::IntoHeaderValue<ObjectParam>) -> Self {
|
||||
hyper::header::HeaderValue::from_str(&hdr_value.to_string()).unwrap()
|
||||
impl std::convert::TryFrom<header::IntoHeaderValue<ObjectParam>> for hyper::header::HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: header::IntoHeaderValue<ObjectParam>) -> std::result::Result<Self, Self::Error> {
|
||||
let hdr_value = hdr_value.to_string();
|
||||
match hyper::header::HeaderValue::from_str(&hdr_value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(value),
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Invalid header value for ObjectParam - value: {} is invalid {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<hyper::header::HeaderValue> for header::IntoHeaderValue<ObjectParam> {
|
||||
fn from(hdr_value: hyper::header::HeaderValue) -> Self {
|
||||
header::IntoHeaderValue(<ObjectParam as std::str::FromStr>::from_str(hdr_value.to_str().unwrap()).unwrap())
|
||||
impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderValue<ObjectParam> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
std::result::Result::Ok(value) => {
|
||||
match <ObjectParam as std::str::FromStr>::from_str(value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)),
|
||||
std::result::Result::Err(err) => std::result::Result::Err(
|
||||
format!("Unable to convert header value '{}' into ObjectParam - {}",
|
||||
value, err))
|
||||
}
|
||||
},
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Unable to convert header: {:?} to string: {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1227,16 +1403,38 @@ impl ObjectParam {
|
||||
// Methods for converting between header::IntoHeaderValue<ObjectUntypedProps> and hyper::header::HeaderValue
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<header::IntoHeaderValue<ObjectUntypedProps>> for hyper::header::HeaderValue {
|
||||
fn from(hdr_value: header::IntoHeaderValue<ObjectUntypedProps>) -> Self {
|
||||
hyper::header::HeaderValue::from_str(&hdr_value.to_string()).unwrap()
|
||||
impl std::convert::TryFrom<header::IntoHeaderValue<ObjectUntypedProps>> for hyper::header::HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: header::IntoHeaderValue<ObjectUntypedProps>) -> std::result::Result<Self, Self::Error> {
|
||||
let hdr_value = hdr_value.to_string();
|
||||
match hyper::header::HeaderValue::from_str(&hdr_value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(value),
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Invalid header value for ObjectUntypedProps - value: {} is invalid {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<hyper::header::HeaderValue> for header::IntoHeaderValue<ObjectUntypedProps> {
|
||||
fn from(hdr_value: hyper::header::HeaderValue) -> Self {
|
||||
header::IntoHeaderValue(<ObjectUntypedProps as std::str::FromStr>::from_str(hdr_value.to_str().unwrap()).unwrap())
|
||||
impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderValue<ObjectUntypedProps> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
std::result::Result::Ok(value) => {
|
||||
match <ObjectUntypedProps as std::str::FromStr>::from_str(value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)),
|
||||
std::result::Result::Err(err) => std::result::Result::Err(
|
||||
format!("Unable to convert header value '{}' into ObjectUntypedProps - {}",
|
||||
value, err))
|
||||
}
|
||||
},
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Unable to convert header: {:?} to string: {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1354,16 +1552,38 @@ impl ObjectUntypedProps {
|
||||
// Methods for converting between header::IntoHeaderValue<ObjectWithArrayOfObjects> and hyper::header::HeaderValue
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<header::IntoHeaderValue<ObjectWithArrayOfObjects>> for hyper::header::HeaderValue {
|
||||
fn from(hdr_value: header::IntoHeaderValue<ObjectWithArrayOfObjects>) -> Self {
|
||||
hyper::header::HeaderValue::from_str(&hdr_value.to_string()).unwrap()
|
||||
impl std::convert::TryFrom<header::IntoHeaderValue<ObjectWithArrayOfObjects>> for hyper::header::HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: header::IntoHeaderValue<ObjectWithArrayOfObjects>) -> std::result::Result<Self, Self::Error> {
|
||||
let hdr_value = hdr_value.to_string();
|
||||
match hyper::header::HeaderValue::from_str(&hdr_value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(value),
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Invalid header value for ObjectWithArrayOfObjects - value: {} is invalid {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<hyper::header::HeaderValue> for header::IntoHeaderValue<ObjectWithArrayOfObjects> {
|
||||
fn from(hdr_value: hyper::header::HeaderValue) -> Self {
|
||||
header::IntoHeaderValue(<ObjectWithArrayOfObjects as std::str::FromStr>::from_str(hdr_value.to_str().unwrap()).unwrap())
|
||||
impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderValue<ObjectWithArrayOfObjects> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
std::result::Result::Ok(value) => {
|
||||
match <ObjectWithArrayOfObjects as std::str::FromStr>::from_str(value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)),
|
||||
std::result::Result::Err(err) => std::result::Result::Err(
|
||||
format!("Unable to convert header value '{}' into ObjectWithArrayOfObjects - {}",
|
||||
value, err))
|
||||
}
|
||||
},
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Unable to convert header: {:?} to string: {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1778,16 +1998,38 @@ impl UuidObject {
|
||||
// Methods for converting between header::IntoHeaderValue<XmlArray> and hyper::header::HeaderValue
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<header::IntoHeaderValue<XmlArray>> for hyper::header::HeaderValue {
|
||||
fn from(hdr_value: header::IntoHeaderValue<XmlArray>) -> Self {
|
||||
hyper::header::HeaderValue::from_str(&hdr_value.to_string()).unwrap()
|
||||
impl std::convert::TryFrom<header::IntoHeaderValue<XmlArray>> for hyper::header::HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: header::IntoHeaderValue<XmlArray>) -> std::result::Result<Self, Self::Error> {
|
||||
let hdr_value = hdr_value.to_string();
|
||||
match hyper::header::HeaderValue::from_str(&hdr_value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(value),
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Invalid header value for XmlArray - value: {} is invalid {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<hyper::header::HeaderValue> for header::IntoHeaderValue<XmlArray> {
|
||||
fn from(hdr_value: hyper::header::HeaderValue) -> Self {
|
||||
header::IntoHeaderValue(<XmlArray as std::str::FromStr>::from_str(hdr_value.to_str().unwrap()).unwrap())
|
||||
impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderValue<XmlArray> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
std::result::Result::Ok(value) => {
|
||||
match <XmlArray as std::str::FromStr>::from_str(value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)),
|
||||
std::result::Result::Err(err) => std::result::Result::Err(
|
||||
format!("Unable to convert header value '{}' into XmlArray - {}",
|
||||
value, err))
|
||||
}
|
||||
},
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Unable to convert header: {:?} to string: {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1957,16 +2199,38 @@ impl XmlInner {
|
||||
// Methods for converting between header::IntoHeaderValue<XmlObject> and hyper::header::HeaderValue
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<header::IntoHeaderValue<XmlObject>> for hyper::header::HeaderValue {
|
||||
fn from(hdr_value: header::IntoHeaderValue<XmlObject>) -> Self {
|
||||
hyper::header::HeaderValue::from_str(&hdr_value.to_string()).unwrap()
|
||||
impl std::convert::TryFrom<header::IntoHeaderValue<XmlObject>> for hyper::header::HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: header::IntoHeaderValue<XmlObject>) -> std::result::Result<Self, Self::Error> {
|
||||
let hdr_value = hdr_value.to_string();
|
||||
match hyper::header::HeaderValue::from_str(&hdr_value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(value),
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Invalid header value for XmlObject - value: {} is invalid {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<hyper::header::HeaderValue> for header::IntoHeaderValue<XmlObject> {
|
||||
fn from(hdr_value: hyper::header::HeaderValue) -> Self {
|
||||
header::IntoHeaderValue(<XmlObject as std::str::FromStr>::from_str(hdr_value.to_str().unwrap()).unwrap())
|
||||
impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderValue<XmlObject> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
std::result::Result::Ok(value) => {
|
||||
match <XmlObject as std::str::FromStr>::from_str(value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)),
|
||||
std::result::Result::Err(err) => std::result::Result::Err(
|
||||
format!("Unable to convert header value '{}' into XmlObject - {}",
|
||||
value, err))
|
||||
}
|
||||
},
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Unable to convert header: {:?} to string: {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ use hyper::{Body, Uri, Response};
|
||||
use hyper_openssl::HttpsConnector;
|
||||
use serde_json;
|
||||
use std::borrow::Cow;
|
||||
use std::convert::TryInto;
|
||||
use std::io::{Read, Error, ErrorKind};
|
||||
use std::error;
|
||||
use std::fmt;
|
||||
@ -211,9 +212,20 @@ impl<C, F> CallbackApi<C> for Client<F> where
|
||||
});
|
||||
|
||||
// Header parameters
|
||||
param_information.map(|value| request.headers_mut().append(
|
||||
match param_information {
|
||||
Some(param_information) => {
|
||||
request.headers_mut().append(
|
||||
HeaderName::from_static("information"),
|
||||
header::IntoHeaderValue(value.clone()).into()));
|
||||
match header::IntoHeaderValue(param_information.clone()).try_into() {
|
||||
Ok(header) => header,
|
||||
Err(e) => {
|
||||
return Box::new(future::err(ApiError(format!(
|
||||
"Invalid header information - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
|
||||
},
|
||||
});
|
||||
},
|
||||
None => {}
|
||||
}
|
||||
|
||||
Box::new(self.client_service.request(request)
|
||||
.map_err(|e| ApiError(format!("No response received: {}", e)))
|
||||
|
@ -5,6 +5,8 @@ use hyper::{Request, Response, Error, StatusCode, Body, HeaderMap};
|
||||
use hyper::header::{HeaderName, HeaderValue, CONTENT_TYPE};
|
||||
use log::warn;
|
||||
use serde_json;
|
||||
#[allow(unused_imports)]
|
||||
use std::convert::{TryFrom, TryInto};
|
||||
use std::io;
|
||||
use url::form_urlencoded;
|
||||
#[allow(unused_imports)]
|
||||
@ -365,11 +367,23 @@ where
|
||||
let param_x_header = headers.get(HeaderName::from_static("x-header"));
|
||||
|
||||
let param_x_header = match param_x_header {
|
||||
Some(v) => header::IntoHeaderValue::<String>::from((*v).clone()).0,
|
||||
None => return Box::new(future::ok(Response::builder()
|
||||
Some(v) => match header::IntoHeaderValue::<String>::try_from((*v).clone()) {
|
||||
Ok(result) =>
|
||||
result.0,
|
||||
Err(err) => {
|
||||
return Box::new(future::ok(Response::builder()
|
||||
.status(StatusCode::BAD_REQUEST)
|
||||
.body(Body::from("Missing or invalid required header X-Header"))
|
||||
.expect("Unable to create Bad Request response for missing required header X-Header"))),
|
||||
.body(Body::from(format!("Invalid header X-Header - {}", err)))
|
||||
.expect("Unable to create Bad Request response for invalid header X-Header")));
|
||||
|
||||
},
|
||||
},
|
||||
None => {
|
||||
return Box::new(future::ok(Response::builder()
|
||||
.status(StatusCode::BAD_REQUEST)
|
||||
.body(Body::from("Missing required header X-Header"))
|
||||
.expect("Unable to create Bad Request response for missing required header X-Header")));
|
||||
}
|
||||
};
|
||||
|
||||
Box::new({
|
||||
@ -920,17 +934,52 @@ where
|
||||
{
|
||||
body,
|
||||
success_info,
|
||||
bool_header,
|
||||
object_header
|
||||
}
|
||||
=> {
|
||||
let success_info = match header::IntoHeaderValue(success_info).try_into() {
|
||||
Ok(val) => val,
|
||||
Err(e) => {
|
||||
return future::ok(Response::builder()
|
||||
.status(StatusCode::INTERNAL_SERVER_ERROR)
|
||||
.body(Body::from(format!("An internal server error occurred handling success_info header - {}", e)))
|
||||
.expect("Unable to create Internal Server Error for invalid response header"))
|
||||
}
|
||||
};
|
||||
|
||||
let bool_header = match header::IntoHeaderValue(bool_header).try_into() {
|
||||
Ok(val) => val,
|
||||
Err(e) => {
|
||||
return future::ok(Response::builder()
|
||||
.status(StatusCode::INTERNAL_SERVER_ERROR)
|
||||
.body(Body::from(format!("An internal server error occurred handling bool_header header - {}", e)))
|
||||
.expect("Unable to create Internal Server Error for invalid response header"))
|
||||
}
|
||||
};
|
||||
|
||||
let object_header = match header::IntoHeaderValue(object_header).try_into() {
|
||||
Ok(val) => val,
|
||||
Err(e) => {
|
||||
return future::ok(Response::builder()
|
||||
.status(StatusCode::INTERNAL_SERVER_ERROR)
|
||||
.body(Body::from(format!("An internal server error occurred handling object_header header - {}", e)))
|
||||
.expect("Unable to create Internal Server Error for invalid response header"))
|
||||
}
|
||||
};
|
||||
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
response.headers_mut().insert(
|
||||
HeaderName::from_static("success-info"),
|
||||
header::IntoHeaderValue(success_info).into()
|
||||
success_info
|
||||
);
|
||||
response.headers_mut().insert(
|
||||
HeaderName::from_static("bool-header"),
|
||||
bool_header
|
||||
);
|
||||
response.headers_mut().insert(
|
||||
HeaderName::from_static("object-header"),
|
||||
header::IntoHeaderValue(object_header).into()
|
||||
object_header
|
||||
);
|
||||
response.headers_mut().insert(
|
||||
CONTENT_TYPE,
|
||||
@ -945,14 +994,34 @@ where
|
||||
failure_info
|
||||
}
|
||||
=> {
|
||||
let further_info = match header::IntoHeaderValue(further_info).try_into() {
|
||||
Ok(val) => val,
|
||||
Err(e) => {
|
||||
return future::ok(Response::builder()
|
||||
.status(StatusCode::INTERNAL_SERVER_ERROR)
|
||||
.body(Body::from(format!("An internal server error occurred handling further_info header - {}", e)))
|
||||
.expect("Unable to create Internal Server Error for invalid response header"))
|
||||
}
|
||||
};
|
||||
|
||||
let failure_info = match header::IntoHeaderValue(failure_info).try_into() {
|
||||
Ok(val) => val,
|
||||
Err(e) => {
|
||||
return future::ok(Response::builder()
|
||||
.status(StatusCode::INTERNAL_SERVER_ERROR)
|
||||
.body(Body::from(format!("An internal server error occurred handling failure_info header - {}", e)))
|
||||
.expect("Unable to create Internal Server Error for invalid response header"))
|
||||
}
|
||||
};
|
||||
|
||||
*response.status_mut() = StatusCode::from_u16(412).expect("Unable to turn 412 into a StatusCode");
|
||||
response.headers_mut().insert(
|
||||
HeaderName::from_static("further-info"),
|
||||
header::IntoHeaderValue(further_info).into()
|
||||
further_info
|
||||
);
|
||||
response.headers_mut().insert(
|
||||
HeaderName::from_static("failure-info"),
|
||||
header::IntoHeaderValue(failure_info).into()
|
||||
failure_info
|
||||
);
|
||||
},
|
||||
},
|
||||
|
@ -8,6 +8,7 @@ use hyper::{Body, Uri, Response};
|
||||
use hyper_openssl::HttpsConnector;
|
||||
use serde_json;
|
||||
use std::borrow::Cow;
|
||||
use std::convert::TryInto;
|
||||
use std::io::{Read, Error, ErrorKind};
|
||||
use std::error;
|
||||
use std::fmt;
|
||||
|
@ -1,5 +1,6 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use hyper::header::HeaderValue;
|
||||
use std::convert::TryFrom;
|
||||
use std::fmt;
|
||||
use std::ops::Deref;
|
||||
|
||||
@ -19,19 +20,31 @@ impl<T> Deref for IntoHeaderValue<T> {
|
||||
}
|
||||
}
|
||||
|
||||
// Derive for each From<T> in hyper::header::HeaderValue
|
||||
// Derive for each TryFrom<T> in hyper::header::HeaderValue
|
||||
|
||||
macro_rules! ihv_generate {
|
||||
($t:ident) => {
|
||||
impl From<HeaderValue> for IntoHeaderValue<$t> {
|
||||
fn from(hdr_value: HeaderValue) -> Self {
|
||||
IntoHeaderValue(hdr_value.to_str().unwrap().parse::<$t>().unwrap())
|
||||
impl TryFrom<HeaderValue> for IntoHeaderValue<$t> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: HeaderValue) -> Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
Ok(hdr_value) => match hdr_value.parse::<$t>() {
|
||||
Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value)),
|
||||
Err(e) => Err(format!("Unable to parse {} as a string: {}",
|
||||
stringify!($t), e)),
|
||||
},
|
||||
Err(e) => Err(format!("Unable to parse header {:?} as a string - {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IntoHeaderValue<$t>> for HeaderValue {
|
||||
fn from(hdr_value: IntoHeaderValue<$t>) -> Self {
|
||||
hdr_value.0.into()
|
||||
impl TryFrom<IntoHeaderValue<$t>> for HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: IntoHeaderValue<$t>) -> Result<Self, Self::Error> {
|
||||
Ok(hdr_value.0.into())
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -48,52 +61,120 @@ ihv_generate!(i32);
|
||||
|
||||
// Custom derivations
|
||||
|
||||
impl From<HeaderValue> for IntoHeaderValue<Vec<String>> {
|
||||
fn from(hdr_value: HeaderValue) -> Self {
|
||||
IntoHeaderValue(
|
||||
hdr_value
|
||||
.to_str()
|
||||
.unwrap()
|
||||
// Vec<String>
|
||||
|
||||
impl TryFrom<HeaderValue> for IntoHeaderValue<Vec<String>> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: HeaderValue) -> Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
Ok(hdr_value) => Ok(IntoHeaderValue(
|
||||
hdr_value
|
||||
.split(',')
|
||||
.filter_map(|x| match x.trim() {
|
||||
"" => None,
|
||||
y => Some(y.to_string()),
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
.collect())),
|
||||
Err(e) => Err(format!("Unable to parse header: {:?} as a string - {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IntoHeaderValue<Vec<String>>> for HeaderValue {
|
||||
fn from(hdr_value: IntoHeaderValue<Vec<String>>) -> Self {
|
||||
HeaderValue::from_str(&hdr_value.0.join(", ")).unwrap()
|
||||
impl TryFrom<IntoHeaderValue<Vec<String>>> for HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: IntoHeaderValue<Vec<String>>) -> Result<Self, Self::Error> {
|
||||
match HeaderValue::from_str(&hdr_value.0.join(", ")) {
|
||||
Ok(hdr_value) => Ok(hdr_value),
|
||||
Err(e) => Err(format!("Unable to convert {:?} into a header - {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<HeaderValue> for IntoHeaderValue<String> {
|
||||
fn from(hdr_value: HeaderValue) -> Self {
|
||||
IntoHeaderValue(hdr_value.to_str().unwrap().to_string())
|
||||
// String
|
||||
|
||||
impl TryFrom<HeaderValue> for IntoHeaderValue<String> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: HeaderValue) -> Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value.to_string())),
|
||||
Err(e) => Err(format!("Unable to convert header {:?} to {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IntoHeaderValue<String>> for HeaderValue {
|
||||
fn from(hdr_value: IntoHeaderValue<String>) -> Self {
|
||||
HeaderValue::from_str(&hdr_value.0).unwrap()
|
||||
impl TryFrom<IntoHeaderValue<String>> for HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: IntoHeaderValue<String>) -> Result<Self, Self::Error> {
|
||||
match HeaderValue::from_str(&hdr_value.0) {
|
||||
Ok(hdr_value) => Ok(hdr_value),
|
||||
Err(e) => Err(format!("Unable to convert {:?} from a header {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<HeaderValue> for IntoHeaderValue<DateTime<Utc>> {
|
||||
fn from(hdr_value: HeaderValue) -> Self {
|
||||
IntoHeaderValue(
|
||||
DateTime::parse_from_rfc3339(hdr_value.to_str().unwrap())
|
||||
.unwrap()
|
||||
.with_timezone(&Utc),
|
||||
)
|
||||
// bool
|
||||
impl TryFrom<HeaderValue> for IntoHeaderValue<bool> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: HeaderValue) -> Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
Ok(hdr_value) => match hdr_value.parse() {
|
||||
Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value)),
|
||||
Err(e) => Err(format!("Unable to parse bool from {} - {}",
|
||||
hdr_value, e)),
|
||||
},
|
||||
Err(e) => Err(format!("Unable to convert {:?} from a header {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IntoHeaderValue<DateTime<Utc>>> for HeaderValue {
|
||||
fn from(hdr_value: IntoHeaderValue<DateTime<Utc>>) -> Self {
|
||||
HeaderValue::from_str(hdr_value.0.to_rfc3339().as_str()).unwrap()
|
||||
impl TryFrom<IntoHeaderValue<bool>> for HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: IntoHeaderValue<bool>) -> Result<Self, Self::Error> {
|
||||
match HeaderValue::from_str(&hdr_value.0.to_string()) {
|
||||
Ok(hdr_value) => Ok(hdr_value),
|
||||
Err(e) => Err(format!("Unable to convert: {:?} into a header: {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// DateTime
|
||||
|
||||
impl TryFrom<HeaderValue> for IntoHeaderValue<DateTime<Utc>> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: HeaderValue) -> Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
Ok(hdr_value) => match DateTime::parse_from_rfc3339(hdr_value) {
|
||||
Ok(date) => Ok(IntoHeaderValue(date.with_timezone(&Utc))),
|
||||
Err(e) => Err(format!("Unable to parse: {} as date - {}",
|
||||
hdr_value, e)),
|
||||
},
|
||||
Err(e) => Err(format!("Unable to convert header {:?} to string {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<IntoHeaderValue<DateTime<Utc>>> for HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: IntoHeaderValue<DateTime<Utc>>) -> Result<Self, Self::Error> {
|
||||
match HeaderValue::from_str(hdr_value.0.to_rfc3339().as_str()) {
|
||||
Ok(hdr_value) => Ok(hdr_value),
|
||||
Err(e) => Err(format!("Unable to convert {:?} to a header: {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,8 @@ use hyper::{Request, Response, Error, StatusCode, Body, HeaderMap};
|
||||
use hyper::header::{HeaderName, HeaderValue, CONTENT_TYPE};
|
||||
use log::warn;
|
||||
use serde_json;
|
||||
#[allow(unused_imports)]
|
||||
use std::convert::{TryFrom, TryInto};
|
||||
use std::io;
|
||||
use url::form_urlencoded;
|
||||
#[allow(unused_imports)]
|
||||
|
@ -8,6 +8,7 @@ use hyper::{Body, Uri, Response};
|
||||
use hyper_openssl::HttpsConnector;
|
||||
use serde_json;
|
||||
use std::borrow::Cow;
|
||||
use std::convert::TryInto;
|
||||
use std::io::{Read, Error, ErrorKind};
|
||||
use std::error;
|
||||
use std::fmt;
|
||||
@ -1358,13 +1359,35 @@ impl<C, F> Api<C> for Client<F> where
|
||||
});
|
||||
|
||||
// Header parameters
|
||||
param_enum_header_string_array.map(|value| request.headers_mut().append(
|
||||
match param_enum_header_string_array {
|
||||
Some(param_enum_header_string_array) => {
|
||||
request.headers_mut().append(
|
||||
HeaderName::from_static("enum_header_string_array"),
|
||||
header::IntoHeaderValue(value.clone()).into()));
|
||||
match header::IntoHeaderValue(param_enum_header_string_array.clone()).try_into() {
|
||||
Ok(header) => header,
|
||||
Err(e) => {
|
||||
return Box::new(future::err(ApiError(format!(
|
||||
"Invalid header enum_header_string_array - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
|
||||
},
|
||||
});
|
||||
},
|
||||
None => {}
|
||||
}
|
||||
|
||||
param_enum_header_string.map(|value| request.headers_mut().append(
|
||||
match param_enum_header_string {
|
||||
Some(param_enum_header_string) => {
|
||||
request.headers_mut().append(
|
||||
HeaderName::from_static("enum_header_string"),
|
||||
header::IntoHeaderValue(value.clone()).into()));
|
||||
match header::IntoHeaderValue(param_enum_header_string.clone()).try_into() {
|
||||
Ok(header) => header,
|
||||
Err(e) => {
|
||||
return Box::new(future::err(ApiError(format!(
|
||||
"Invalid header enum_header_string - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
|
||||
},
|
||||
});
|
||||
},
|
||||
None => {}
|
||||
}
|
||||
|
||||
Box::new(self.client_service.request(request)
|
||||
.map_err(|e| ApiError(format!("No response received: {}", e)))
|
||||
@ -1836,9 +1859,20 @@ impl<C, F> Api<C> for Client<F> where
|
||||
}
|
||||
|
||||
// Header parameters
|
||||
param_api_key.map(|value| request.headers_mut().append(
|
||||
match param_api_key {
|
||||
Some(param_api_key) => {
|
||||
request.headers_mut().append(
|
||||
HeaderName::from_static("api_key"),
|
||||
header::IntoHeaderValue(value.clone()).into()));
|
||||
match header::IntoHeaderValue(param_api_key.clone()).try_into() {
|
||||
Ok(header) => header,
|
||||
Err(e) => {
|
||||
return Box::new(future::err(ApiError(format!(
|
||||
"Invalid header api_key - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
|
||||
},
|
||||
});
|
||||
},
|
||||
None => {}
|
||||
}
|
||||
|
||||
Box::new(self.client_service.request(request)
|
||||
.map_err(|e| ApiError(format!("No response received: {}", e)))
|
||||
@ -3431,10 +3465,26 @@ impl<C, F> Api<C> for Client<F> where
|
||||
Some(response_x_rate_limit) => response_x_rate_limit.clone(),
|
||||
None => return Box::new(future::err(ApiError(String::from("Required response header X-Rate-Limit for response 200 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
|
||||
};
|
||||
let response_x_rate_limit = match TryInto::<header::IntoHeaderValue<i32>>::try_into(response_x_rate_limit) {
|
||||
Ok(value) => value,
|
||||
Err(e) => {
|
||||
return Box::new(future::err(ApiError(format!("Invalid response header X-Rate-Limit for response 200 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
|
||||
},
|
||||
};
|
||||
let response_x_rate_limit = response_x_rate_limit.0;
|
||||
|
||||
let response_x_expires_after = match response.headers().get(HeaderName::from_static("x-expires-after")) {
|
||||
Some(response_x_expires_after) => response_x_expires_after.clone(),
|
||||
None => return Box::new(future::err(ApiError(String::from("Required response header X-Expires-After for response 200 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
|
||||
};
|
||||
let response_x_expires_after = match TryInto::<header::IntoHeaderValue<chrono::DateTime::<chrono::Utc>>>::try_into(response_x_expires_after) {
|
||||
Ok(value) => value,
|
||||
Err(e) => {
|
||||
return Box::new(future::err(ApiError(format!("Invalid response header X-Expires-After for response 200 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
|
||||
},
|
||||
};
|
||||
let response_x_expires_after = response_x_expires_after.0;
|
||||
|
||||
let body = response.into_body();
|
||||
Box::new(
|
||||
body
|
||||
@ -3454,8 +3504,8 @@ impl<C, F> Api<C> for Client<F> where
|
||||
LoginUserResponse::SuccessfulOperation
|
||||
{
|
||||
body: body,
|
||||
x_rate_limit: (*Into::<header::IntoHeaderValue<i32>>::into(response_x_rate_limit)).clone(),
|
||||
x_expires_after: (*Into::<header::IntoHeaderValue<chrono::DateTime::<chrono::Utc>>>::into(response_x_expires_after)).clone(),
|
||||
x_rate_limit: response_x_rate_limit,
|
||||
x_expires_after: response_x_expires_after,
|
||||
}
|
||||
})
|
||||
) as Box<dyn Future<Item=_, Error=_> + Send>
|
||||
|
@ -1,5 +1,6 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use hyper::header::HeaderValue;
|
||||
use std::convert::TryFrom;
|
||||
use std::fmt;
|
||||
use std::ops::Deref;
|
||||
|
||||
@ -19,19 +20,31 @@ impl<T> Deref for IntoHeaderValue<T> {
|
||||
}
|
||||
}
|
||||
|
||||
// Derive for each From<T> in hyper::header::HeaderValue
|
||||
// Derive for each TryFrom<T> in hyper::header::HeaderValue
|
||||
|
||||
macro_rules! ihv_generate {
|
||||
($t:ident) => {
|
||||
impl From<HeaderValue> for IntoHeaderValue<$t> {
|
||||
fn from(hdr_value: HeaderValue) -> Self {
|
||||
IntoHeaderValue(hdr_value.to_str().unwrap().parse::<$t>().unwrap())
|
||||
impl TryFrom<HeaderValue> for IntoHeaderValue<$t> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: HeaderValue) -> Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
Ok(hdr_value) => match hdr_value.parse::<$t>() {
|
||||
Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value)),
|
||||
Err(e) => Err(format!("Unable to parse {} as a string: {}",
|
||||
stringify!($t), e)),
|
||||
},
|
||||
Err(e) => Err(format!("Unable to parse header {:?} as a string - {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IntoHeaderValue<$t>> for HeaderValue {
|
||||
fn from(hdr_value: IntoHeaderValue<$t>) -> Self {
|
||||
hdr_value.0.into()
|
||||
impl TryFrom<IntoHeaderValue<$t>> for HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: IntoHeaderValue<$t>) -> Result<Self, Self::Error> {
|
||||
Ok(hdr_value.0.into())
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -48,52 +61,120 @@ ihv_generate!(i32);
|
||||
|
||||
// Custom derivations
|
||||
|
||||
impl From<HeaderValue> for IntoHeaderValue<Vec<String>> {
|
||||
fn from(hdr_value: HeaderValue) -> Self {
|
||||
IntoHeaderValue(
|
||||
hdr_value
|
||||
.to_str()
|
||||
.unwrap()
|
||||
// Vec<String>
|
||||
|
||||
impl TryFrom<HeaderValue> for IntoHeaderValue<Vec<String>> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: HeaderValue) -> Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
Ok(hdr_value) => Ok(IntoHeaderValue(
|
||||
hdr_value
|
||||
.split(',')
|
||||
.filter_map(|x| match x.trim() {
|
||||
"" => None,
|
||||
y => Some(y.to_string()),
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
.collect())),
|
||||
Err(e) => Err(format!("Unable to parse header: {:?} as a string - {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IntoHeaderValue<Vec<String>>> for HeaderValue {
|
||||
fn from(hdr_value: IntoHeaderValue<Vec<String>>) -> Self {
|
||||
HeaderValue::from_str(&hdr_value.0.join(", ")).unwrap()
|
||||
impl TryFrom<IntoHeaderValue<Vec<String>>> for HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: IntoHeaderValue<Vec<String>>) -> Result<Self, Self::Error> {
|
||||
match HeaderValue::from_str(&hdr_value.0.join(", ")) {
|
||||
Ok(hdr_value) => Ok(hdr_value),
|
||||
Err(e) => Err(format!("Unable to convert {:?} into a header - {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<HeaderValue> for IntoHeaderValue<String> {
|
||||
fn from(hdr_value: HeaderValue) -> Self {
|
||||
IntoHeaderValue(hdr_value.to_str().unwrap().to_string())
|
||||
// String
|
||||
|
||||
impl TryFrom<HeaderValue> for IntoHeaderValue<String> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: HeaderValue) -> Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value.to_string())),
|
||||
Err(e) => Err(format!("Unable to convert header {:?} to {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IntoHeaderValue<String>> for HeaderValue {
|
||||
fn from(hdr_value: IntoHeaderValue<String>) -> Self {
|
||||
HeaderValue::from_str(&hdr_value.0).unwrap()
|
||||
impl TryFrom<IntoHeaderValue<String>> for HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: IntoHeaderValue<String>) -> Result<Self, Self::Error> {
|
||||
match HeaderValue::from_str(&hdr_value.0) {
|
||||
Ok(hdr_value) => Ok(hdr_value),
|
||||
Err(e) => Err(format!("Unable to convert {:?} from a header {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<HeaderValue> for IntoHeaderValue<DateTime<Utc>> {
|
||||
fn from(hdr_value: HeaderValue) -> Self {
|
||||
IntoHeaderValue(
|
||||
DateTime::parse_from_rfc3339(hdr_value.to_str().unwrap())
|
||||
.unwrap()
|
||||
.with_timezone(&Utc),
|
||||
)
|
||||
// bool
|
||||
impl TryFrom<HeaderValue> for IntoHeaderValue<bool> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: HeaderValue) -> Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
Ok(hdr_value) => match hdr_value.parse() {
|
||||
Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value)),
|
||||
Err(e) => Err(format!("Unable to parse bool from {} - {}",
|
||||
hdr_value, e)),
|
||||
},
|
||||
Err(e) => Err(format!("Unable to convert {:?} from a header {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IntoHeaderValue<DateTime<Utc>>> for HeaderValue {
|
||||
fn from(hdr_value: IntoHeaderValue<DateTime<Utc>>) -> Self {
|
||||
HeaderValue::from_str(hdr_value.0.to_rfc3339().as_str()).unwrap()
|
||||
impl TryFrom<IntoHeaderValue<bool>> for HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: IntoHeaderValue<bool>) -> Result<Self, Self::Error> {
|
||||
match HeaderValue::from_str(&hdr_value.0.to_string()) {
|
||||
Ok(hdr_value) => Ok(hdr_value),
|
||||
Err(e) => Err(format!("Unable to convert: {:?} into a header: {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// DateTime
|
||||
|
||||
impl TryFrom<HeaderValue> for IntoHeaderValue<DateTime<Utc>> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: HeaderValue) -> Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
Ok(hdr_value) => match DateTime::parse_from_rfc3339(hdr_value) {
|
||||
Ok(date) => Ok(IntoHeaderValue(date.with_timezone(&Utc))),
|
||||
Err(e) => Err(format!("Unable to parse: {} as date - {}",
|
||||
hdr_value, e)),
|
||||
},
|
||||
Err(e) => Err(format!("Unable to convert header {:?} to string {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<IntoHeaderValue<DateTime<Utc>>> for HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: IntoHeaderValue<DateTime<Utc>>) -> Result<Self, Self::Error> {
|
||||
match HeaderValue::from_str(hdr_value.0.to_rfc3339().as_str()) {
|
||||
Ok(hdr_value) => Ok(hdr_value),
|
||||
Err(e) => Err(format!("Unable to convert {:?} to a header: {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -5,6 +5,8 @@ use hyper::{Request, Response, Error, StatusCode, Body, HeaderMap};
|
||||
use hyper::header::{HeaderName, HeaderValue, CONTENT_TYPE};
|
||||
use log::warn;
|
||||
use serde_json;
|
||||
#[allow(unused_imports)]
|
||||
use std::convert::{TryFrom, TryInto};
|
||||
use std::io;
|
||||
use url::form_urlencoded;
|
||||
#[allow(unused_imports)]
|
||||
@ -1026,14 +1028,40 @@ where
|
||||
// Header parameters
|
||||
let param_enum_header_string_array = headers.get(HeaderName::from_static("enum_header_string_array"));
|
||||
|
||||
let param_enum_header_string_array = param_enum_header_string_array.map(|p| {
|
||||
header::IntoHeaderValue::<Vec<String>>::from((*p).clone()).0
|
||||
});
|
||||
let param_enum_header_string_array = match param_enum_header_string_array {
|
||||
Some(v) => match header::IntoHeaderValue::<Vec<String>>::try_from((*v).clone()) {
|
||||
Ok(result) =>
|
||||
Some(result.0),
|
||||
Err(err) => {
|
||||
return Box::new(future::ok(Response::builder()
|
||||
.status(StatusCode::BAD_REQUEST)
|
||||
.body(Body::from(format!("Invalid header enum_header_string_array - {}", err)))
|
||||
.expect("Unable to create Bad Request response for invalid header enum_header_string_array")));
|
||||
|
||||
},
|
||||
},
|
||||
None => {
|
||||
None
|
||||
}
|
||||
};
|
||||
let param_enum_header_string = headers.get(HeaderName::from_static("enum_header_string"));
|
||||
|
||||
let param_enum_header_string = param_enum_header_string.map(|p| {
|
||||
header::IntoHeaderValue::<String>::from((*p).clone()).0
|
||||
});
|
||||
let param_enum_header_string = match param_enum_header_string {
|
||||
Some(v) => match header::IntoHeaderValue::<String>::try_from((*v).clone()) {
|
||||
Ok(result) =>
|
||||
Some(result.0),
|
||||
Err(err) => {
|
||||
return Box::new(future::ok(Response::builder()
|
||||
.status(StatusCode::BAD_REQUEST)
|
||||
.body(Body::from(format!("Invalid header enum_header_string - {}", err)))
|
||||
.expect("Unable to create Bad Request response for invalid header enum_header_string")));
|
||||
|
||||
},
|
||||
},
|
||||
None => {
|
||||
None
|
||||
}
|
||||
};
|
||||
|
||||
// Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response)
|
||||
let query_params = form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()).collect::<Vec<_>>();
|
||||
@ -1487,9 +1515,22 @@ where
|
||||
// Header parameters
|
||||
let param_api_key = headers.get(HeaderName::from_static("api_key"));
|
||||
|
||||
let param_api_key = param_api_key.map(|p| {
|
||||
header::IntoHeaderValue::<String>::from((*p).clone()).0
|
||||
});
|
||||
let param_api_key = match param_api_key {
|
||||
Some(v) => match header::IntoHeaderValue::<String>::try_from((*v).clone()) {
|
||||
Ok(result) =>
|
||||
Some(result.0),
|
||||
Err(err) => {
|
||||
return Box::new(future::ok(Response::builder()
|
||||
.status(StatusCode::BAD_REQUEST)
|
||||
.body(Body::from(format!("Invalid header api_key - {}", err)))
|
||||
.expect("Unable to create Bad Request response for invalid header api_key")));
|
||||
|
||||
},
|
||||
},
|
||||
None => {
|
||||
None
|
||||
}
|
||||
};
|
||||
|
||||
Box::new({
|
||||
{{
|
||||
@ -2890,14 +2931,34 @@ where
|
||||
x_expires_after
|
||||
}
|
||||
=> {
|
||||
let x_rate_limit = match header::IntoHeaderValue(x_rate_limit).try_into() {
|
||||
Ok(val) => val,
|
||||
Err(e) => {
|
||||
return future::ok(Response::builder()
|
||||
.status(StatusCode::INTERNAL_SERVER_ERROR)
|
||||
.body(Body::from(format!("An internal server error occurred handling x_rate_limit header - {}", e)))
|
||||
.expect("Unable to create Internal Server Error for invalid response header"))
|
||||
}
|
||||
};
|
||||
|
||||
let x_expires_after = match header::IntoHeaderValue(x_expires_after).try_into() {
|
||||
Ok(val) => val,
|
||||
Err(e) => {
|
||||
return future::ok(Response::builder()
|
||||
.status(StatusCode::INTERNAL_SERVER_ERROR)
|
||||
.body(Body::from(format!("An internal server error occurred handling x_expires_after header - {}", e)))
|
||||
.expect("Unable to create Internal Server Error for invalid response header"))
|
||||
}
|
||||
};
|
||||
|
||||
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
|
||||
response.headers_mut().insert(
|
||||
HeaderName::from_static("x-rate-limit"),
|
||||
header::IntoHeaderValue(x_rate_limit).into()
|
||||
x_rate_limit
|
||||
);
|
||||
response.headers_mut().insert(
|
||||
HeaderName::from_static("x-expires-after"),
|
||||
header::IntoHeaderValue(x_expires_after).into()
|
||||
x_expires_after
|
||||
);
|
||||
response.headers_mut().insert(
|
||||
CONTENT_TYPE,
|
||||
|
@ -8,6 +8,7 @@ use hyper::{Body, Uri, Response};
|
||||
use hyper_openssl::HttpsConnector;
|
||||
use serde_json;
|
||||
use std::borrow::Cow;
|
||||
use std::convert::TryInto;
|
||||
use std::io::{Read, Error, ErrorKind};
|
||||
use std::error;
|
||||
use std::fmt;
|
||||
|
@ -1,5 +1,6 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use hyper::header::HeaderValue;
|
||||
use std::convert::TryFrom;
|
||||
use std::fmt;
|
||||
use std::ops::Deref;
|
||||
|
||||
@ -19,19 +20,31 @@ impl<T> Deref for IntoHeaderValue<T> {
|
||||
}
|
||||
}
|
||||
|
||||
// Derive for each From<T> in hyper::header::HeaderValue
|
||||
// Derive for each TryFrom<T> in hyper::header::HeaderValue
|
||||
|
||||
macro_rules! ihv_generate {
|
||||
($t:ident) => {
|
||||
impl From<HeaderValue> for IntoHeaderValue<$t> {
|
||||
fn from(hdr_value: HeaderValue) -> Self {
|
||||
IntoHeaderValue(hdr_value.to_str().unwrap().parse::<$t>().unwrap())
|
||||
impl TryFrom<HeaderValue> for IntoHeaderValue<$t> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: HeaderValue) -> Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
Ok(hdr_value) => match hdr_value.parse::<$t>() {
|
||||
Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value)),
|
||||
Err(e) => Err(format!("Unable to parse {} as a string: {}",
|
||||
stringify!($t), e)),
|
||||
},
|
||||
Err(e) => Err(format!("Unable to parse header {:?} as a string - {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IntoHeaderValue<$t>> for HeaderValue {
|
||||
fn from(hdr_value: IntoHeaderValue<$t>) -> Self {
|
||||
hdr_value.0.into()
|
||||
impl TryFrom<IntoHeaderValue<$t>> for HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: IntoHeaderValue<$t>) -> Result<Self, Self::Error> {
|
||||
Ok(hdr_value.0.into())
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -48,52 +61,120 @@ ihv_generate!(i32);
|
||||
|
||||
// Custom derivations
|
||||
|
||||
impl From<HeaderValue> for IntoHeaderValue<Vec<String>> {
|
||||
fn from(hdr_value: HeaderValue) -> Self {
|
||||
IntoHeaderValue(
|
||||
hdr_value
|
||||
.to_str()
|
||||
.unwrap()
|
||||
// Vec<String>
|
||||
|
||||
impl TryFrom<HeaderValue> for IntoHeaderValue<Vec<String>> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: HeaderValue) -> Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
Ok(hdr_value) => Ok(IntoHeaderValue(
|
||||
hdr_value
|
||||
.split(',')
|
||||
.filter_map(|x| match x.trim() {
|
||||
"" => None,
|
||||
y => Some(y.to_string()),
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
.collect())),
|
||||
Err(e) => Err(format!("Unable to parse header: {:?} as a string - {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IntoHeaderValue<Vec<String>>> for HeaderValue {
|
||||
fn from(hdr_value: IntoHeaderValue<Vec<String>>) -> Self {
|
||||
HeaderValue::from_str(&hdr_value.0.join(", ")).unwrap()
|
||||
impl TryFrom<IntoHeaderValue<Vec<String>>> for HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: IntoHeaderValue<Vec<String>>) -> Result<Self, Self::Error> {
|
||||
match HeaderValue::from_str(&hdr_value.0.join(", ")) {
|
||||
Ok(hdr_value) => Ok(hdr_value),
|
||||
Err(e) => Err(format!("Unable to convert {:?} into a header - {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<HeaderValue> for IntoHeaderValue<String> {
|
||||
fn from(hdr_value: HeaderValue) -> Self {
|
||||
IntoHeaderValue(hdr_value.to_str().unwrap().to_string())
|
||||
// String
|
||||
|
||||
impl TryFrom<HeaderValue> for IntoHeaderValue<String> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: HeaderValue) -> Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value.to_string())),
|
||||
Err(e) => Err(format!("Unable to convert header {:?} to {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IntoHeaderValue<String>> for HeaderValue {
|
||||
fn from(hdr_value: IntoHeaderValue<String>) -> Self {
|
||||
HeaderValue::from_str(&hdr_value.0).unwrap()
|
||||
impl TryFrom<IntoHeaderValue<String>> for HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: IntoHeaderValue<String>) -> Result<Self, Self::Error> {
|
||||
match HeaderValue::from_str(&hdr_value.0) {
|
||||
Ok(hdr_value) => Ok(hdr_value),
|
||||
Err(e) => Err(format!("Unable to convert {:?} from a header {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<HeaderValue> for IntoHeaderValue<DateTime<Utc>> {
|
||||
fn from(hdr_value: HeaderValue) -> Self {
|
||||
IntoHeaderValue(
|
||||
DateTime::parse_from_rfc3339(hdr_value.to_str().unwrap())
|
||||
.unwrap()
|
||||
.with_timezone(&Utc),
|
||||
)
|
||||
// bool
|
||||
impl TryFrom<HeaderValue> for IntoHeaderValue<bool> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: HeaderValue) -> Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
Ok(hdr_value) => match hdr_value.parse() {
|
||||
Ok(hdr_value) => Ok(IntoHeaderValue(hdr_value)),
|
||||
Err(e) => Err(format!("Unable to parse bool from {} - {}",
|
||||
hdr_value, e)),
|
||||
},
|
||||
Err(e) => Err(format!("Unable to convert {:?} from a header {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IntoHeaderValue<DateTime<Utc>>> for HeaderValue {
|
||||
fn from(hdr_value: IntoHeaderValue<DateTime<Utc>>) -> Self {
|
||||
HeaderValue::from_str(hdr_value.0.to_rfc3339().as_str()).unwrap()
|
||||
impl TryFrom<IntoHeaderValue<bool>> for HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: IntoHeaderValue<bool>) -> Result<Self, Self::Error> {
|
||||
match HeaderValue::from_str(&hdr_value.0.to_string()) {
|
||||
Ok(hdr_value) => Ok(hdr_value),
|
||||
Err(e) => Err(format!("Unable to convert: {:?} into a header: {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// DateTime
|
||||
|
||||
impl TryFrom<HeaderValue> for IntoHeaderValue<DateTime<Utc>> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: HeaderValue) -> Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
Ok(hdr_value) => match DateTime::parse_from_rfc3339(hdr_value) {
|
||||
Ok(date) => Ok(IntoHeaderValue(date.with_timezone(&Utc))),
|
||||
Err(e) => Err(format!("Unable to parse: {} as date - {}",
|
||||
hdr_value, e)),
|
||||
},
|
||||
Err(e) => Err(format!("Unable to convert header {:?} to string {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<IntoHeaderValue<DateTime<Utc>>> for HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: IntoHeaderValue<DateTime<Utc>>) -> Result<Self, Self::Error> {
|
||||
match HeaderValue::from_str(hdr_value.0.to_rfc3339().as_str()) {
|
||||
Ok(hdr_value) => Ok(hdr_value),
|
||||
Err(e) => Err(format!("Unable to convert {:?} to a header: {}",
|
||||
hdr_value, e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,16 +8,38 @@ use crate::header;
|
||||
// Methods for converting between header::IntoHeaderValue<ANullableContainer> and hyper::header::HeaderValue
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<header::IntoHeaderValue<ANullableContainer>> for hyper::header::HeaderValue {
|
||||
fn from(hdr_value: header::IntoHeaderValue<ANullableContainer>) -> Self {
|
||||
hyper::header::HeaderValue::from_str(&hdr_value.to_string()).unwrap()
|
||||
impl std::convert::TryFrom<header::IntoHeaderValue<ANullableContainer>> for hyper::header::HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: header::IntoHeaderValue<ANullableContainer>) -> std::result::Result<Self, Self::Error> {
|
||||
let hdr_value = hdr_value.to_string();
|
||||
match hyper::header::HeaderValue::from_str(&hdr_value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(value),
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Invalid header value for ANullableContainer - value: {} is invalid {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<hyper::header::HeaderValue> for header::IntoHeaderValue<ANullableContainer> {
|
||||
fn from(hdr_value: hyper::header::HeaderValue) -> Self {
|
||||
header::IntoHeaderValue(<ANullableContainer as std::str::FromStr>::from_str(hdr_value.to_str().unwrap()).unwrap())
|
||||
impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderValue<ANullableContainer> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
std::result::Result::Ok(value) => {
|
||||
match <ANullableContainer as std::str::FromStr>::from_str(value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)),
|
||||
std::result::Result::Err(err) => std::result::Result::Err(
|
||||
format!("Unable to convert header value '{}' into ANullableContainer - {}",
|
||||
value, err))
|
||||
}
|
||||
},
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Unable to convert header: {:?} to string: {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -169,16 +191,38 @@ impl ::std::str::FromStr for AdditionalPropertiesObject {
|
||||
// Methods for converting between header::IntoHeaderValue<AllOfObject> and hyper::header::HeaderValue
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<header::IntoHeaderValue<AllOfObject>> for hyper::header::HeaderValue {
|
||||
fn from(hdr_value: header::IntoHeaderValue<AllOfObject>) -> Self {
|
||||
hyper::header::HeaderValue::from_str(&hdr_value.to_string()).unwrap()
|
||||
impl std::convert::TryFrom<header::IntoHeaderValue<AllOfObject>> for hyper::header::HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: header::IntoHeaderValue<AllOfObject>) -> std::result::Result<Self, Self::Error> {
|
||||
let hdr_value = hdr_value.to_string();
|
||||
match hyper::header::HeaderValue::from_str(&hdr_value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(value),
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Invalid header value for AllOfObject - value: {} is invalid {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<hyper::header::HeaderValue> for header::IntoHeaderValue<AllOfObject> {
|
||||
fn from(hdr_value: hyper::header::HeaderValue) -> Self {
|
||||
header::IntoHeaderValue(<AllOfObject as std::str::FromStr>::from_str(hdr_value.to_str().unwrap()).unwrap())
|
||||
impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderValue<AllOfObject> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
std::result::Result::Ok(value) => {
|
||||
match <AllOfObject as std::str::FromStr>::from_str(value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)),
|
||||
std::result::Result::Err(err) => std::result::Result::Err(
|
||||
format!("Unable to convert header value '{}' into AllOfObject - {}",
|
||||
value, err))
|
||||
}
|
||||
},
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Unable to convert header: {:?} to string: {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -278,16 +322,38 @@ impl std::str::FromStr for AllOfObject {
|
||||
// Methods for converting between header::IntoHeaderValue<BaseAllOf> and hyper::header::HeaderValue
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<header::IntoHeaderValue<BaseAllOf>> for hyper::header::HeaderValue {
|
||||
fn from(hdr_value: header::IntoHeaderValue<BaseAllOf>) -> Self {
|
||||
hyper::header::HeaderValue::from_str(&hdr_value.to_string()).unwrap()
|
||||
impl std::convert::TryFrom<header::IntoHeaderValue<BaseAllOf>> for hyper::header::HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: header::IntoHeaderValue<BaseAllOf>) -> std::result::Result<Self, Self::Error> {
|
||||
let hdr_value = hdr_value.to_string();
|
||||
match hyper::header::HeaderValue::from_str(&hdr_value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(value),
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Invalid header value for BaseAllOf - value: {} is invalid {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<hyper::header::HeaderValue> for header::IntoHeaderValue<BaseAllOf> {
|
||||
fn from(hdr_value: hyper::header::HeaderValue) -> Self {
|
||||
header::IntoHeaderValue(<BaseAllOf as std::str::FromStr>::from_str(hdr_value.to_str().unwrap()).unwrap())
|
||||
impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderValue<BaseAllOf> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
std::result::Result::Ok(value) => {
|
||||
match <BaseAllOf as std::str::FromStr>::from_str(value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)),
|
||||
std::result::Result::Err(err) => std::result::Result::Err(
|
||||
format!("Unable to convert header value '{}' into BaseAllOf - {}",
|
||||
value, err))
|
||||
}
|
||||
},
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Unable to convert header: {:?} to string: {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -374,16 +440,38 @@ impl std::str::FromStr for BaseAllOf {
|
||||
// Methods for converting between header::IntoHeaderValue<GetYamlResponse> and hyper::header::HeaderValue
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<header::IntoHeaderValue<GetYamlResponse>> for hyper::header::HeaderValue {
|
||||
fn from(hdr_value: header::IntoHeaderValue<GetYamlResponse>) -> Self {
|
||||
hyper::header::HeaderValue::from_str(&hdr_value.to_string()).unwrap()
|
||||
impl std::convert::TryFrom<header::IntoHeaderValue<GetYamlResponse>> for hyper::header::HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: header::IntoHeaderValue<GetYamlResponse>) -> std::result::Result<Self, Self::Error> {
|
||||
let hdr_value = hdr_value.to_string();
|
||||
match hyper::header::HeaderValue::from_str(&hdr_value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(value),
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Invalid header value for GetYamlResponse - value: {} is invalid {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<hyper::header::HeaderValue> for header::IntoHeaderValue<GetYamlResponse> {
|
||||
fn from(hdr_value: hyper::header::HeaderValue) -> Self {
|
||||
header::IntoHeaderValue(<GetYamlResponse as std::str::FromStr>::from_str(hdr_value.to_str().unwrap()).unwrap())
|
||||
impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderValue<GetYamlResponse> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
std::result::Result::Ok(value) => {
|
||||
match <GetYamlResponse as std::str::FromStr>::from_str(value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)),
|
||||
std::result::Result::Err(err) => std::result::Result::Err(
|
||||
format!("Unable to convert header value '{}' into GetYamlResponse - {}",
|
||||
value, err))
|
||||
}
|
||||
},
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Unable to convert header: {:?} to string: {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -470,16 +558,38 @@ impl std::str::FromStr for GetYamlResponse {
|
||||
// Methods for converting between header::IntoHeaderValue<InlineObject> and hyper::header::HeaderValue
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<header::IntoHeaderValue<InlineObject>> for hyper::header::HeaderValue {
|
||||
fn from(hdr_value: header::IntoHeaderValue<InlineObject>) -> Self {
|
||||
hyper::header::HeaderValue::from_str(&hdr_value.to_string()).unwrap()
|
||||
impl std::convert::TryFrom<header::IntoHeaderValue<InlineObject>> for hyper::header::HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: header::IntoHeaderValue<InlineObject>) -> std::result::Result<Self, Self::Error> {
|
||||
let hdr_value = hdr_value.to_string();
|
||||
match hyper::header::HeaderValue::from_str(&hdr_value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(value),
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Invalid header value for InlineObject - value: {} is invalid {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<hyper::header::HeaderValue> for header::IntoHeaderValue<InlineObject> {
|
||||
fn from(hdr_value: hyper::header::HeaderValue) -> Self {
|
||||
header::IntoHeaderValue(<InlineObject as std::str::FromStr>::from_str(hdr_value.to_str().unwrap()).unwrap())
|
||||
impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderValue<InlineObject> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
std::result::Result::Ok(value) => {
|
||||
match <InlineObject as std::str::FromStr>::from_str(value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)),
|
||||
std::result::Result::Err(err) => std::result::Result::Err(
|
||||
format!("Unable to convert header value '{}' into InlineObject - {}",
|
||||
value, err))
|
||||
}
|
||||
},
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Unable to convert header: {:?} to string: {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -577,16 +687,38 @@ impl std::str::FromStr for InlineObject {
|
||||
// Methods for converting between header::IntoHeaderValue<ObjectOfObjects> and hyper::header::HeaderValue
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<header::IntoHeaderValue<ObjectOfObjects>> for hyper::header::HeaderValue {
|
||||
fn from(hdr_value: header::IntoHeaderValue<ObjectOfObjects>) -> Self {
|
||||
hyper::header::HeaderValue::from_str(&hdr_value.to_string()).unwrap()
|
||||
impl std::convert::TryFrom<header::IntoHeaderValue<ObjectOfObjects>> for hyper::header::HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: header::IntoHeaderValue<ObjectOfObjects>) -> std::result::Result<Self, Self::Error> {
|
||||
let hdr_value = hdr_value.to_string();
|
||||
match hyper::header::HeaderValue::from_str(&hdr_value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(value),
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Invalid header value for ObjectOfObjects - value: {} is invalid {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<hyper::header::HeaderValue> for header::IntoHeaderValue<ObjectOfObjects> {
|
||||
fn from(hdr_value: hyper::header::HeaderValue) -> Self {
|
||||
header::IntoHeaderValue(<ObjectOfObjects as std::str::FromStr>::from_str(hdr_value.to_str().unwrap()).unwrap())
|
||||
impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderValue<ObjectOfObjects> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
std::result::Result::Ok(value) => {
|
||||
match <ObjectOfObjects as std::str::FromStr>::from_str(value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)),
|
||||
std::result::Result::Err(err) => std::result::Result::Err(
|
||||
format!("Unable to convert header value '{}' into ObjectOfObjects - {}",
|
||||
value, err))
|
||||
}
|
||||
},
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Unable to convert header: {:?} to string: {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -668,16 +800,38 @@ impl std::str::FromStr for ObjectOfObjects {
|
||||
// Methods for converting between header::IntoHeaderValue<ObjectOfObjectsInner> and hyper::header::HeaderValue
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<header::IntoHeaderValue<ObjectOfObjectsInner>> for hyper::header::HeaderValue {
|
||||
fn from(hdr_value: header::IntoHeaderValue<ObjectOfObjectsInner>) -> Self {
|
||||
hyper::header::HeaderValue::from_str(&hdr_value.to_string()).unwrap()
|
||||
impl std::convert::TryFrom<header::IntoHeaderValue<ObjectOfObjectsInner>> for hyper::header::HeaderValue {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: header::IntoHeaderValue<ObjectOfObjectsInner>) -> std::result::Result<Self, Self::Error> {
|
||||
let hdr_value = hdr_value.to_string();
|
||||
match hyper::header::HeaderValue::from_str(&hdr_value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(value),
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Invalid header value for ObjectOfObjectsInner - value: {} is invalid {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "client", feature = "server"))]
|
||||
impl From<hyper::header::HeaderValue> for header::IntoHeaderValue<ObjectOfObjectsInner> {
|
||||
fn from(hdr_value: hyper::header::HeaderValue) -> Self {
|
||||
header::IntoHeaderValue(<ObjectOfObjectsInner as std::str::FromStr>::from_str(hdr_value.to_str().unwrap()).unwrap())
|
||||
impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderValue<ObjectOfObjectsInner> {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
|
||||
match hdr_value.to_str() {
|
||||
std::result::Result::Ok(value) => {
|
||||
match <ObjectOfObjectsInner as std::str::FromStr>::from_str(value) {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)),
|
||||
std::result::Result::Err(err) => std::result::Result::Err(
|
||||
format!("Unable to convert header value '{}' into ObjectOfObjectsInner - {}",
|
||||
value, err))
|
||||
}
|
||||
},
|
||||
std::result::Result::Err(e) => std::result::Result::Err(
|
||||
format!("Unable to convert header: {:?} to string: {}",
|
||||
hdr_value, e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,8 @@ use hyper::{Request, Response, Error, StatusCode, Body, HeaderMap};
|
||||
use hyper::header::{HeaderName, HeaderValue, CONTENT_TYPE};
|
||||
use log::warn;
|
||||
use serde_json;
|
||||
#[allow(unused_imports)]
|
||||
use std::convert::{TryFrom, TryInto};
|
||||
use std::io;
|
||||
use url::form_urlencoded;
|
||||
#[allow(unused_imports)]
|
||||
|
Loading…
x
Reference in New Issue
Block a user