Add percent_encode_noop configuration to Form (#467)
				
					
				
			Some implementations of multipart/form parsing don't support alternate encodings, but do allow unicode in 'standard' parameter values. This change allows users to specify that they do not want to encode parameters. (See also: #419, #420.)
This commit is contained in:
		| @@ -91,6 +91,11 @@ impl Form { | |||||||
|         self.with_inner(|inner| inner.percent_encode_attr_chars()) |         self.with_inner(|inner| inner.percent_encode_attr_chars()) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /// Configure this `Form` to skip percent-encoding | ||||||
|  |     pub fn percent_encode_noop(self) -> Form { | ||||||
|  |         self.with_inner(|inner| inner.percent_encode_noop()) | ||||||
|  |     } | ||||||
|  |  | ||||||
|     /// Consume this instance and transform into an instance of hyper::Body for use in a request. |     /// Consume this instance and transform into an instance of hyper::Body for use in a request. | ||||||
|     pub(crate) fn stream(mut self) -> hyper::Body { |     pub(crate) fn stream(mut self) -> hyper::Body { | ||||||
|         if self.inner.fields.len() == 0 { |         if self.inner.fields.len() == 0 { | ||||||
| @@ -278,6 +283,12 @@ impl<P: PartProps> FormParts<P> { | |||||||
|         self |         self | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /// Configure this `Form` to skip percent-encoding | ||||||
|  |     pub(crate) fn percent_encode_noop(mut self) -> Self { | ||||||
|  |         self.percent_encoding = PercentEncoding::NoOp; | ||||||
|  |         self | ||||||
|  |     } | ||||||
|  |  | ||||||
|     // If predictable, computes the length the request will have |     // If predictable, computes the length the request will have | ||||||
|     // The length should be preditable if only String and file fields have been added, |     // The length should be preditable if only String and file fields have been added, | ||||||
|     // but not if a generic reader has been added; |     // but not if a generic reader has been added; | ||||||
| @@ -389,6 +400,7 @@ impl EncodeSet for AttrCharEncodeSet { | |||||||
| pub(crate) enum PercentEncoding { | pub(crate) enum PercentEncoding { | ||||||
|     PathSegment, |     PathSegment, | ||||||
|     AttrChar, |     AttrChar, | ||||||
|  |     NoOp, | ||||||
| } | } | ||||||
|  |  | ||||||
| impl PercentEncoding { | impl PercentEncoding { | ||||||
| @@ -434,6 +446,7 @@ impl PercentEncoding { | |||||||
|                 percent_encoding::utf8_percent_encode(value, AttrCharEncodeSet) |                 percent_encoding::utf8_percent_encode(value, AttrCharEncodeSet) | ||||||
|                     .to_string() |                     .to_string() | ||||||
|             }, |             }, | ||||||
|  |             PercentEncoding::NoOp => { value.to_string() }, | ||||||
|         }; |         }; | ||||||
|         if value.len() == legal_value.len() { |         if value.len() == legal_value.len() { | ||||||
|             // nothing has been percent encoded |             // nothing has been percent encoded | ||||||
|   | |||||||
| @@ -130,6 +130,11 @@ impl Form { | |||||||
|         self.with_inner(|inner| inner.percent_encode_attr_chars()) |         self.with_inner(|inner| inner.percent_encode_attr_chars()) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /// Configure this `Form` to skip percent-encoding | ||||||
|  |     pub fn percent_encode_noop(self) -> Form { | ||||||
|  |         self.with_inner(|inner| inner.percent_encode_noop()) | ||||||
|  |     } | ||||||
|  |  | ||||||
|     pub(crate) fn reader(self) -> Reader { |     pub(crate) fn reader(self) -> Reader { | ||||||
|         Reader::new(self) |         Reader::new(self) | ||||||
|     } |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user