Standard library / net/http
http.ParseSetCookie()
Parse a single Set-Cookie response header, including recognized attributes. Parsing is not a browser-policy check. Expected stdout: 'demo / true true\n'.
Formal Syntax & Structure
go syntaxgo
func ParseSetCookie(line string) (*Cookie, error)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| line | string | Raw cookie header field value. |
Return Value
(*Cookie, error)
Operation result; check errors and validity indicators when returned.
Working Example
Example Snippetgo
package main
import ( "fmt" "net/http")
func main() { c := must(http.ParseSetCookie("demo=yes; Path=/; HttpOnly; Secure")) fmt.Println(c.Name, c.Path, c.HttpOnly, c.Secure)}
func must[T any](v T, e error) T { if e != nil { panic(e) } return v}func check(e error) { if e != nil { panic(e) }}