private bool ParseRequestForHeaders()
 {
     int num;
     int num2;
     int num3;
     if ((this.m_requestData == null) || (this.iEntityBodyOffset < 4))
     {
         return false;
     }
     this.m_headers = new HTTPRequestHeaders(Config.HeaderEncoding);
     byte[] arrRequest = this.m_requestData.GetBuffer();
     Parser.CrackRequestLine(arrRequest, out num2, out num3, out num);
     if ((num2 < 1) || (num3 < 1))
     {
         return false;
     }
     this.m_headers.HTTPMethod = Encoding.ASCII.GetString(arrRequest, 0, num2 - 1).ToUpper();
     this.m_headers.HTTPVersion = Encoding.ASCII.GetString(arrRequest, (num2 + num3) + 1, ((num - num3) - num2) - 2).Trim().ToUpper();
     int num4 = 0;
     if (arrRequest[num2] != 0x2f)
     {
         if (((num3 > 7) && (arrRequest[num2 + 4] == 0x3a)) && ((arrRequest[num2 + 5] == 0x2f) && (arrRequest[num2 + 6] == 0x2f)))
         {
             this.m_headers.UriScheme = Encoding.ASCII.GetString(arrRequest, num2, 4);
             num4 = num2 + 6;
             num2 += 7;
             num3 -= 7;
         }
         else if (((num3 > 8) && (arrRequest[num2 + 5] == 0x3a)) && ((arrRequest[num2 + 6] == 0x2f) && (arrRequest[num2 + 7] == 0x2f)))
         {
             this.m_headers.UriScheme = Encoding.ASCII.GetString(arrRequest, num2, 5);
             num4 = num2 + 7;
             num2 += 8;
             num3 -= 8;
         }
         else if (((num3 > 6) && (arrRequest[num2 + 3] == 0x3a)) && ((arrRequest[num2 + 4] == 0x2f) && (arrRequest[num2 + 5] == 0x2f)))
         {
             this.m_headers.UriScheme = Encoding.ASCII.GetString(arrRequest, num2, 3);
             num4 = num2 + 5;
             num2 += 6;
             num3 -= 6;
         }
     }
     if (num4 == 0)
     {
         if ((this.ClientPipe != null) && this.ClientPipe.IsSecured)
         {
             this.m_headers.UriScheme = "https";
         }
         else
         {
             this.m_headers.UriScheme = "http";
         }
     }
     if (num4 > 0)
     {
         while (((num3 > 0) && (arrRequest[num2] != 0x2f)) && (arrRequest[num2] != 0x3f))
         {
             num2++;
             num3--;
         }
         if (num3 == 0)
         {
             num2 = num4;
             num3 = 1;
         }
         int index = num4 + 1;
         int count = num2 - index;
         if (count > 0)
         {
             this.m_sHostFromURI = Config.HeaderEncoding.GetString(arrRequest, index, count);
             if ((this.m_headers.UriScheme == "ftp") && this.m_sHostFromURI.Contains("@"))
             {
                 int length = this.m_sHostFromURI.LastIndexOf("@") + 1;
                 this.m_headers._uriUserInfo = this.m_sHostFromURI.Substring(0, length);
                 this.m_sHostFromURI = this.m_sHostFromURI.Substring(length);
             }
         }
     }
     byte[] dst = new byte[num3];
     Buffer.BlockCopy(arrRequest, num2, dst, 0, num3);
     this.m_headers.RawPath = dst;
     string str = Config.HeaderEncoding.GetString(arrRequest, num, this.iEntityBodyOffset - num).Trim();
     arrRequest = null;
     if (str.Length >= 1)
     {
         string[] sHeaderLines = str.Replace("\r\n", "\n").Split(new char[] { '\n' });
         string sErrors = string.Empty;
         if (!Parser.ParseNVPHeaders(this.m_headers, sHeaderLines, 0, ref sErrors))
         {
         }
     }
     return true;
 }
示例#2
0
 public static HTTPRequestHeaders ParseRequest(string sRequest)
 {
     HTTPRequestHeaders oHeaders = new HTTPRequestHeaders(Config.HeaderEncoding);
     string[] sHeaderLines = sRequest.Substring(0, sRequest.IndexOf("\r\n\r\n", StringComparison.Ordinal)).Replace("\r\n", "\n").Split(new char[] { '\n' });
     if (sHeaderLines.Length >= 1)
     {
         int index = sHeaderLines[0].IndexOf(' ');
         if (index > 0)
         {
             oHeaders.HTTPMethod = sHeaderLines[0].Substring(0, index).ToUpper();
             sHeaderLines[0] = sHeaderLines[0].Substring(index).Trim();
         }
         index = sHeaderLines[0].LastIndexOf(' ');
         if (index > 0)
         {
             oHeaders.RequestPath = sHeaderLines[0].Substring(0, index);
             oHeaders.HTTPVersion = sHeaderLines[0].Substring(index).Trim().ToUpper();
             if (oHeaders.RequestPath.StartsWith("http://", StringComparison.OrdinalIgnoreCase))
             {
                 oHeaders.UriScheme = "http";
                 index = oHeaders.RequestPath.IndexOfAny(new char[] { '/', '?' }, 7);
                 if (index == -1)
                 {
                     oHeaders.RequestPath = "/";
                 }
                 else
                 {
                     oHeaders.RequestPath = oHeaders.RequestPath.Substring(index);
                 }
             }
             else if (oHeaders.RequestPath.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
             {
                 oHeaders.UriScheme = "https";
                 index = oHeaders.RequestPath.IndexOfAny(new char[] { '/', '?' }, 8);
                 if (index == -1)
                 {
                     oHeaders.RequestPath = "/";
                 }
                 else
                 {
                     oHeaders.RequestPath = oHeaders.RequestPath.Substring(index);
                 }
             }
             else if (oHeaders.RequestPath.StartsWith("ftp://", StringComparison.OrdinalIgnoreCase))
             {
                 oHeaders.UriScheme = "ftp";
                 index = oHeaders.RequestPath.IndexOf('/', 6);
                 if (index == -1)
                 {
                     oHeaders.RequestPath = "/";
                 }
                 else
                 {
                     oHeaders.RequestPath = oHeaders.RequestPath.Substring(index);
                 }
             }
             string sErrors = string.Empty;
             ParseNVPHeaders(oHeaders, sHeaderLines, 1, ref sErrors);
             return oHeaders;
         }
     }
     return null;
 }
 private bool isRequestComplete()
 {
     if (this.m_headers == null)
     {
         if (!this.HeadersAvailable())
         {
             return false;
         }
         if (!this.ParseRequestForHeaders())
         {
             string str;
             if (this.m_requestData != null)
             {
                 str = Utilities.ByteArrayToHexView(this.m_requestData.GetBuffer(), 0x18, (int) Math.Min(this.m_requestData.Length, 0x800L));
             }
             else
             {
                 str = "{JrIntercepter:no data}";
             }
             if (this.m_headers == null)
             {
                 this.m_headers = new HTTPRequestHeaders();
                 this.m_headers.HTTPMethod = "BAD";
                 this.m_headers["Host"] = "BAD-REQUEST";
                 this.m_headers.RequestPath = "/BAD_REQUEST";
             }
             this.FailSession(400, "JrIntercepter - Bad Request", "[JrIntercepter] Request Header parsing failed. Request was:\n" + str);
             return true;
         }
         this.m_session.AssignID();
     }
     if (this.m_headers.ExistsAndEquals("Transfer-encoding", "chunked"))
     {
         long num;
         long num2;
         return Utilities.IsChunkedBodyComplete(this.m_session, this.m_requestData, (long) this.iEntityBodyOffset, out num2, out num);
     }
     if (this.m_headers.Exists("Content-Length"))
     {
         long result = 0L;
         try
         {
             if (!long.TryParse(this.m_headers["Content-Length"], NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out result) || (result < 0L))
             {
                 this.FailSession(400, "JrIntercepter - Bad Request", "[JrIntercepter] Request Content-Length header parsing failed.\nContent-Length: " + this.m_headers["Content-Length"]);
                 return true;
             }
             return (this.m_requestData.Length >= (this.iEntityBodyOffset + result));
         }
         catch
         {
             this.FailSession(400, "JrIntercepter - Bad Request", "[JrIntercepter] Unknown error: Check content length header?");
             return false;
         }
     }
     return true;
 }