File tree Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -52,9 +52,9 @@ impl MediaTypeProposal {
52
52
/// we have to parse the full string to the media type first, and then see if
53
53
/// a `q` value has been set.
54
54
pub ( crate ) fn from_str ( s : & str ) -> crate :: Result < Self > {
55
- let media_type = Mime :: from_str ( s) ?;
55
+ let mut media_type = Mime :: from_str ( s) ?;
56
56
let weight = media_type
57
- . param ( "q" )
57
+ . remove_param ( "q" )
58
58
. map ( |param| param. as_str ( ) . parse ( ) )
59
59
. transpose ( ) ?;
60
60
Ok ( Self :: new ( media_type, weight) ?)
Original file line number Diff line number Diff line change @@ -109,6 +109,33 @@ impl Mime {
109
109
} )
110
110
. flatten ( )
111
111
}
112
+
113
+ /// Remove a param from the set. Returns the `ParamValue` if it was contained within the set.
114
+ pub fn remove_param ( & mut self , name : impl Into < ParamName > ) -> Option < ParamValue > {
115
+ let name: ParamName = name. into ( ) ;
116
+ let mut unset_params = false ;
117
+ let ret = self
118
+ . params
119
+ . as_mut ( )
120
+ . map ( |inner| match inner {
121
+ ParamKind :: Vec ( v) => match v. iter ( ) . position ( |( k, _) | k == & name) {
122
+ Some ( index) => Some ( v. remove ( index) . 1 ) ,
123
+ None => None ,
124
+ } ,
125
+ ParamKind :: Utf8 => match name {
126
+ ParamName ( Cow :: Borrowed ( "charset" ) ) => {
127
+ unset_params = true ;
128
+ Some ( ParamValue ( Cow :: Borrowed ( "utf8" ) ) )
129
+ }
130
+ _ => None ,
131
+ } ,
132
+ } )
133
+ . flatten ( ) ;
134
+ if unset_params {
135
+ self . params = None ;
136
+ }
137
+ ret
138
+ }
112
139
}
113
140
114
141
impl PartialEq < Mime > for Mime {
You can’t perform that action at this time.
0 commit comments