@@ -39,10 +39,7 @@ pub fn introspect_schema(
39
39
let mut req_builder = client. post ( location) . headers ( construct_headers ( ) ) ;
40
40
41
41
for custom_header in headers {
42
- req_builder = req_builder. header (
43
- custom_header. name . as_str ( ) ,
44
- custom_header. value . as_str ( ) ,
45
- ) ;
42
+ req_builder = req_builder. header ( custom_header. name . as_str ( ) , custom_header. value . as_str ( ) ) ;
46
43
}
47
44
48
45
if let Some ( token) = authorization {
@@ -79,11 +76,14 @@ pub struct Header {
79
76
80
77
impl FromStr for Header {
81
78
type Err = failure:: Error ;
82
-
79
+
83
80
fn from_str ( input : & str ) -> Result < Self , Self :: Err > {
84
81
// error: colon required for name/value pair
85
- if ! input. contains ( ":" ) {
86
- return Err ( format_err ! ( "Invalid header input. A colon is required to separate the name and value. [{}]" , input) ) ;
82
+ if !input. contains ( ":" ) {
83
+ return Err ( format_err ! (
84
+ "Invalid header input. A colon is required to separate the name and value. [{}]" ,
85
+ input
86
+ ) ) ;
87
87
}
88
88
89
89
// split on first colon and trim whitespace from name and value
@@ -93,15 +93,24 @@ impl FromStr for Header {
93
93
94
94
// error: field name must be
95
95
if name. len ( ) == 0 {
96
- return Err ( format_err ! ( "Invalid header input. Field name is required before colon. [{}]" , input) ) ;
96
+ return Err ( format_err ! (
97
+ "Invalid header input. Field name is required before colon. [{}]" ,
98
+ input
99
+ ) ) ;
97
100
}
98
-
101
+
99
102
// error: no whitespace in field name
100
103
if name. split_whitespace ( ) . count ( ) > 1 {
101
- return Err ( format_err ! ( "Invalid header input. Whitespace not allowed in field name. [{}]" , input) ) ;
104
+ return Err ( format_err ! (
105
+ "Invalid header input. Whitespace not allowed in field name. [{}]" ,
106
+ input
107
+ ) ) ;
102
108
}
103
109
104
- Ok ( Self { name : name. to_string ( ) , value : value. to_string ( ) } )
110
+ Ok ( Self {
111
+ name : name. to_string ( ) ,
112
+ value : value. to_string ( ) ,
113
+ } )
105
114
}
106
115
}
107
116
@@ -129,8 +138,14 @@ mod tests {
129
138
fn it_parses_valid_headers ( ) {
130
139
// https://tools.ietf.org/html/rfc7230#section-3.2
131
140
132
- let expected1 = Header { name : "X-Name" . to_string ( ) , value : "Value" . to_string ( ) } ;
133
- let expected2 = Header { name : "X-Name" . to_string ( ) , value : "Value:" . to_string ( ) } ;
141
+ let expected1 = Header {
142
+ name : "X-Name" . to_string ( ) ,
143
+ value : "Value" . to_string ( ) ,
144
+ } ;
145
+ let expected2 = Header {
146
+ name : "X-Name" . to_string ( ) ,
147
+ value : "Value:" . to_string ( ) ,
148
+ } ;
134
149
135
150
for ( input, expected) in vec ! [
136
151
( "X-Name: Value" , & expected1) , // ideal
0 commit comments