Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 836
Callum Linington Avatar asked Oct 31 '22 19:10

Callum Linington


2 Answers

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

.Add("Cookie", "cookie1=value1;cookie2=value2")
like image 97
Grzegorz Wróblewski Avatar answered Nov 08 '22 07:11

Grzegorz Wróblewski


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

like image 44
hnafar Avatar answered Nov 08 '22 07:11

hnafar