Jamie
Jamie

Reputation: 864

Castle Windsor Interceptor - adding a HTTP Header

I'm trying to add an interceptor to just add a simple HTTP header, is there a nice way of doing this using IInvocation?

I've had a look around and can't see any examples of it, or via a WcfPolicy. An example of what I'm trying to do is below..

Cheers,

Jamie

 public void Intercept(IInvocation invocation)
    {
        Guard.NotNull(() => invocation, invocation);

        invocation.Proceed();

        AddVersionHeaders(invocation);
    }

    private static void AddVersionHeaders(IInvocation invocation)
    {
        using (var scope = new OperationContextScope(OperationContext.Current))
        {
            OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = new HttpRequestMessageProperty
            {
                Headers =
                {
                    {
                        "X-Version", invocation.TargetType.Assembly.GetName().Version.ToString()
                    }
                }
            };
        }
    }

Upvotes: 1

Views: 159

Answers (1)

Jamie
Jamie

Reputation: 864

In the end, just went with adding it in each Global.asax, would have been nice to have it in a library but perhaps simplicity over reuse is the best option.

Upvotes: 0

Related Questions