util::http::set_cookies (public)
util::http::set_cookies -resp_headers resp_headers \ [ -headers headers ] [ -cookie_names cookie_names ] \ [ -pattern pattern ]
Defined in packages/acs-tcl/tcl/http-client-procs.tcl
Extracts cookies from response headers. This is done reading every 'set-cookie' header and populating an ns_set of request headers suitable for issuing 'util::http' requests.
- Switches:
- -resp_headers (required)
- Response headers, in a list form as returned by 'util::http' API.
- -headers (optional)
- ns_set of request headers that will be populated with extracted cookies. If not specified, a new ns_set will be created. Existing cookies will be overwritten.
- -cookie_names (optional)
- Cookie names we want to retrieve. Other cookies will be ignored. If omitted together with '-pattern' proc will include every cookie.
- -pattern (optional)
- Cookies which name respects this pattern as in 'string match' will be included. If omitted together with '-cookie_names' proc will include every cookie.
- Returns:
- ns_set of headers containing received cookies
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
Source code: if {$headers eq ""} { set headers [ns_set create headers] } set cookies [list] foreach {name value} $resp_headers { # get only set-cookie headers, ignoring case set name [string tolower $name] if {$name ne "set-cookie"} continue # keep only relevant part of the cookie set cookie [lindex [split $value ";"] 0] set cookie_name [lindex [split $cookie "="] 0] if {($cookie_names eq "" || $cookie_name in $cookie_names) && ($pattern eq "" || [string match $pattern $cookie_name])} { lappend cookies $cookie } } ns_set idelkey $headers "cookie" set cookies [join $cookies "; "] ns_set put $headers "cookie" $cookies return $headersXQL Not present: Generic, PostgreSQL, Oracle