| 141 | } |
| 142 | |
| 143 | pub fn get<'js>(&self, ctx: Ctx<'js>, key: String) -> Result<Value<'js>> { |
| 144 | let key = lower_key(key); |
| 145 | if !is_http_header_name(&key) { |
| 146 | return Err(Exception::throw_type(&ctx, "Invalid key")); |
| 147 | } |
| 148 | |
| 149 | if key.as_ref() == SET_COOKIE.as_str() { |
| 150 | let result: Vec<&str> = self |
| 151 | .headers |
| 152 | .iter() |
| 153 | .filter_map(|(k, v)| if k == &key { Some(v.as_ref()) } else { None }) |
| 154 | .collect(); |
| 155 | return if result.is_empty() { |
| 156 | Null.into_js(&ctx) |
| 157 | } else { |
| 158 | result.join(", ").into_js(&ctx) |
| 159 | }; |
| 160 | } |
| 161 | self.headers |
| 162 | .iter() |
| 163 | .find(|(k, _)| *k == key) |
| 164 | .map(|(_, v)| v.as_ref().into_js(&ctx)) |
| 165 | .unwrap_or_else(|| Null.into_js(&ctx)) |
| 166 | } |
| 167 | |
| 168 | pub fn get_set_cookie(&self) -> Vec<&str> { |
| 169 | self.headers |