@Override public String getRequestProperty(String field) { return delegate.getRequestProperty(field); }
@Override public String getRequestProperty(String field) { return delegate.getRequestProperty(field); }
private int getRangeStart(HttpURLConnection request) { String value = request.getRequestProperty(Constants.RANGE); // Header rangeHeader = request.getFirstHeader(Constants.RANGE); if (value != null) { return Integer.valueOf(value.substring(value.indexOf("bytes=") + 6, value.indexOf("-"))); } return 0; }
/** * Open connection * * @param threadId id of the calling thread, used only for debug * @param rangeStart range start * @param rangeEnd range end * @return a {@link java.net.URLConnection URLConnection} linking to the URL. * @throws IOException if an I/O exception occurs. */ HttpURLConnection openConnection(int threadId, long rangeStart, long rangeEnd) throws IOException { URL url = new URL(urls[current]); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setInstanceFollowRedirects(true); if (rangeStart >= 0) { String req = "bytes=" + rangeStart + "-"; if (rangeEnd > 0) req += rangeEnd; conn.setRequestProperty("Range", req); if (DEBUG) { Log.d(TAG, threadId + ":" + conn.getRequestProperty("Range")); } } return conn; }
/** * Add the appropriate Authorization header to the HttpURLConnection. * @param connection The HttpURLConnection to which the header will be added. * @param method The HTTP method to use (GET, PUT, DELETE) * @param bucket the bucket name this request is for * @param key the key this request is for * @param pathArgs path arguments which are part of this request */ private void addAuthHeader(HttpURLConnection connection, String method, String bucket, String key, Map pathArgs) { if(connection.getRequestProperty("Date") == null) { connection.setRequestProperty("Date", httpDate()); } if(connection.getRequestProperty("Content-Type") == null) { connection.setRequestProperty("Content-Type", ""); } if(this.awsAccessKeyId != null && this.awsSecretAccessKey != null) { String canonicalString= Utils.makeCanonicalString(method, bucket, key, pathArgs, connection.getRequestProperties()); String encodedCanonical=Utils.encode(this.awsSecretAccessKey, canonicalString, false); connection.setRequestProperty("Authorization", "AWS " + this.awsAccessKeyId + ":" + encodedCanonical); } }
new DelegationTokenAuthenticatedURL.Token(); if (authRetryCount > 0) { String contentType = conn.getRequestProperty(CONTENT_TYPE); String requestMethod = conn.getRequestMethod(); URL url = conn.getURL();
@Test public void testNormalOperation() throws Exception { // Setup client-side context Authentication clientSideAuthentication = new UsernamePasswordAuthenticationToken( "Aladdin", "open sesame"); SecurityContextHolder.getContext().setAuthentication(clientSideAuthentication); // Create a connection and ensure our executor sets its // properties correctly AuthenticationSimpleHttpInvokerRequestExecutor executor = new AuthenticationSimpleHttpInvokerRequestExecutor(); HttpURLConnection conn = new MockHttpURLConnection(new URL("http://localhost/")); executor.prepareConnection(conn, 10); // Check connection properties // See http://www.faqs.org/rfcs/rfc1945.html section 11.1 for example // we are comparing against assertThat(conn.getRequestProperty("Authorization")).isEqualTo( "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="); }
@Test public void testNullContextHolderIsNull() throws Exception { SecurityContextHolder.getContext().setAuthentication(null); // Create a connection and ensure our executor sets its // properties correctly AuthenticationSimpleHttpInvokerRequestExecutor executor = new AuthenticationSimpleHttpInvokerRequestExecutor(); HttpURLConnection conn = new MockHttpURLConnection(new URL("http://localhost/")); executor.prepareConnection(conn, 10); // Check connection properties (shouldn't be an Authorization header) assertThat(conn.getRequestProperty("Authorization")).isNull(); }
@Test public void testNullContextHolderWhenAnonymous() throws Exception { AnonymousAuthenticationToken anonymous = new AnonymousAuthenticationToken("key", "principal", AuthorityUtils.createAuthorityList("ROLE_ANONYMOUS")); SecurityContextHolder.getContext().setAuthentication(anonymous); // Create a connection and ensure our executor sets its // properties correctly AuthenticationSimpleHttpInvokerRequestExecutor executor = new AuthenticationSimpleHttpInvokerRequestExecutor(); HttpURLConnection conn = new MockHttpURLConnection(new URL("http://localhost/")); executor.prepareConnection(conn, 10); // Check connection properties (shouldn't be an Authorization header) assertThat(conn.getRequestProperty("Authorization")).isNull(); }
logger.appendKeyValue("URL", url); logger.appendKeyValue("Method", connection.getRequestMethod()); logger.appendKeyValue("User-Agent", connection.getRequestProperty("User-Agent")); logger.appendKeyValue("Content-Type", connection.getRequestProperty("Content-Type"));
@Test public void testSingleGetToHttpRequest() throws Exception { GraphRequest requestMe = new GraphRequest(null, "TourEiffel"); HttpURLConnection connection = GraphRequest.toHttpConnection(requestMe); assertTrue(connection != null); assertEquals("GET", connection.getRequestMethod()); assertEquals("/" + FacebookSdk.getGraphApiVersion() + "/TourEiffel", connection.getURL().getPath()); assertTrue(connection.getRequestProperty("User-Agent").startsWith("FBAndroidSDK")); Uri uri = Uri.parse(connection.getURL().toString()); assertEquals("android", uri.getQueryParameter("sdk")); assertEquals("json", uri.getQueryParameter("format")); }
@LargeTest public void testBuildsUploadPhotoHttpURLConnection() throws Exception { Bitmap image = createTestBitmap(128); GraphRequest request = GraphRequest.newUploadPhotoRequest( AccessToken.getCurrentAccessToken(), ShareInternalUtility.MY_PHOTOS, image, "Test photo messsage", null, null); HttpURLConnection connection = GraphRequest.toHttpConnection(request); assertTrue(connection != null); assertNotSame("gzip", connection.getRequestProperty("Content-Encoding")); assertNotSame("application/x-www-form-urlencoded", connection.getRequestProperty("Content-Type")); }
public String getContentType() { return connection.getRequestProperty("Content-Type"); }
public String getHeader(String name) { return connection.getRequestProperty(name); }
@SmallTest public void testSetVersion() throws Exception { String currentVersion = FacebookSdk.getGraphApiVersion(); FacebookSdk.setGraphApiVersion("v4.5"); GraphRequest requestMe = new GraphRequest(null, "TourEiffel"); HttpURLConnection connection = GraphRequest.toHttpConnection(requestMe); assertTrue(connection != null); assertEquals("GET", connection.getRequestMethod()); assertEquals("v4.5", FacebookSdk.getGraphApiVersion()); assertEquals("/v4.5" + "/TourEiffel", connection.getURL().getPath()); assertTrue(connection.getRequestProperty("User-Agent").startsWith("FBAndroidSDK")); Uri uri = Uri.parse(connection.getURL().toString()); assertEquals("android", uri.getQueryParameter("sdk")); assertEquals("json", uri.getQueryParameter("format")); FacebookSdk.setGraphApiVersion(currentVersion); } }
private static void logOutgoing(HttpURLConnection connection) { LOG.info("> " + connection.getRequestMethod() + " " + connection.getURL()); LOG.info("> Content-Type: " + connection.getRequestProperty("Content-Type")); LOG.info("> Accept: " + connection.getRequestProperty("Accept")); }
@Test public void spanStartingContainsHeader() { when(urlConnection.getRequestProperty(anyString())).thenReturn("bla bla"); ClientRequestAdapter<TextMap> adapter = sensor.getClientRequestAdapter(urlConnection, null, rsc); assertThat(adapter.startClientSpan(), is(false)); }
@Test public void spanStarting() { when(urlConnection.getRequestProperty(anyString())).thenReturn(null); ClientRequestAdapter<TextMap> adapter = sensor.getClientRequestAdapter(urlConnection, null, rsc); assertThat(adapter.startClientSpan(), is(true)); }
@Override public void eventOccurred(SendingRequestEvent eventArg) { HttpURLConnection connection = (HttpURLConnection) eventArg.getConnectionObject(); assertNotNull(connection.getRequestProperty("x-ms-foo")); assertNotNull(connection.getRequestProperty("x-ms-hello")); } };
@Test public void sendsUserAgent() throws IOException, InvalidArgumentException { String baseUrl = "http://example.com/graphql"; BraintreeGraphQLHttpClient httpClient = new BraintreeGraphQLHttpClient(baseUrl, TOKENIZATION_KEY); HttpURLConnection connection = httpClient.init(baseUrl); assertEquals("braintree/android/" + BuildConfig.VERSION_NAME, connection.getRequestProperty("User-Agent")); }