Azure Relay Hybrid Connection Response Headers

Category: azure servicebus


K Lagan on Sat, 07 Sep 2019 21:54:07

I have a pretty vanilla set up taken straight out of the examples. 

I want to set the response headers but they never seem to get set.

context.Response.Headers.Add("something", "or another");

Isnt that all I need to do to get the header set or did I miss something?


DixitArora-MSFT on Mon, 09 Sep 2019 09:33:21

You can do something like this :

async Task SendResponseAsync(RelayedHttpListenerContext context, HttpResponseMessage responseMessage)
            context.Response.StatusCode = responseMessage.StatusCode;
            context.Response.StatusDescription = responseMessage.ReasonPhrase;
            foreach (KeyValuePair<string, IEnumerable<string>> header in responseMessage.Headers)
                if (string.Equals(header.Key, "Transfer-Encoding"))

                context.Response.Headers.Add(header.Key, string.Join(",", header.Value));

            var responseStream = await responseMessage.Content.ReadAsStreamAsync();
            await responseStream.CopyToAsync(context.Response.OutputStream);

Complete sample can be found here :

K Lagan on Mon, 09 Sep 2019 19:59:07

Thanks for this, but I was already adding the header as shown above but it was just not returning.

I understand that there is a strict order to the way that you add/change values on a response object: status, headers, content.

When I ordered my changes like this the response started to contain all my changes.

I'm not *sure* this was the solution, but it is working now so I am happy.


DixitArora-MSFT on Tue, 10 Sep 2019 03:54:26

I am glad that the issue is resolved. So for now I am going to resolve this thread so that others in the community could also be benefited from this. In case there is anything from your side , please feel free to re-engage on this thread and will be happy to assist.