Setting multiple response headers with same name, different values

Mauricio Freitas 1 Reputation point
2021-09-16T22:54:27.66+00:00

Hi folks

Implementing headers compatible with RFC 8297 https://datatracker.ietf.org/doc/html/rfc8297 and specifically want to issue three Link headers in my 200 response - each Link header has a different value as per RFC example:

Link: </style.css>; rel=preload; as=style
Link: </script1.js>; rel=preload; as=script
Link: </script2.js>; rel=preload; as=script

Using IIS 8 I can't just add the HTTP Headers because the UI prevents creating multiple response headers with the same name saying "A header with this name already exists."

Is there a way around this?

Thanks

Internet Information Services
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Bruce Zhang-MSFT 3,736 Reputation points
    2021-09-17T06:38:47.113+00:00

    Hi @Mauricio Freitas ,

    I also used IIS10 and IIS7 to add these headers which have same key, but both of them show the same result:" A header with this name already exists."

    So IIS dooesn't allow custom response headers with same name.

    In the http specification:

    Multiple message-header fields with the same field-name MAY be present in a message if and only if the entire field-value for that header field is defined as a comma-separated list [i.e., #(values)]. It MUST be possible to combine the multiple header fields into one "field-name: field-value" pair, without changing the semantics of the message, by appending each subsequent field-value to the first, each separated by a comma.

    So I think you can add response headers like this, use; separate multiple values.
    132958-3.jpg

    The result may be different.
    132939-4.jpg


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,
    Bruce Zhang

    0 comments No comments

  2. Mauricio Freitas 1 Reputation point
    2021-09-17T21:58:00.687+00:00

    Thanks for your reply @Bruce Zhang-MSFT

    I did consider using a single header but still not sure as the RFC shows one per line.

    I will test a bit more on this front.

    0 comments No comments

  3. Mauricio Freitas 1 Reputation point
    2021-09-17T22:12:17.077+00:00

    Looking at RFC 2616 (which you quoted), I think the key part "by appending each subsequent field-value to the first, each separated by a comma."

    So instead of your example it should be

    Link: </style.css>; rel=preload; as=style , </script1.js>; rel=preload; as=script, </script2.js>; rel=preload; as=script

    I will test this.

    Thanks again