Standard library / net/http

http.Response.Cookies()

Parse Set-Cookie headers from a response; this does not itself store them. Expected stdout: '2\n'.

Formal Syntax & Structure

go syntaxgo
func (r *Response) Cookies() []*Cookie

Return Value

[]*Cookie

Operation result; check errors and validity indicators when returned.

Working Example

Example Snippetgo
package main
import (  "fmt"  "net/http")
func main() {  r := &http.Response{Header: http.Header{"Set-Cookie": {"a=1", "b=2"}}}  fmt.Println(len(r.Cookies()))}
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)  }}
Go Reference