Пример #1
0
 public void UrlRewriteTo(string url)
 {
     if (!this.IsRewrite)
     {
         this.IsRewrite     = true;
         this.SourceUrl     = Url;
         this.SourceBaseUrl = BaseUrl;
         this.SourcePath    = Path;
     }
     Ext = null;
     Url = url;
     mQueryStringIndex = HttpParse.ReadUrlQueryString(Url, null, this);
     if (mQueryStringIndex > 0)
     {
         HttpParse.ReadUrlPathAndExt(Url.AsSpan().Slice(0, mQueryStringIndex), mQueryString, this, this.Server.Options);
     }
     else
     {
         HttpParse.ReadUrlPathAndExt(Url.AsSpan(), mQueryString, this, this.Server.Options);
     }
     if (Server.EnableLog(EventArgs.LogType.Info))
     {
         Server.BaseServer.Log(EventArgs.LogType.Info, Session, $"HTTP {ID} {((IPEndPoint)Session.RemoteEndPoint).Address} request {SourceUrl} rewrite to {Url}");
     }
 }
Пример #2
0
        private void LoadMethod(PipeStream stream)
        {
            if (mState == LoadedState.None)
            {
                string data;
                if (!stream.TryReadWith(HeaderTypeFactory.LINE_BYTES, out data))
                {
                    return;
                }
                HttpParse.AnalyzeRequestLine(data, this);
                HttpParse.ReadHttpVersionNumber(HttpVersion, mQueryString, this);
                int len = HttpParse.ReadUrlQueryString(Url, mQueryString, this);
                if (len > 0)
                {
                    HttpParse.ReadUrlPathAndExt(Url.AsSpan().Slice(0, len), mQueryString, this, this.Server.ServerConfig);
                }
                else
                {
                    HttpParse.ReadUrlPathAndExt(Url.AsSpan(), mQueryString, this, this.Server.ServerConfig);
                }

                RouteMatchResult routeMatchResult = new RouteMatchResult();
                if (Server.UrlRewrite.Match(this, ref routeMatchResult, mQueryString))
                {
                    this.IsRewrite = true;
                    this.SourceUrl = this.Url;
                    if (Server.EnableLog(EventArgs.LogType.Info))
                    {
                        Server.BaseServer.Log(EventArgs.LogType.Info, Session, "request rewrite {0}  to {1}", Url, routeMatchResult.RewriteUrl);
                    }
                    Url = routeMatchResult.RewriteUrl;
                    if (Server.ServerConfig.UrlIgnoreCase)
                    {
                        BaseUrl = routeMatchResult.RewriteUrlLower;
                    }
                    else
                    {
                        BaseUrl = routeMatchResult.RewriteUrl;
                    }
                    Ext = routeMatchResult.Ext;
                }
                mState = LoadedState.Method;
            }
        }
Пример #3
0
 private void LoadMethod(PipeStream stream)
 {
     if (mState == LoadedState.None)
     {
         Span <char> data;
         if (!stream.ReadLine(out data))
         {
             return;
         }
         HttpParse.AnalyzeRequestLine(data, this);
         HttpParse.ReadHttpVersionNumber(HttpVersion, mQueryString, this);
         int len = HttpParse.ReadUrlQueryString(Url, mQueryString, this);
         if (len > 0)
         {
             HttpParse.ReadUrlPathAndExt(Url.AsSpan().Slice(0, len), mQueryString, this, this.Server.Options);
         }
         else
         {
             HttpParse.ReadUrlPathAndExt(Url.AsSpan(), mQueryString, this, this.Server.Options);
         }
         //UrlCode = BaseUrl.GetHashCode() << 16 | BaseUrl.Length;
         RouteMatchResult routeMatchResult = new RouteMatchResult();
         if (Server.UrlRewrite.Count > 0 && Server.UrlRewrite.Match(this, ref routeMatchResult, mQueryString))
         {
             this.IsRewrite = true;
             this.SourceUrl = this.Url;
             if (Server.EnableLog(EventArgs.LogType.Info))
             {
                 Server.BaseServer.Log(EventArgs.LogType.Info, Session, $"HTTP {ID} request rewrite {Url} to {routeMatchResult.RewriteUrl}");
             }
             Url = routeMatchResult.RewriteUrl;
             if (Server.Options.UrlIgnoreCase)
             {
                 BaseUrl = routeMatchResult.RewriteUrlLower;
             }
             else
             {
                 BaseUrl = routeMatchResult.RewriteUrl;
             }
             Ext = routeMatchResult.Ext;
         }
         mState = LoadedState.Method;
     }
 }
Пример #4
0
 private void LoadMethod(PipeStream stream)
 {
     if (mState == LoadedState.None)
     {
         Span <char> data;
         if (!stream.ReadLine(out data))
         {
             return;
         }
         PathLevel = 0;
         HttpParse.AnalyzeRequestLine(data, this);
         HttpParse.ReadHttpVersionNumber(HttpVersion, mQueryString, this);
         mQueryStringIndex = HttpParse.ReadUrlQueryString(Url, mQueryString, this);
         if (mQueryStringIndex > 0)
         {
             HttpParse.ReadUrlPathAndExt(Url.AsSpan().Slice(0, mQueryStringIndex), mQueryString, this, this.Server.Options);
         }
         else
         {
             HttpParse.ReadUrlPathAndExt(Url.AsSpan(), mQueryString, this, this.Server.Options);
         }
         mState = LoadedState.Method;
     }
 }
Пример #5
0
 private void LoadMethod(PipeStream stream)
 {
     if (mState == LoadedState.None)
     {
         Span <char> data;
         if (!stream.ReadLine(out data))
         {
             return;
         }
         HttpParse.AnalyzeRequestLine(data, this);
         HttpParse.ReadHttpVersionNumber(HttpVersion, mQueryString, this);
         int len = HttpParse.ReadUrlQueryString(Url, mQueryString, this);
         if (len > 0)
         {
             HttpParse.ReadUrlPathAndExt(Url.AsSpan().Slice(0, len), mQueryString, this, this.Server.Options);
         }
         else
         {
             HttpParse.ReadUrlPathAndExt(Url.AsSpan(), mQueryString, this, this.Server.Options);
         }
         RouteMatchResult routeMatchResult = new RouteMatchResult();
         this.IsRewrite = false;
         if (Server.UrlRewrite.Count > 0 && Server.UrlRewrite.Match(this, ref routeMatchResult, mQueryString))
         {
             this.IsRewrite     = true;
             this.SourceUrl     = Url;
             this.SourceBaseUrl = BaseUrl;
             this.SourcePath    = Path;
             if (Server.Options.UrlIgnoreCase)
             {
                 Url = routeMatchResult.RewriteUrlLower;
             }
             else
             {
                 Url = routeMatchResult.RewriteUrl;
             }
             if (Server.Options.AgentRewrite)
             {
                 if (len > 0 && this.SourceUrl.Length > len + 1)
                 {
                     if (Url.IndexOf('?') > 0)
                     {
                         Url += "&";
                     }
                     else
                     {
                         Url += "?";
                     }
                     Url += new string(SourceUrl.AsSpan().Slice(len + 1));
                 }
             }
             len = HttpParse.ReadUrlQueryString(Url, null, this);
             if (len > 0)
             {
                 HttpParse.ReadUrlPathAndExt(Url.AsSpan().Slice(0, len), mQueryString, this, this.Server.Options);
             }
             else
             {
                 HttpParse.ReadUrlPathAndExt(Url.AsSpan(), mQueryString, this, this.Server.Options);
             }
             if (Server.EnableLog(EventArgs.LogType.Info))
             {
                 Server.BaseServer.Log(EventArgs.LogType.Info, Session, $"HTTP {ID} {((IPEndPoint)Session.RemoteEndPoint).Address} request {SourceUrl} rewrite to {Url}");
             }
         }
         mState = LoadedState.Method;
     }
 }