How do I get multiple headers with the same name in router rhai script?

I tried response.headers["set-cookie"] but it only returns one value. It seems to be calling http::header::map::HeaderMap::get. How do I make it call http::header::map::HeaderMap::get_all?

Full code:

fn subgraph_service(service, subgraph) {
    let store_cookies_from_subgraphs = |response| {
        if response.headers["set-cookie"] != () {
            if response.context["set_cookie_headers"] == () {
                response.context.set_cookie_headers = [];
            }

            response.context.set_cookie_headers += response.headers["set-cookie"];
        }        
    };
    service.map_response(store_cookies_from_subgraphs);
}

It looks like from these docs that you want the values() method, so like request.headers.values("set-cookie")

1 Like

Thanks.

I think I’ve found a better rhai script for passing set-cookie headers.

fn supergraph_service(service) {
  let add_cookies_to_response = |response| {
    if response.context["set_cookie_headers"] == () || response.context["set_cookie_headers"].is_empty() {
      return;
    }
    response.headers["set-cookie"] = response.context["set_cookie_headers"];
  };

  service.map_response(add_cookies_to_response);
}

fn subgraph_service(service, subgraph) {
    let store_cookies_from_subgraphs = |response| {
      if response.headers.values("set-cookie")?.is_empty() { return; }
      response.context.set_cookie_headers = response.headers.values("set-cookie");
    };

    service.map_response(store_cookies_from_subgraphs);
}
1 Like