http-wasm / http-wasm-guest-tinygo

HTTP Middleware library for TinyGo used to compile WebAssembly Guest modules
Apache License 2.0
21 stars 10 forks source link

Provide easy way to setup cookie to response #31

Open zetaab opened 1 year ago

zetaab commented 1 year ago

Currently there is no easy way to add http.Cookie to response https://github.com/http-wasm/http-wasm-guest-tinygo/blob/main/handler/api/api.go#L135

of course it can be done through w.Header().Add("Set-Cookie", "a=b"). However, it would be nice to have helper function which does this out of the box (including parameters like Expires, Secure, HttpOnly). Example from go source https://cs.opensource.google/go/go/+/refs/tags/go1.21.3:src/net/http/cookie.go;l=169

zetaab commented 12 months ago

actually I found pretty easy way:

    cook := &http.Cookie{
        Name:     "bar",
        Value:    "foo",
        Path:     "/",
        HttpOnly: true,
        Secure:   true,
        Domain:   host,
        MaxAge:   3600 * 12,
    }
    resp.Headers().Add("Set-Cookie", cook.String())