protected void updateCookies(final HttpURLConnection http) {
		String headerName;
		preferenceLock.writeLock().lock();
		try {
			for (int i = 1; (headerName = http.getHeaderFieldKey(i)) != null; i++)
				if (headerName.equalsIgnoreCase("Set-Cookie")) {
					final String cookie = http.getHeaderField(i);

					final String cookieCrumb = cookie.substring(0, cookie.indexOf(';'));
					final String name = cookieCrumb.substring(0, cookieCrumb.indexOf('=')).trim();
					final String value = cookieCrumb.substring(cookieCrumb.indexOf('=') + 1, cookieCrumb.length()).trim();
					cookies.put(name, value);

					/* If the cookie's Expires date in the past, remove it. */
					final String[] cookieAttributes = cookie.substring(cookie.indexOf(';') + 1).split(";");
					for (final String cookieAttribute : cookieAttributes) {
						if (cookieAttribute.indexOf('=') == -1) {
							continue;
						}
						final String attrName = cookieAttribute.substring(0, cookieAttribute.indexOf('=')).trim();
						final String attrValue = cookieAttribute.substring(cookieAttribute.indexOf('=') + 1, cookieAttribute.length()).trim();
						if (attrName.equalsIgnoreCase("Expires")) {
							final Matcher m = rfc1123DateRegex.matcher(attrValue);
							if (m.find()) {
								try {
									final Date expires = rfc1123DateParser.parse(m.group(1));
									if (expires.compareTo(new Date()) < 0) {
										cookies.remove(name);
									}
								} catch (final ParseException e) {
									// don't care; just keep the cookie
								}
							}
						}
					}
				}
		} finally {
			preferenceLock.writeLock().unlock();
		}
	}