/** @return {@code location} with query parameter 'digest' set to the BLOB's digest */ @Override public URL getApiRoute(String apiRouteBase) { return new GenericUrl(location).set("digest", blobDigest).toURL(); }
/** * Extract the {@code Location} header from the response to get the new location for the next * request. * * <p>The {@code Location} header can be relative or absolute. * * @see <a * href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location#Directives">https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location#Directives</a> * @param response the response to extract the 'Location' header from * @return the new location for the next request * @throws RegistryErrorException if there was not a single 'Location' header */ private URL getRedirectLocation(Response response) throws RegistryErrorException { // Extracts and returns the 'Location' header. List<String> locationHeaders = response.getHeader("Location"); if (locationHeaders.size() != 1) { throw buildRegistryErrorException( "Expected 1 'Location' header, but found " + locationHeaders.size()); } String locationHeader = locationHeaders.get(0); return response.getRequestUrl().toURL(locationHeader); } }
@Nullable private T fallBackToHttp(URL url) throws IOException, RegistryException { GenericUrl httpUrl = new GenericUrl(url); httpUrl.setScheme("http"); eventDispatcher.dispatch( LogEvent.info( "Failed to connect to " + url + " over HTTPS. Attempting again with HTTP: " + httpUrl)); return call(httpUrl.toURL(), connectionFactory); }
String host = url.getHost(); int port = url.getPort(); port = port > 0 ? port : url.toURL().getDefaultPort(); String path = "/upload" + url.getRawPath(); url = new GenericUrl(scheme + "://" + host + ":" + port + path);
/** @return {@code location} with query parameter 'digest' set to the BLOB's digest */ @Override public URL getApiRoute(String apiRouteBase) { return new GenericUrl(location).set("digest", blobDigest).toURL(); }
/** @return {@code location} with query parameter 'digest' set to the BLOB's digest */ @Override public URL getApiRoute(String apiRouteBase) { return new GenericUrl(location).set("digest", blobDigest).toURL(); }
/** * Extract the {@code Location} header from the response to get the new location for the next * request. * * <p>The {@code Location} header can be relative or absolute. * * @see <a * href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location#Directives">https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location#Directives</a> * @param response the response to extract the 'Location' header from * @return the new location for the next request * @throws RegistryErrorException if there was not a single 'Location' header */ private URL getRedirectLocation(Response response) throws RegistryErrorException { // Extracts and returns the 'Location' header. List<String> locationHeaders = response.getHeader("Location"); if (locationHeaders.size() != 1) { throw buildRegistryErrorException( "Expected 1 'Location' header, but found " + locationHeaders.size()); } String locationHeader = locationHeaders.get(0); return response.getRequestUrl().toURL(locationHeader); } }
/** * Extract the {@code Location} header from the response to get the new location for the next * request. * * <p>The {@code Location} header can be relative or absolute. * * @see <a * href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location#Directives">https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location#Directives</a> * @param response the response to extract the 'Location' header from * @return the new location for the next request * @throws RegistryErrorException if there was not a single 'Location' header */ private URL getRedirectLocation(Response response) throws RegistryErrorException { // Extracts and returns the 'Location' header. List<String> locationHeaders = response.getHeader("Location"); if (locationHeaders.size() != 1) { throw buildRegistryErrorException( "Expected 1 'Location' header, but found " + locationHeaders.size()); } String locationHeader = locationHeaders.get(0); return response.getRequestUrl().toURL(locationHeader); } }
@Nullable private T fallBackToHttp(URL url) throws IOException, RegistryException { GenericUrl httpUrl = new GenericUrl(url); httpUrl.setScheme("http"); eventDispatcher.dispatch( LogEvent.info( "Failed to connect to " + url + " over HTTPS. Attempting again with HTTP: " + httpUrl)); return call(httpUrl.toURL(), connectionFactory); }
@Nullable private T fallBackToHttp(URL url) throws IOException, RegistryException { GenericUrl httpUrl = new GenericUrl(url); httpUrl.setScheme("http"); eventDispatcher.dispatch( LogEvent.info( "Failed to connect to " + url + " over HTTPS. Attempting again with HTTP: " + httpUrl)); return call(httpUrl.toURL(), connectionFactory); }
HTTPRequestInfo(HttpRequest req) { method = req.getRequestMethod(); url = req.getUrl().toURL(); long myLength; HttpContent content = req.getContent(); try { myLength = content == null ? -1 : content.getLength(); } catch (IOException e) { myLength = -1; } length = myLength; h1 = req.getHeaders(); h2 = null; }
@VisibleForTesting RequestInfo buildRequestInfo(HttpRequest request) { RequestInfo.Builder requestBuilder = new RequestInfo.Builder(); if (request != null) { requestBuilder.withServiceName("reportdownload").withMethodName(request.getRequestMethod()); try { requestBuilder.withUrl(request.getUrl().toURL().toString()); } catch (IllegalArgumentException e) { requestBuilder.withUrl("Malformed URL: " + request.getUrl()); } if (request.getHeaders() != null) { String clientCustomerId = request.getHeaders().getFirstHeaderStringValue(CLIENT_CUSTOMER_ID); requestBuilder.withContext(CLIENT_CUSTOMER_ID, clientCustomerId); } // Get the payload from the request. requestBuilder.withPayload(extractPayload(request.getHeaders(), request.getContent())); } return requestBuilder.build(); }
@VisibleForTesting RequestInfo buildRequestInfo(HttpRequest request) { RequestInfo.Builder requestBuilder = new RequestInfo.Builder(); if (request != null) { requestBuilder.withServiceName("reportdownload").withMethodName(request.getRequestMethod()); try { requestBuilder.withUrl(request.getUrl().toURL().toString()); } catch (IllegalArgumentException e) { requestBuilder.withUrl("Malformed URL: " + request.getUrl()); } if (request.getHeaders() != null) { String clientCustomerId = request.getHeaders().getFirstHeaderStringValue(CLIENT_CUSTOMER_ID); requestBuilder.withContext(CLIENT_CUSTOMER_ID, clientCustomerId); } // Get the payload from the request. requestBuilder.withPayload(extractPayload(request.getHeaders(), request.getContent())); } return requestBuilder.build(); }
String host = url.getHost(); int port = url.getPort(); port = port > 0 ? port : url.toURL().getDefaultPort(); String path = "/upload" + url.getRawPath(); url = new GenericUrl(scheme + "://" + host + ":" + port + path);
/** * Return an URL that performs the authorization consent prompt web UI. * * @param userId Application's identifier for the end user. * @param state State that is passed on to the OAuth2 callback URI after the consent. * @param baseUri The URI to resolve the OAuth2 callback URI relative to. * @return The URL that can be navigated or redirected to. */ public URL getAuthorizationUrl(String userId, String state, URI baseUri) { URI resolvedCallbackUri = getCallbackUri(baseUri); String scopesString = Joiner.on(' ').join(scopes); GenericUrl url = new GenericUrl(userAuthUri); url.put("response_type", "code"); url.put("client_id", clientId.getClientId()); url.put("redirect_uri", resolvedCallbackUri); url.put("scope", scopesString); if (state != null) { url.put("state", state); } url.put("access_type", "offline"); url.put("approval_prompt", "force"); if (userId != null) { url.put("login_hint", userId); } url.put("include_granted_scopes", true); return url.toURL(); }
/** * Return an URL that performs the authorization consent prompt web UI. * * @param userId Application's identifier for the end user. * @param state State that is passed on to the OAuth2 callback URI after the consent. * @param baseUri The URI to resolve the OAuth2 callback URI relative to. * @return The URL that can be navigated or redirected to. */ public URL getAuthorizationUrl(String userId, String state, URI baseUri) { URI resolvedCallbackUri = getCallbackUri(baseUri); String scopesString = Joiner.on(' ').join(scopes); GenericUrl url = new GenericUrl(userAuthUri); url.put("response_type", "code"); url.put("client_id", clientId.getClientId()); url.put("redirect_uri", resolvedCallbackUri); url.put("scope", scopesString); if (state != null) { url.put("state", state); } url.put("access_type", "offline"); url.put("approval_prompt", "force"); if (userId != null) { url.put("login_hint", userId); } url.put("include_granted_scopes", true); return url.toURL(); }