@Override
List<Cookie> getAppEngineLoginCookies(String urlStr) throws IOException {
FetchOptions fetchOptions = FetchOptions.Builder.doNotFollowRedirects();
URL url = new URL(urlStr);
HTTPRequest req = new HTTPRequest(url, HTTPMethod.GET, fetchOptions);
HTTPResponse resp = fetchService.fetch(req);
if (resp.getResponseCode() != 302) {
throw new LoginException("unexpected response from app engine: " + resp.getResponseCode());
}
List<Cookie> cookies = new ArrayList<Cookie>();
for (HTTPHeader header : resp.getHeaders()) {
if (header.getName().toLowerCase().equals("set-cookie")) {
CookieSpecBase spec = new CookieSpecBase();
Collections.addAll(cookies, spec.parse(url.getHost(),
url.getPort() == -1 ? 0 : url.getPort(), url.getPath(),
url.getProtocol().equals("https"), header.getValue()));