Example #1
0
        public void ダメインスタンス()
        {
            var instance = new HttpSettings();

            Assert.IsNotNull(instance);
            Assert.IsFalse(instance.IsValid);
        }
Example #2
0
        public void プロパティn()
        {
            dynamic instance = new HttpSettings();
            instance.n = 100;

            Assert.IsNotNull(instance);
            Assert.AreEqual(instance.n, 100);
        }
Example #3
0
        public void プロパティU()
        {
            dynamic instance = new HttpSettings();
            var url = new Uri("http://localhost");
            instance.U = url;

            Assert.IsNotNull(instance);
            Assert.AreEqual(instance.U, url);
        }
Example #4
0
        /// <summary>
        /// Starts a new session
        /// </summary>
        /// <returns>The session.</returns>
        /// <param name="operationTimeout">The operation timeout.</param>
        /// <param name="readwriteTimeout">The readwrite timeout.</param>
        /// <param name="bufferRequests">If set to <c>true</c> http requests are buffered.</param>
        public static IDisposable StartSession(TimeSpan operationTimeout = default(TimeSpan), TimeSpan readwriteTimeout = default(TimeSpan), bool bufferRequests = false, bool acceptAnyCertificate = false, string[] allowedCertificates = null)
        {
            // Make sure we always use our own version of the callback
            System.Net.ServicePointManager.ServerCertificateValidationCallback = ServicePointManagerCertificateCallback;

            var httpSettings = new HttpSettings
            {
                OperationTimeout     = operationTimeout,
                ReadWriteTimeout     = readwriteTimeout,
                BufferRequests       = bufferRequests,
                CertificateValidator = acceptAnyCertificate || (allowedCertificates != null)
                    ? new SslCertificateValidator(acceptAnyCertificate, allowedCertificates)
                    : null
            };

            return(CallContextSettings <HttpSettings> .StartContext(httpSettings));
        }
            public void Should_Add_Basic_Authorization_Header()
            {
                //Given
                HttpSettings settings = new HttpSettings();
                string       userName = "******";
                string       password = "******";

                //When
                settings.UseBasicAuthorization(userName, password);

                //Then
                var expected = "Basic c2NvdHQ6dGlnZXI=";

                Assert.NotNull(settings.Headers);
                Assert.True(settings.Headers.ContainsKey("Authorization"));
                Assert.Equal(settings.Headers["Authorization"], expected, StringComparer.OrdinalIgnoreCase);
            }
            public void Should_Add_Authorization_Header()
            {
                //Given
                HttpSettings settings  = new HttpSettings();
                string       schema    = "Bearer";
                string       parameter = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ0b3B0YWwuY29tIiwiZXhwIjoxNDI2NDIwODAwLCJodHRwOi8vdG9wdGFsLmNvbS9qd3RfY2xhaW1zL2lzX2FkbWluIjp0cnVlLCJjb21wYW55IjoiVG9wdGFsIiwiYXdlc29tZSI6dHJ1ZX0.yRQYnWzskCZUxPwaQupWkiUzKELZ49eM7oWxAQK_ZXw";

                //When
                settings.SetAuthorization(schema, parameter);

                //Then
                var expected = $"{schema} {parameter}";

                Assert.NotNull(settings.Headers);
                Assert.True(settings.Headers.ContainsKey("Authorization"));
                Assert.Equal(settings.Headers["Authorization"], expected, StringComparer.OrdinalIgnoreCase);
            }
        public async Task NullSendFormValue()
        {
            var settings = new HttpSettings();

            var form = new System.Collections.Specialized.NameValueCollection
            {
                ["nullValue"] = null,
            };

            var result = await Http.Request("https://httpbin.org/post", settings)
                         .SendForm(form)
                         .ExpectJson <HttpBinResponse>()
                         .PostAsync();

            Assert.True(result.Success);
            Assert.Null(result.Error);
            Assert.Same("", result.Data.Form["nullValue"]);
        }
Example #8
0
        public async Task <string> Login(LoginModel model)
        {
            var settings = new HttpSettings($"{this._url}/login", null, null, "Login");

            var body = new HttpBody <LoginModel>(model);

            string result = await this._httpService.CreateString <LoginModel>(settings, body);

            if (!string.IsNullOrEmpty(result))
            {
                await this._localStorageService.SetItemAsync("authToken", result);

                this._httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", result);
                ((ApiAuthenticationStateProvider)this._authenticationStateProvider).MarkUserAsAuthenticated();
            }

            return(result);
        }
Example #9
0
            public void Should_Replace_Existing_Header()
            {
                //Given
                HttpSettings settings = new HttpSettings()
                {
                    Headers = new Dictionary <string, string>
                    {
                        ["Content-Type"] = "application/json",
                        ["Accept"]       = "application/xml"
                    }
                };

                //When
                settings.AppendHeader("Content-Type", "text/xml");

                //Then
                Assert.Equal(settings.Headers["Content-Type"], "text/xml", StringComparer.OrdinalIgnoreCase);
            }
            public void Should_Post_And_Return_Json_Result()
            {
                //Given
                ICakeContext context    = _Context;
                HttpSettings settings   = new HttpSettings();
                string       address    = $"{ RootAddress }/posts";
                string       httpMethod = "POST";

                settings.SetRequestBody("{ \"title\": \"foo\", \"body\": \"bar\", \"userId\": 1}");

                //When
                var actual = HttpClientAliases.HttpSend(context, address, httpMethod, settings);

                //Then
                var expected = "{\n  \"id\": 101\n}";

                Assert.NotNull(actual);
                Assert.Equal(expected, actual, ignoreCase: true, ignoreLineEndingDifferences: true, ignoreWhiteSpaceDifferences: true);
            }
            public void Should_Put_And_Return_Json_Result()
            {
                //Given
                var putData = "{\r\n    title: 'foo',\r\n    body: 'bar',\r\n    userId: 1\r\n  }";

                ICakeContext context  = _Context;
                string       address  = $"{ RootAddress }/posts/1";
                HttpSettings settings = new HttpSettings();

                settings.SetRequestBody(putData);

                //When
                var actual = HttpClientAliases.HttpPut(context, address, settings);

                //Then
                var expected = "{\n  \"id\": 1\n}";

                Assert.NotNull(actual);
                Assert.Equal(expected, actual, ignoreCase: true, ignoreLineEndingDifferences: true, ignoreWhiteSpaceDifferences: true);
            }
            public void Should_Patch_And_Return_Json_Result()
            {
                //Given
                var patchData = "{\r\n    title: 'foo',\r\n    body: 'bar',\r\n    userId: 1\r\n  }";

                ICakeContext context  = _Context;
                string       address  = $"{ RootAddress }/posts/1";
                HttpSettings settings = new HttpSettings();

                settings.SetRequestBody(patchData);

                //When
                var actual = HttpClientAliases.HttpPatch(context, address, settings);

                //Then
                var expected = "{\n  \"userId\": 1,\n  \"id\": 1,\n  \"title\": \"sunt aut facere repellat provident occaecati excepturi optio reprehenderit\",\n  \"body\": \"quia et suscipit\\nsuscipit recusandae consequuntur expedita et cum\\nreprehenderit molestiae ut ut quas totam\\nnostrum rerum est autem sunt rem eveniet architecto\"\n}";

                Assert.NotNull(actual);
                Assert.Equal(expected, actual, ignoreCase: true, ignoreLineEndingDifferences: true, ignoreWhiteSpaceDifferences: true);
            }
Example #13
0
        public void Should_Add_Client_Certificates_From_Settings_To_Property()
        {
            //Given
            var cakeContext = Substitute.For <ICakeContext>();
            var settings    = new HttpSettings
            {
                ClientCertificates =
                {
                    Substitute.For <X509Certificate2>(),
                    Substitute.For <X509Certificate2>()
                }
            };

            //When
            var handler = new CakeHttpClientHandler(cakeContext, settings);

            //Then
            Assert.Equal(settings.ClientCertificates[0], handler.ClientCertificates[0]);
            Assert.Equal(settings.ClientCertificates[1], handler.ClientCertificates[1]);
        }
Example #14
0
            public void Should_Throw_On_Null_Or_Empty_ContentType_Parameter()
            {
                //Given
                HttpSettings settings    = new HttpSettings();
                string       contentType = null;

                //When
                contentType = null;
                var nullRecord = Record.Exception(() => HttpSettingsExtensions.SetContentType(settings, contentType));

                contentType = string.Empty;
                var emptyRecord = Record.Exception(() => HttpSettingsExtensions.SetContentType(settings, contentType));

                contentType = "      ";
                var spaceRecord = Record.Exception(() => HttpSettingsExtensions.SetContentType(settings, contentType));

                //Then
                CakeAssert.IsArgumentNullException(nullRecord, nameof(contentType));
                CakeAssert.IsArgumentNullException(emptyRecord, nameof(contentType));
                CakeAssert.IsArgumentNullException(spaceRecord, nameof(contentType));
            }
Example #15
0
        /// <inheritdoc />
        public IChangeableHttpBehaviour ShallowClone()
        {
            var result = (HttpBehaviour)MemberwiseClone();

            result.HttpSettings = HttpSettings.ShallowClone();
            // Make sure the RequestConfigurations are copied but changeable
            if (RequestConfigurations != null)
            {
                result.RequestConfigurations = new Dictionary <string, IHttpRequestConfiguration>();
                foreach (var key in RequestConfigurations.Keys)
                {
                    result.RequestConfigurations[key] = RequestConfigurations[key];
                }
            }
            // Make sure the RequestConfigurations are copied but changeable
            if (HttpContentConverters != null)
            {
                result.HttpContentConverters = new List <IHttpContentConverter>(HttpContentConverters);
            }
            return(result);
        }
Example #16
0
            public void Should_Throw_On_Null_Or_Empty_Token_Parameter()
            {
                //Given
                HttpSettings settings = new HttpSettings();
                string       token    = null;

                //When
                token = null;
                var nullRecord = Record.Exception(() => HttpSettingsExtensions.UseBearerAuthorization(settings, token));

                token = string.Empty;
                var emptyRecord = Record.Exception(() => HttpSettingsExtensions.UseBearerAuthorization(settings, token));

                token = "      ";
                var spaceRecord = Record.Exception(() => HttpSettingsExtensions.UseBearerAuthorization(settings, token));

                //Then
                CakeAssert.IsArgumentNullException(nullRecord, nameof(token));
                CakeAssert.IsArgumentNullException(emptyRecord, nameof(token));
                CakeAssert.IsArgumentNullException(spaceRecord, nameof(token));
            }
Example #17
0
            public void Should_Throw_On_Null_Or_Empty_Accept_Parameter()
            {
                //Given
                HttpSettings settings = new HttpSettings();
                string       accept   = null;

                //When
                accept = null;
                var nullRecord = Record.Exception(() => HttpSettingsExtensions.SetAccept(settings, accept));

                accept = string.Empty;
                var emptyRecord = Record.Exception(() => HttpSettingsExtensions.SetAccept(settings, accept));

                accept = "      ";
                var spaceRecord = Record.Exception(() => HttpSettingsExtensions.SetAccept(settings, accept));

                //Then
                CakeAssert.IsArgumentNullException(nullRecord, nameof(accept));
                CakeAssert.IsArgumentNullException(emptyRecord, nameof(accept));
                CakeAssert.IsArgumentNullException(spaceRecord, nameof(accept));
            }
Example #18
0
            public void Should_Throw_On_Null_Or_Empty_Url_Parameter()
            {
                //Given
                HttpSettings settings = new HttpSettings();
                string       url      = null;

                //When
                url = null;
                var nullRecord = Record.Exception(() => HttpSettingsExtensions.SetReferer(settings, url));

                url = string.Empty;
                var emptyRecord = Record.Exception(() => HttpSettingsExtensions.SetReferer(settings, url));

                url = "      ";
                var spaceRecord = Record.Exception(() => HttpSettingsExtensions.SetReferer(settings, url));

                //Then
                CakeAssert.IsArgumentNullException(nullRecord, nameof(url));
                CakeAssert.IsArgumentNullException(emptyRecord, nameof(url));
                CakeAssert.IsArgumentNullException(spaceRecord, nameof(url));
            }
Example #19
0
            public void Should_Throw_On_Null_Or_Empty_RequestBody_Parameter()
            {
                //Given
                HttpSettings settings    = new HttpSettings();
                string       requestBody = null;

                //When
                requestBody = null;
                var nullRecord = Record.Exception(() => HttpSettingsExtensions.SetRequestBody(settings, requestBody));

                requestBody = string.Empty;
                var emptyRecord = Record.Exception(() => HttpSettingsExtensions.SetRequestBody(settings, requestBody));

                requestBody = "      ";
                var spaceRecord = Record.Exception(() => HttpSettingsExtensions.SetRequestBody(settings, requestBody));

                //Then
                CakeAssert.IsArgumentNullException(nullRecord, nameof(requestBody));
                CakeAssert.IsArgumentNullException(emptyRecord, nameof(requestBody));
                CakeAssert.IsArgumentNullException(spaceRecord, nameof(requestBody));
            }
Example #20
0
            public void Should_Throw_On_Null_Or_Empty_Value_Parameter()
            {
                //Given
                HttpSettings settings = new HttpSettings();
                string       name     = "sessionid";
                string       value    = null;

                //When
                value = null;
                var nullRecord = Record.Exception(() => HttpSettingsExtensions.AppendCookie(settings, name, value));

                value = string.Empty;
                var emptyRecord = Record.Exception(() => HttpSettingsExtensions.AppendCookie(settings, name, value));

                value = "      ";
                var spaceRecord = Record.Exception(() => HttpSettingsExtensions.AppendCookie(settings, name, value));

                //Then
                CakeAssert.IsArgumentNullException(nullRecord, nameof(value));
                CakeAssert.IsArgumentNullException(emptyRecord, nameof(value));
                CakeAssert.IsArgumentNullException(spaceRecord, nameof(value));
            }
Example #21
0
            public void Should_Throw_On_Null_Or_Empty_Name_Parameter()
            {
                //Given
                HttpSettings settings = new HttpSettings();
                string       name     = null;
                string       value    = "1BA9481B-74C1-42B3-A1B9-0B914BAE0F05";

                //When
                name = null;
                var nullRecord = Record.Exception(() => HttpSettingsExtensions.AppendCookie(settings, name, value));

                name = string.Empty;
                var emptyRecord = Record.Exception(() => HttpSettingsExtensions.AppendCookie(settings, name, value));

                name = "      ";
                var spaceRecord = Record.Exception(() => HttpSettingsExtensions.AppendCookie(settings, name, value));

                //Then
                CakeAssert.IsArgumentNullException(nullRecord, nameof(name));
                CakeAssert.IsArgumentNullException(emptyRecord, nameof(name));
                CakeAssert.IsArgumentNullException(spaceRecord, nameof(name));
            }
Example #22
0
            public void Should_Throw_On_Null_Or_Empty_Password_Parameter()
            {
                //Given
                HttpSettings settings = new HttpSettings();
                string       userName = "******";
                string       password = null;

                //When
                password = null;
                var nullRecord = Record.Exception(() => HttpSettingsExtensions.UseBasicAuthorization(settings, userName, password));

                password = string.Empty;
                var emptyRecord = Record.Exception(() => HttpSettingsExtensions.UseBasicAuthorization(settings, userName, password));

                password = "******";
                var spaceRecord = Record.Exception(() => HttpSettingsExtensions.UseBasicAuthorization(settings, userName, password));

                //Then
                CakeAssert.IsArgumentNullException(nullRecord, nameof(password));
                CakeAssert.IsArgumentNullException(emptyRecord, nameof(password));
                CakeAssert.IsArgumentNullException(spaceRecord, nameof(password));
            }
            public void Should_Throw_On_Null_Or_Empty_Address_Parameter()
            {
                //Given
                ICakeContext context  = _Context;
                HttpSettings settings = new HttpSettings();
                string       address  = null;

                //When
                address = null;
                var nullRecord = Record.Exception(() => HttpClientAliases.HttpGetAsByteArray(context, address, settings));

                address = "";
                var emptyRecord = Record.Exception(() => HttpClientAliases.HttpGetAsByteArray(context, address, settings));

                address = "     ";
                var spaceRecord = Record.Exception(() => HttpClientAliases.HttpGetAsByteArray(context, address, settings));

                //Then
                CakeAssert.IsArgumentNullException(nullRecord, nameof(address));
                CakeAssert.IsArgumentNullException(emptyRecord, nameof(address));
                CakeAssert.IsArgumentNullException(spaceRecord, nameof(address));
            }
Example #24
0
        static void MockUp(
            int testDataSize,
            out HttpSettings httpSettings,
            out MemoryStream senderData,
            out Mock <IHttpResponse> mockHttpResponse,
            out MemoryStream receiverData,
            out HttpResponseHeader responseHeader)
        {
            httpSettings = HttpSettings.Default;
            httpSettings.MaxBodySizeInMemory = 4 * 1024;
            senderData = MockData.MemoryStream(testDataSize);
            var responseHeaderTmp = new HttpResponseHeader();

            responseHeader   = responseHeaderTmp;
            mockHttpResponse = new Mock <IHttpResponse>(MockBehavior.Strict);
            var isHeaderSent = false;
            var t            = mockHttpResponse.Object;

            mockHttpResponse
            .Setup(inst => inst.Header)
            .Returns(responseHeader);
            mockHttpResponse
            .Setup(inst => inst.IsHeaderSent)
            .Returns(() => isHeaderSent);
            mockHttpResponse
            .Setup(inst => inst.SendHeaderAsync())
            .Returns(delegate
            {
                if (isHeaderSent)
                {
                    throw new InvalidDataException();
                }
                isHeaderSent = true;
                responseHeaderTmp.IsWritable = false;
                return(Task.FromResult(true));
            });
            receiverData = new MemoryStream();
        }
Example #25
0
        public JasperRegistry()
        {
            Configuration.SetBasePath(Directory.GetCurrentDirectory());

            Publish = new PublishingExpression(Messaging);

            HttpRoutes = new HttpSettings(Messaging.Settings);

            Services = _applicationServices;

            establishApplicationAssembly();



            deriveServiceName();

            var name = ApplicationAssembly?.GetName().Name ?? "JasperApplication";

            CodeGeneration = new GenerationRules($"{name.Replace(".", "_")}_Generated");

            _baseServices = new JasperServiceRegistry(this);

            Settings = new JasperSettings(this);

            Settings.Require <SubscriptionSettings>();
            Settings.Replace(Messaging.Settings);
            Settings.Replace(Messaging.Settings.Http);


            Hosting = this;

            // ASP.Net Core will freak out if this isn't there
            EnvironmentConfiguration[WebHostDefaults.ApplicationKey] = ApplicationAssembly.FullName;

            Settings.Replace(HttpRoutes);
        }
        /// <inheritdoc />
        public async Task <bool> Login(LoginModel model)
        {
            var pathParams = new HttpPathParameters();

            pathParams.Add("login", -1);

            var settings = new HttpSettings(Url, null, pathParams, "Login");

            var body = new HttpBody <LoginModel>(model);

            var user = await _httpService.CreateWithResult <StorageUser, LoginModel>(settings, body);

            if (user == null)
            {
                return(false);
            }

            await _localStorageService.SetItemAsync("user", user);

            await _localStorageService.SetItemAsync("token", user.Token);

            _storeService.Add("user", user);
            return(true);
        }
Example #27
0
            public void Should_Set_Multiple_KeyValuePair_Request_Body_As_Url_Encoded()
            {
                //Given
                HttpSettings settings = new HttpSettings();
                var          data     = new []
                {
                    new KeyValuePair <string, string>("GroupId", "1"),
                    new KeyValuePair <string, string>("GroupId", "2"),
                    new KeyValuePair <string, string>("GroupId", "3")
                };

                //When
                settings.SetFormUrlEncodedRequestBody(data);

                //Then
                var expected = "GroupId=1&GroupId=2&GroupId=3";

                Assert.NotNull(settings.Headers);
                Assert.True(settings.Headers.ContainsKey("Content-Type"));
                Assert.Equal(settings.Headers["Content-Type"], "application/x-www-form-urlencoded");

                Assert.NotNull(settings.RequestBody);
                Assert.Equal(expected, Encoding.UTF8.GetString(settings.RequestBody));
            }
Example #28
0
        public ExchangeRateServiceAdapter(IConfigurationProvider configurationProvider, ISerializer serializer, IMemoryStreamPool memoryPool = null, IHttpConnector httpConnector = null)
        {
            _configurationProvider = configurationProvider;
            _httpSettings          = new HttpSettings();

            if (serializer != null)
            {
                _httpSettings.WithSerializer(serializer);
            }

            if (memoryPool != null)
            {
                _httpSettings.WithMemoryStreamPool(memoryPool);
            }

            if (httpConnector != null)
            {
                Func <IHttpConnector> func = () => httpConnector;
                _httpSettings.WithConnector(func);
            }
            var ip = GetSystemLocalIp();

            _httpSettings.Headers.Add(Constants.OskiUserIp, ip.Equals(string.Empty) ? Constants.UserIp : ip);
        }
Example #29
0
            public void Should_Set_Request_Body_As_Url_Encoded()
            {
                //Given
                HttpSettings settings             = new HttpSettings();
                IDictionary <string, string> data = new Dictionary <string, string>
                {
                    ["Id"]        = "123",
                    ["LastName"]  = "Test",
                    ["FirstName"] = "John"
                };

                //When
                settings.SetFormUrlEncodedRequestBody(data);

                //Then
                var expected = "Id=123&LastName=Test&FirstName=John";

                Assert.NotNull(settings.Headers);
                Assert.True(settings.Headers.ContainsKey("Content-Type"));
                Assert.Equal(settings.Headers["Content-Type"], "application/x-www-form-urlencoded");

                Assert.NotNull(settings.RequestBody);
                Assert.Equal(expected, Encoding.UTF8.GetString(settings.RequestBody));
            }
Example #30
0
        public void インスタンス生成()
        {
            dynamic instance = new HttpSettings();

            Assert.IsNotNull(instance);
        }
Example #31
0
        /// <summary>
        /// vmess协议远程服务器底层传输配置
        /// </summary>
        /// <param name="config"></param>
        /// <param name="iobound"></param>
        /// <param name="streamSettings"></param>
        /// <returns></returns>
        private static int boundStreamSettings(Config config, string iobound, ref StreamSettings streamSettings)
        {
            try
            {
                //远程服务器底层传输配置
                streamSettings.network  = config.network();
                streamSettings.security = config.streamSecurity();

                //streamSettings
                switch (config.network())
                {
                //kcp基本配置暂时是默认值,用户能自己设置伪装类型
                case "kcp":
                    KcpSettings kcpSettings = new KcpSettings();
                    kcpSettings.mtu = config.kcpItem.mtu;
                    kcpSettings.tti = config.kcpItem.tti;
                    if (iobound.Equals("out"))
                    {
                        kcpSettings.uplinkCapacity   = config.kcpItem.uplinkCapacity;
                        kcpSettings.downlinkCapacity = config.kcpItem.downlinkCapacity;
                    }
                    else if (iobound.Equals("in"))
                    {
                        kcpSettings.uplinkCapacity   = config.kcpItem.downlinkCapacity;;
                        kcpSettings.downlinkCapacity = config.kcpItem.downlinkCapacity;
                    }
                    else
                    {
                        kcpSettings.uplinkCapacity   = config.kcpItem.uplinkCapacity;
                        kcpSettings.downlinkCapacity = config.kcpItem.downlinkCapacity;
                    }

                    kcpSettings.congestion      = config.kcpItem.congestion;
                    kcpSettings.readBufferSize  = config.kcpItem.readBufferSize;
                    kcpSettings.writeBufferSize = config.kcpItem.writeBufferSize;
                    kcpSettings.header          = new Header();
                    kcpSettings.header.type     = config.headerType();
                    streamSettings.kcpSettings  = kcpSettings;
                    break;

                //ws
                case "ws":
                    WsSettings wsSettings = new WsSettings();
                    wsSettings.connectionReuse = true;

                    string host2 = config.requestHost().Replace(" ", "");
                    string path  = config.path().Replace(" ", "");
                    if (!string.IsNullOrWhiteSpace(host2))
                    {
                        wsSettings.headers      = new Headers();
                        wsSettings.headers.Host = host2;
                    }
                    if (!string.IsNullOrWhiteSpace(path))
                    {
                        wsSettings.path = path;
                    }
                    streamSettings.wsSettings = wsSettings;

                    TlsSettings tlsSettings = new TlsSettings();
                    tlsSettings.allowInsecure  = config.allowInsecure();
                    streamSettings.tlsSettings = tlsSettings;
                    break;

                //h2
                case "h2":
                    HttpSettings httpSettings = new HttpSettings();

                    string host3 = config.requestHost().Replace(" ", "");
                    if (!string.IsNullOrWhiteSpace(host3))
                    {
                        httpSettings.host = Utils.String2List(host3);
                    }
                    httpSettings.path = config.path().Replace(" ", "");

                    streamSettings.httpSettings = httpSettings;

                    TlsSettings tlsSettings2 = new TlsSettings();
                    tlsSettings2.allowInsecure = config.allowInsecure();
                    streamSettings.tlsSettings = tlsSettings2;
                    break;

                default:
                    //tcp带http伪装
                    if (config.headerType().Equals(Global.TcpHeaderHttp))
                    {
                        TcpSettings tcpSettings = new TcpSettings();
                        tcpSettings.connectionReuse = true;
                        tcpSettings.header          = new Header();
                        tcpSettings.header.type     = config.headerType();

                        //request填入自定义Host
                        string   request = Utils.GetEmbedText(Global.v2raySampleHttprequestFileName);
                        string[] arrHost = config.requestHost().Replace(" ", "").Split(',');
                        string   host    = string.Join("\",\"", arrHost);
                        request = request.Replace("$requestHost$", string.Format("\"{0}\"", host));
                        //request = request.Replace("$requestHost$", string.Format("\"{0}\"", config.requestHost()));

                        string response = Utils.GetEmbedText(Global.v2raySampleHttpresponseFileName);

                        tcpSettings.header.request  = Utils.FromJson <object>(request);
                        tcpSettings.header.response = Utils.FromJson <object>(response);
                        streamSettings.tcpSettings  = tcpSettings;
                    }
                    break;
                }
            }
            catch
            {
            }
            return(0);
        }
Example #32
0
 public void 存在しないプロパティX()
 {
     dynamic instance = new HttpSettings();
     instance.X = 100;
 }
Example #33
0
        public async Task <UserShortDto> GetShortUser()
        {
            var settings = new HttpSettings($"{this._url}/shorter");

            return(await this._httpService.Get <UserShortDto>(settings));
        }
 public void methods_are_candidate_actions()
 {
     HttpSettings.IsCandidate(ReflectionHelper.GetMethod <RoutedEndpoint>(x => x.get_with_date_time(DateTime.MinValue))).ShouldBeTrue();
     HttpSettings.IsCandidate(ReflectionHelper.GetMethod <RoutedEndpoint>(x => x.get_with_dateoffset_time(DateTimeOffset.MaxValue))).ShouldBeTrue();
     HttpSettings.IsCandidate(ReflectionHelper.GetMethod <RoutedEndpoint>(x => x.get_with_number_value(55))).ShouldBeTrue();
 }
Example #35
0
        internal static AuthConfigData DeserializeAuthConfigData(JsonElement element)
        {
            ResourceIdentifier           id                = default;
            string                       name              = default;
            ResourceType                 type              = default;
            SystemData                   systemData        = default;
            Optional <AuthPlatform>      platform          = default;
            Optional <GlobalValidation>  globalValidation  = default;
            Optional <IdentityProviders> identityProviders = default;
            Optional <ContainerAppLogin> login             = default;
            Optional <HttpSettings>      httpSettings      = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("id"))
                {
                    id = new ResourceIdentifier(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("name"))
                {
                    name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("type"))
                {
                    type = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("systemData"))
                {
                    systemData = JsonSerializer.Deserialize <SystemData>(property.Value.ToString());
                    continue;
                }
                if (property.NameEquals("properties"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        if (property0.NameEquals("platform"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            platform = AuthPlatform.DeserializeAuthPlatform(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("globalValidation"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            globalValidation = GlobalValidation.DeserializeGlobalValidation(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("identityProviders"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            identityProviders = IdentityProviders.DeserializeIdentityProviders(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("login"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            login = ContainerAppLogin.DeserializeContainerAppLogin(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("httpSettings"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            httpSettings = HttpSettings.DeserializeHttpSettings(property0.Value);
                            continue;
                        }
                    }
                    continue;
                }
            }
            return(new AuthConfigData(id, name, type, systemData, platform.Value, globalValidation.Value, identityProviders.Value, login.Value, httpSettings.Value));
        }
 public IHttpBuilder Settings(HttpSettings settings) => Set(() => _settings = settings);