session - What is the difference between cookie and cookiejar? -
today faced term "cookiejar" (package net/http/cookiejar). tried gather information regarding it, got nothing intelligible. know cookie key/value pairs server sends client, eg: set-cookie: foo=10, browser store locally , each subsequent request browser send these cookies server, eg: cookie: foo=10.
ok, cookiejar? , how looks like?
as described in question, cookies managed browsers (http clients) , allow store information on clients' computers sent automatically browser on subsequent requests.
if application acts client (you connect remote http servers using net/http package), there no browser handle / manage cookies. mean storing/remembering cookies arrive set-cookie: response headers, , attaching them subsequent outgoing requests being made same host/domain. cookies have expiration date have check before deciding include them in outgoing requests.
the http.client type allows set value of type http.cookiejar, , if so, have automatic cookie management otherwise not exist or have yourself. enables multiple requests net/http package server see part of same session if made real browser, http sessions (the session ids) maintained using cookies.
the package net/http/cookiejar cookiejar implementation can use out of box. note implementation in-memory means if restart application, cookies lost.
so http cookie small piece of data sent website , stored in user's web browser while user browsing website.
cookiejar go interface of simple cookie manager (to manage cookies http request , response headers) , implementation of interface.
Comments
Post a Comment