Skip to content

v3.1.0

Compare
Choose a tag to compare
@stifskere stifskere released this 05 Apr 14:50
· 6 commits to main since this release

Description

This release comes with cookies!

Features

There is now a cookies extension class, you can use in any IResponsible implementation.

new ResponseEntity(ResponseCodes.Ok)
        .WithCookie(new Cookie{ Name = "", Value = "" /*...*/ });

Headers are now a multiple value to one key map, meaning that you now may add a single cookie using the Add(string, string) method, otherwise, if using the indexer, you will need to pass an array.

- response.Headers["Name"] = "value";
+ response.Headers["Name"] = ["value"];

To add a single value to a key, simply use

response.Headers.Add("Name", "value");

Since all the collections implement IEnumerable, LINQ is available, so you may remove a single value from a key using it, mind that internally multiple value to one key maps are handled as a List<KeyValuePair<TKey, TValue>>.

Using the collection Remove(string) will remove all the values related to that key, so an example of removal using LINQ would be

response.Headers.RemoveAll(pair => pair.Value == "some value");

The WithoutCookie(this IResponsible, string) method only adds a Set-Cookie header with an anterior date as per this, so you might want to parse inside the RemoveAll method and check whether it has a value or a specified property.

response.Headers.RemoveAll(pair => pair.Key == "Set-Cookie" && Cookie.Parse(pair.value).Name == "CookieName");

Even tho, handling the cookie addition conditionally is always preferred.

Fixes

Parsers and strings are now file format agnostic, meaning that not mattering if the new line format is CL or CLRF the new lines are handled based on the System.Environment.NewLine constant property.