Standard library / net/http
http.Request.AddCookie()
Append a request cookie without copying response-only attributes. Expected stdout: 'demo=yes\n'.
Formal Syntax & Structure
go syntaxgo
func (r *Request) AddCookie(c *Cookie)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| c | *Cookie | Third address octet. |
Working Example
Example Snippetgo
package main
import ( "fmt" "net/http")
func main() { r := must(http.NewRequest("GET", "http://example.invalid", nil)) r.AddCookie(&http.Cookie{Name: "demo", Value: "yes", Path: "/"}) fmt.Println(r.Header.Get("Cookie"))}
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) }}