This class implements the client side of the Netscape V0 and RFC 2109 (V1) cookie protocols. It does not support RFC 2965 (V2) cookies.
There should be one instance of this class per user. Call readCookies()
after each HTTP response from the server, e.g., after URLConnection.getInputStream()
. Call writeCookies()
before each HTTP request to the server, e.g., before URLConnection.getOutputStream()
. These methods know how to match cookies against domains, expire cookies, etc.
There is a hard limit on the number of cookies stored at any moment. The default limit is 300 cookies for all hosts combined. If this limit is exceeded, cookies are removed by the LRU approximation policy.
Caveats:
HttpURLConnection
silently follows redirects, which means that you will not get to see the cookies in 3XX responses. This is wrong. Call HttpURLConnection.setInstanceFollowRedirects(false)
and handle the 3XX response codes yourself. HTTP allows for at most five redirects for a given request.URLConnection
s. Sun's implementation does some primitive connection pooling, but it's not nearly as good as com.google.io.ConnectionPool
. Sun's URLConnection
also does some HTTP magic behind your back.
|
|
|
|