question

freitasm avatar image
0 Votes"
freitasm asked BruceZhang-MSFT commented

Setting multiple response headers with same name, different values

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

windows-server-iis-configuration
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

BruceZhang-MSFT avatar image
0 Votes"
BruceZhang-MSFT answered BruceZhang-MSFT edited

Hi @freitasm ,

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




3.jpg (89.5 KiB)
4.jpg (32.5 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

freitasm avatar image
0 Votes"
freitasm answered

Thanks for your reply @BruceZhang-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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

freitasm avatar image
0 Votes"
freitasm answered BruceZhang-MSFT commented

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

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @freitasm ,

II changed the ";" to "," and tested again, get the same result.
133449-5.jpg


0 Votes 0 ·
5.jpg (54.0 KiB)