public async Task DefaultHeaders_SetCredentials_ClearedOnRedirect(Configuration.Http.RemoteServer remoteServer, int statusCode)
        {
            if (statusCode == 308 && (IsWinHttpHandler && PlatformDetection.WindowsVersion < 10))
            {
                // 308 redirects are not supported on old versions of WinHttp, or on .NET Framework.
                return;
            }

            HttpClientHandler handler = CreateHttpClientHandler();

            using (HttpClient client = CreateHttpClientForRemoteServer(remoteServer, handler))
            {
                string credentialString = _credential.UserName + ":" + _credential.Password;
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", credentialString);
                Uri uri = remoteServer.RedirectUriForDestinationUri(
                    statusCode: statusCode,
                    destinationUri: remoteServer.EchoUri,
                    hops: 1);
                _output.WriteLine("Uri: {0}", uri);
                using (HttpResponseMessage response = await client.GetAsync(uri))
                {
                    string responseText = await response.Content.ReadAsStringAsync();

                    _output.WriteLine(responseText);
                    Assert.False(TestHelper.JsonMessageContainsKey(responseText, "Authorization"));
                }
            }
        }
Exemplo n.º 2
0
        public async Task PostAsync_EmptyContent_ContentTypeHeaderNotSent(Configuration.Http.RemoteServer remoteServer)
        {
            using (HttpClient client = CreateHttpClientForRemoteServer(remoteServer))
                using (HttpResponseMessage response = await client.PostAsync(remoteServer.EchoUri, null))
                {
                    string responseContent = await response.Content.ReadAsStringAsync();

                    bool sentContentType = TestHelper.JsonMessageContainsKey(responseContent, "Content-Type");

                    Assert.False(sentContentType);
                }
        }
Exemplo n.º 3
0
        public async Task GetAsync_DefaultCoookieContainer_NoCookieSent()
        {
            using (HttpClient client = new HttpClient())
            {
                HttpResponseMessage httpResponse = await client.GetAsync(HttpTestServers.RemoteServerHeadersUri);

                string responseText = await httpResponse.Content.ReadAsStringAsync();

                _output.WriteLine(responseText);
                Assert.False(TestHelper.JsonMessageContainsKey(responseText, "Cookie"));
            }
        }
Exemplo n.º 4
0
        public async Task PostAsync_EmptyContent_ContentTypeHeaderNotSent(Uri serverUri)
        {
            using (HttpClient client = CreateHttpClient())
                using (HttpResponseMessage response = await client.PostAsync(serverUri, null))
                {
                    string responseContent = await response.Content.ReadAsStringAsync();

                    bool sentContentType = TestHelper.JsonMessageContainsKey(responseContent, "Content-Type");

                    Assert.False(sentContentType);
                }
        }
        public async Task DefaultHeaders_SetCredentials_ClearedOnRedirect(Configuration.Http.RemoteServer remoteServer, int statusCode)
        {
            HttpClientHandler handler = CreateHttpClientHandler();

            using (HttpClient client = CreateHttpClientForRemoteServer(remoteServer, handler))
            {
                string credentialString = _credential.UserName + ":" + _credential.Password;
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", credentialString);
                Uri uri = remoteServer.RedirectUriForDestinationUri(
                    statusCode: statusCode,
                    destinationUri: remoteServer.EchoUri,
                    hops: 1);
                _output.WriteLine("Uri: {0}", uri);
                using (HttpResponseMessage response = await client.GetAsync(uri))
                {
                    string responseText = await response.Content.ReadAsStringAsync();

                    _output.WriteLine(responseText);
                    Assert.False(TestHelper.JsonMessageContainsKey(responseText, "Authorization"));
                }
            }
        }