Standard library / net/http

http.Request.CookiesNamed()

Return all request cookies matching a name, including duplicates. Expected stdout: '2\n'.

Formal Syntax & Structure

go syntaxgo
func (r *Request) CookiesNamed(name string) []*Cookie

Parameters & Attributes

NameTypeDescription
namestringName of the requested cookie or field.

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 := must(http.NewRequest("GET", "http://example.invalid", nil))  r.Header.Set("Cookie", "a=1; a=2; b=3")  fmt.Println(len(r.CookiesNamed("a")))}
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