Callum Linington
Callum Linington

Reputation: 14417

Microsoft OWIN Test Server setting cookies

I have an Owin Test Server:

using (var testServer = TestServer.Create<TestPipelineConfiguration>())
using (var client = new HttpClient(testServer.Handler))
{
    client
        .DefaultRequestHeaders
        .Add("Cookie", $"{AspNetCookies}=HeyThere;");

    client.BaseAddress = new Uri("https://testserver/");

    var message = client
                    .PostAsync("print", new StringContent(
                                                jsonProvider.SerialiseObject(new
                                                {
                                                    Url = "https://some/url"
                                                }),
                                                Encoding.UTF8, "application/json"))
                    .Result;

    //var message = client.GetAsync("test").Result;

    message
        .StatusCode
        .ShouldBeEquivalentTo(HttpStatusCode.OK);
}

I want to set other properties on that cookie, like HttpOnly, Secure and Domain.

Is this possible?

Upvotes: 5

Views: 866

Answers (2)

hnafar
hnafar

Reputation: 611

Properties are part of the cookie value, semicolon separated, e.g. "Cookie=cookievalue; path=/; HttpOnly"

Upvotes: 1

Cookie is a header with list of key-value items. In your code it will look like this:

.Add("Cookie", "cookie1=value1;cookie2=value2")

Upvotes: 1

Related Questions