示例#1
0
        public static HeaderType Find(string name)
        {
            HeaderType type;
            long       id = HeaderType.GetNameCode(name);

            if (mHeaderTypes.TryGetValue(id, out type))
            {
                return(type);
            }
            HeaderType[] items;
            lock (mHeaderTypes)
            {
                if (mHeaderTypes.TryGetValue(id, out type))
                {
                    return(type);
                }
                items = mHeaderTypes.Values.ToArray();
                foreach (var item in items)
                {
                    if (item.Compare(name))
                    {
                        type = item;
                    }
                }
            }
            if (type == null)
            {
                type = new HeaderType(name);
            }
            Add(name, type);
            return(type);
        }
示例#2
0
 private static void Add(String name)
 {
     lock (mHeaderTypes)
     {
         HeaderType type = new HeaderType(name);
         mHeaderTypes[type.ID] = type;
     }
 }
示例#3
0
        private HeaderValue FindOnly(string name)
        {
            HeaderValue result;
            long        id = HeaderType.GetNameCode(name);

            mValues.TryGetValue(id, out result);
            return(result);
        }
示例#4
0
 private static void Add(String name)
 {
     if (Find(name) == null)
     {
         HeaderType type = new HeaderType(name);
         mTypes[type.Index].Add(type);
     }
 }
示例#5
0
 public void Write(PipeStream stream)
 {
     foreach (string key in mItems.Keys)
     {
         HeaderType.Write(key, stream);
         stream.Write(mItems[key]);
         stream.Write(HeaderType.LINE_BYTES, 0, 2);
     }
 }
示例#6
0
 internal void Write(PipeStream stream)
 {
     foreach (var item in mItems)
     {
         HeaderType.Write(item.Key, stream);
         stream.Write(item.Value);
         stream.Write(HeaderType.LINE_BYTES, 0, 2);
     }
 }
示例#7
0
 private static void Add(string name, HeaderType type)
 {
     if (mCount < 5000)
     {
         lock (mHeaderTypes)
         {
             long id = HeaderType.GetNameCode(name);
             mHeaderTypes[id] = type;
         }
         System.Threading.Interlocked.Increment(ref mCount);
     }
 }
示例#8
0
        private HeaderValue Find(string name)
        {
            HeaderType  type = HeaderTypeFactory.Find(name);
            HeaderValue value;

            if (mValues.TryGetValue(type.ID, out value))
            {
                return(value);
            }
            value            = new HeaderValue(type, null);
            mValues[type.ID] = value;
            return(value);
        }
示例#9
0
        public static void Write(string name, PipeStream stream)
        {
            HeaderType type = Find(name);

            if (type != null)
            {
                stream.Write(type.Bytes);
            }
            else
            {
                stream.Write(name + ": ");
            }
        }
示例#10
0
        internal void Write(PipeStream stream)
        {
            stream.Write(HttpVersion);
            stream.Write(HeaderType.SPACE_BYTES[0]);
            stream.Write(mCode);
            stream.Write(HeaderType.SPACE_BYTES[0]);
            stream.Write(CodeMsg);
            stream.Write(HeaderType.LINE_BYTES);
            Header.Write(stream);
            for (int i = 0; i < mSetCookies.Count; i++)
            {
                HeaderType.Write(HeaderType.SET_COOKIE, stream);
                stream.Write(mSetCookies[i]);
                stream.Write(HeaderType.LINE_BYTES);
            }
            if (mBody != null)
            {
                StaticResurce.FileBlock fb = mBody as StaticResurce.FileBlock;
                if (fb != null)
                {
                    stream.Write(HeaderType.LINE_BYTES);
                    fb.Write(stream);
                }
                else
                {
                    MemoryBlockCollection contentLength = stream.Allocate(28);
                    stream.Write(HeaderType.LINE_BYTES);
                    int count = Serializer.Serialize(stream, mBody);
                    contentLength.Full("Content-Length: " + count.ToString().PadRight(10) + "\r\n", stream.Encoding);
                }
            }
            else
            {
                stream.Write(HeaderType.NULL_CONTENT_LENGTH_BYTES);
                stream.Write(HeaderType.LINE_BYTES);
            }

            if (Session.Server.EnableLog(EventArgs.LogType.Debug))
            {
                Session.Server.Log(EventArgs.LogType.Debug, Session, "{0} {1}", Request.ClientIPAddress, this.ToString());
            }

            if (Session.Server.EnableLog(EventArgs.LogType.Info))
            {
                Session.Server.Log(EventArgs.LogType.Info, Session, "{4} {0} {1} response {2} {3}", Request.Method, Request.Url, Code, CodeMsg, Request.ClientIPAddress);
            }
        }
示例#11
0
        public static HeaderType Find(string name)
        {
            HeaderType        type;
            List <HeaderType> headers = mTypes[name.Length % HEADERNAME_MAXLENGTH];

            for (int i = 0; i < headers.Count; i++)
            {
                type = headers[i];
                if (type.Compare(name))
                {
                    return(type);
                }
            }
            if (headers.Count < 20)
            {
                type = new HeaderType(name);
                headers.Add(type);
                return(type);
            }
            return(null);
        }
示例#12
0
        public static HeaderType Find(string name)
        {
            HeaderType type;
            int        id = name.GetHashCode();

            if (mHeaderTypes.TryGetValue(id, out type))
            {
                return(type);
            }
            foreach (var item in mHeaderTypes.Values)
            {
                if (item.Compare(name))
                {
                    Add(name, item);
                    return(item);
                }
            }
            type = new HeaderType(name);
            Add(name, type);
            return(type);
        }
示例#13
0
        private HeaderValue Find(string name)
        {
            HeaderValue result;

            for (int i = 0; i < mValues.Count; i++)
            {
                result = mValues[i];
                if (result.Type.Compare(name))
                {
                    return(result);
                }
            }
            HeaderType type = HeaderTypeFactory.Find(name);

            if (type == null)
            {
                type = new HeaderType(name);
            }
            result = new HeaderValue(type, null);
            mValues.Add(result);
            return(result);
        }
示例#14
0
        public bool Read(PipeStream stream, Cookies cookies)
        {
            IndexOfResult index = stream.IndexOf(HeaderTypeFactory.LINE_BYTES);

            while (index.End != null)
            {
                if (index.Length == 2)
                {
                    stream.ReadFree(2);
                    return(true);
                }
                else
                {
                    ReadOnlySpan <Char> line = HttpParse.ReadCharLine(index);
                    stream.ReadFree(index.Length);
                    if (line[0] == 'C' && line[5] == 'e' && line[1] == 'o' && line[2] == 'o' && line[3] == 'k' && line[4] == 'i')
                    {
                        HttpParse.AnalyzeCookie(line.Slice(8, line.Length - 8), cookies);
                    }
                    else
                    {
                        Tuple <string, string> result = HttpParse.AnalyzeHeader(line);
                        HeaderType             type   = HeaderTypeFactory.Find(result.Item1);
                        if (type == null)
                        {
                            Add(result.Item1, result.Item2);
                        }
                        else
                        {
                            Add(type.Name, result.Item2);
                        }
                    }
                }
                index = stream.IndexOf(HeaderTypeFactory.LINE_BYTES);
            }
            return(false);
        }
示例#15
0
 internal void Write(PipeStream stream)
 {
     stream.Write(HttpVersion);
     stream.Write(HeaderType.SPACE_BYTES[0]);
     stream.Write(mCode);
     stream.Write(HeaderType.SPACE_BYTES[0]);
     stream.Write(CodeMsg);
     stream.Write(HeaderType.LINE_BYTES);
     Header.Write(stream);
     for (int i = 0; i < mSetCookies.Count; i++)
     {
         HeaderType.Write(HeaderType.SET_COOKIE, stream);
         stream.Write(mSetCookies[i]);
         stream.Write(HeaderType.LINE_BYTES);
     }
     if (mBody != null)
     {
         StaticResurce.FileBlock fb = mBody as StaticResurce.FileBlock;
         if (fb != null)
         {
             stream.Write(HeaderType.LINE_BYTES);
             fb.Write(stream);
         }
         else
         {
             MemoryBlockCollection contentLength = stream.Allocate(28);
             stream.Write(HeaderType.LINE_BYTES);
             int count = Serializer.Serialize(stream, mBody);
             contentLength.Full("Content-Length: " + count.ToString().PadRight(10) + "\r\n", stream.Encoding);
         }
     }
     else
     {
         stream.Write(HeaderType.NULL_CONTENT_LENGTH_BYTES);
         stream.Write(HeaderType.LINE_BYTES);
     }
 }
示例#16
0
 public HeaderValue(HeaderType type, string value)
 {
     Type  = type;
     Value = value;
 }
示例#17
0
        public void Remove(string name)
        {
            long id = HeaderType.GetNameCode(name);

            mValues.Remove(id);
        }
示例#18
0
        public static void Write(string name, PipeStream stream)
        {
            HeaderType type = Find(name);

            stream.Write(type.Bytes);
        }