/// <summary>
        /// Used when performing CheckOrigin
        /// </summary>
        internal RequestParameters(Context context, string uri, Headers headers)
        {
            TraceId = context.InitialTraceId;
            Context = context;
            Headers = headers ?? new Headers();
            Uri     = URI.ParseInternal(uri, PercentCharsEscaped(headers), context, out var cachedProtocolProvider);
            var hasMacro = Uri?.Macro != null;

            if (hasMacro)
            {
                if (Uri.Macro.OverwriteHeaders)
                {
                    Uri.Macro.Headers?.ForEach(pair => Headers[pair.Key] = pair.Value);
                }
                else
                {
                    Uri.Macro.Headers?.ForEach(pair =>
                    {
                        var currentValue = Headers.SafeGet(pair.Key);
                        if (string.IsNullOrWhiteSpace(currentValue) || currentValue == "*/*")
                        {
                            Headers[pair.Key] = pair.Value;
                        }
                    });
                }
            }
            CachedProtocolProvider = cachedProtocolProvider;
            UnparsedUri            = uri;
            try
            {
                var _ = IResource;
            }
            catch (Exception e)
            {
                Error = e.AsError();
            }
            if (Error == null && Uri?.HasError == true)
            {
                Error = Uri.Error;
            }
        }
        /// <summary>
        /// Used when creating parsed requests
        /// </summary>
        internal RequestParameters(Context context, Method method, string uri, byte[] body, Headers headers)
        {
            TraceId            = context.InitialTraceId;
            Context            = context;
            Method             = method;
            Headers            = headers ?? new Headers();
            IsWebSocketUpgrade = Context.WebSocket?.Status == WebSocketStatus.Waiting;
            Uri = URI.ParseInternal(uri, PercentCharsEscaped(headers), context, out var cachedProtocolProvider);
            var hasMacro = Uri?.Macro != null;

            if (hasMacro)
            {
                if (Uri.Macro.OverwriteHeaders)
                {
                    Uri.Macro.Headers?.ForEach(pair => Headers[pair.Key] = pair.Value);
                }
                else
                {
                    Uri.Macro.Headers?.ForEach(pair =>
                    {
                        var currentValue = Headers.SafeGet(pair.Key);
                        if (string.IsNullOrWhiteSpace(currentValue) || currentValue == "*/*")
                        {
                            Headers[pair.Key] = pair.Value;
                        }
                    });
                }
            }
            CachedProtocolProvider = cachedProtocolProvider;
            UnparsedUri            = uri;
            if (Uri?.HasError == true)
            {
                Error = Uri.Error;
                return;
            }
            try
            {
                var _ = IResource;
            }
            catch (Exception e)
            {
                Error = e.AsError();
            }

            if (hasMacro)
            {
                if (Uri.Macro.OverwriteBody)
                {
                    if (Uri.Macro.HasBody)
                    {
                        BodyBytes           = Uri.Macro.Body;
                        Headers.ContentType = Providers.Json.ContentType;
                    }
                }
                else
                {
                    if (!(body?.Length > 0) && Uri.Macro.HasBody)
                    {
                        BodyBytes           = Uri.Macro.Body;
                        Headers.ContentType = Providers.Json.ContentType;
                    }
                    else
                    {
                        BodyBytes = body;
                    }
                }
            }
            else
            {
                BodyBytes = body;
            }
            HasBody = BodyBytes?.Length > 0;
        }