| 809 | ctx.clone(), |
| 810 | "Content-Type".into(), |
| 811 | "application/json".into_js(&ctx).unwrap(), |
| 812 | ) |
| 813 | .unwrap(); |
| 814 | |
| 815 | let append_headers = [ |
| 816 | ("set-cookie", "cookie1=value1"), |
| 817 | ("set-cookie", "cookie2=value2"), |
| 818 | ("Accept-Encoding", "deflate"), |
| 819 | ("Accept-Encoding", "gzip"), |
| 820 | ]; |
| 821 | for (key, value) in append_headers { |
| 822 | headers |
| 823 | .append(ctx.clone(), key.into(), value.into_js(&ctx).unwrap()) |
| 824 | .unwrap(); |
| 825 | } |
| 826 | |
| 827 | let get_headers = [ |
| 828 | ("Content-Type", "application/json"), |
| 829 | ("set-cookie", "cookie1=value1, cookie2=value2"), |
| 830 | ("Accept-Encoding", "deflate, gzip"), |
| 831 | ]; |
| 832 | for (key, expected) in get_headers { |
| 833 | assert_eq!( |
| 834 | headers |
| 835 | .get(ctx.clone(), key.into()) |
| 836 | .unwrap() |
| 837 | .as_string() |
| 838 | .unwrap() |
| 839 | .to_string() |
| 840 | .unwrap(), |
| 841 | expected |
| 842 | ); |
| 843 | } |
| 844 | }) |
| 845 | }) |
| 846 | .await; |
| 847 | } |
| 848 | |
| 849 | #[tokio::test] |
| 850 | async fn test_normalize_header_value_inplace() { |
| 851 | test_async_with(|ctx| { |
| 852 | crate::init(&ctx).unwrap(); |
| 853 | Box::pin(async move { |
| 854 | // https://github.com/web-platform-tests/wpt/blob/master/fetch/api/headers/headers-normalize.any.js |
| 855 | let expectations = [ |
| 856 | (" space ", "space"), |
| 857 | ("\ttab\t", "tab"), |
| 858 | (" spaceAndTab\t", "spaceAndTab"), |
| 859 | ("\r\n newLine", "newLine"), |