/// <summary>
 /// 设置http2非加密是否支持
 /// 例如:GRpc如果要对http进行支持,则需要启用
 /// 执行此方法后,默认是启用
 /// </summary>
 /// <param name="enable">是否启动</param>
 public static void SetHttp2UnencryptedSupport(bool enable = true)
 {
     AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", enable);
 }
예제 #2
0
        static partial void PopulateOverrideValuesPartial()
        {
            // Retrieve the value from EE config.
            string overrides = System.Runtime.Versioning.CompatibilitySwitch.GetAppContextOverridesInternalCall();

            // If we have no override values, do nothing.
            if (string.IsNullOrEmpty(overrides))
            {
                return;
            }

            bool encounteredEquals = false, encounteredCharsInKey = false, encounteredCharsInValue = false;
            int  previousSemicolonPos = -1, firstEqualsPos = -1;

            // Iterate over the string one character at a time until we reach the end of the string.
            for (int currentPos = 0; currentPos <= overrides.Length; currentPos++)
            {
                // If the current position is either ';' or 'end-of-string' then we potentially have a key=value pair
                if (currentPos == overrides.Length || overrides[currentPos] == ';')
                {
                    // We only have a key=value pair if we encountered an equals, characters in the key and in the value
                    // portion of the pair.
                    if (encounteredEquals && encounteredCharsInKey && encounteredCharsInValue)
                    {
                        // We compute the indexes in the string for key and value
                        int    firstCharOfKey = previousSemicolonPos + 1;                  //+1 because we don't take the ';' char
                        int    lenghtOfKey    = firstEqualsPos - previousSemicolonPos - 1; //-1 because we don't take the '=' char
                        string name           = overrides.Substring(firstCharOfKey, lenghtOfKey);

                        int    firstCharOfValue = firstEqualsPos + 1;              // +1 because we don't count the '='
                        int    lengthOfValue    = currentPos - firstEqualsPos - 1; // -1 because we don't count the '='
                        string value            = overrides.Substring(firstCharOfValue, lengthOfValue);

                        // apply the value only if it parses as a boolean
                        bool switchValue;
                        if (bool.TryParse(value, out switchValue))
                        {
                            // If multiple switches have the same name, the last value that we find will win.
                            AppContext.SetSwitch(name, switchValue);
                        }
                    }
                    previousSemicolonPos = currentPos;

                    // We need to reset these flags once we encounter a ';'
                    encounteredCharsInKey = encounteredCharsInValue = encounteredEquals = false;
                }
                else if (overrides[currentPos] == '=')
                {
                    // if the current character is '=' then we should flag it and remember it
                    if (!encounteredEquals)
                    {
                        encounteredEquals = true;
                        firstEqualsPos    = currentPos;
                    }
                }
                else
                {
                    // We need to know if the key or value contain any characters (other than ';' and '=');
                    if (encounteredEquals)
                    {
                        encounteredCharsInValue = true;
                    }
                    else
                    {
                        encounteredCharsInKey = true;
                    }
                }
            }
        }