Пример #1
0
 public static CrossDictionary <string, string> Create()
 {
     return(new CrossDictionary <string, string>(
                DictionaryTools.Create <string>(),
                DictionaryTools.Create <string>()
                ));
 }
Пример #2
0
 public StringIndexOf(string str)
 {
     for (int index = str.Length - 1; 0 <= index; index--)
     {
         DictionaryTools.Put(_map, str[index], index);
     }
 }
Пример #3
0
        public void Send(byte[] body, string method)
        {
            Hwr.Method = method;

            if (body != null)
            {
                using (Stream w = Hwr.GetRequestStream())
                {
                    w.Write(body, 0, body.Length);
                }
            }
            WebResponse res = Hwr.GetResponse();

            ResHeaders = DictionaryTools.CreateIgnoreCase <string>();

            foreach (string name in res.Headers.Keys)
            {
                ResHeaders.Add(name, res.Headers[name]);
            }

            using (Stream r = res.GetResponseStream())
            {
                ResBody = FileTools.ReadToEnd(r, this.ResBodySizeMax);
            }
        }
Пример #4
0
        private void CheckHeaderFields()
        {
            String sConLen = DictionaryTools.Get(_headerFields, "Content-Length", null);
            String sTrnEnc = DictionaryTools.Get(_headerFields, "Transfer-Encoding", null);

            if (sConLen != null)
            {
                _contentLength = int.Parse(sConLen);
            }
            if (sTrnEnc != null)
            {
                sTrnEnc = sTrnEnc.ToLower();

                if (sTrnEnc.Contains("chunked"))
                {
                    _chunked = true;
                }
            }
        }
Пример #5
0
 public void Put(K key, V value)
 {
     DictionaryTools.Put(_kv, key, value);
     DictionaryTools.Put(_vk, value, key);
 }
Пример #6
0
        public void send(byte[] body, string method)
        {
            DateTime startedTime = DateTime.Now;
            TimeSpan timeoutSpan = TimeSpan.FromMilliseconds(timeoutMillis);

            _hwr.Method = method;

            if (body != null)
            {
                _hwr.ContentLength = body.Length;

                using (Stream w = _hwr.GetRequestStream())
                {
                    w.Write(body, 0, body.Length);
                    w.Flush();
                }
            }
            using (WebResponse res = _hwr.GetResponse())
            {
                resHeaders = DictionaryTools.createIgnoreCase <string>();

                // header
                {
                    const int LEN_MAX  = 500000;                    // 500 KB
                    const int WEIGHT   = 10;
                    int       totalLen = 0;

                    foreach (string name in res.Headers.Keys)
                    {
                        if (LEN_MAX < name.Length)
                        {
                            throw new Exception("Response header too large. n");
                        }

                        totalLen += name.Length + WEIGHT;

                        if (LEN_MAX < totalLen)
                        {
                            throw new Exception("Response header too large. t1");
                        }

                        string value = res.Headers[name];

                        if (LEN_MAX < value.Length)
                        {
                            throw new Exception("Response header too large. v");
                        }

                        totalLen += value.Length + WEIGHT;

                        if (LEN_MAX < totalLen)
                        {
                            throw new Exception("Response header too large. t2");
                        }

                        resHeaders.Add(name, res.Headers[name]);
                    }
                }

                // body
                {
                    int totalSize = 0;

                    using (Stream r = res.GetResponseStream())
                        using (MemoryStream w = new MemoryStream())
                        {
                            r.ReadTimeout = noTrafficTimeoutMillis;               // この時間経過すると r.Read() が例外を投げる。

                            byte[] buff = new byte[20000000];                     // 20 MB

                            for (; ;)
                            {
                                int readSize = r.Read(buff, 0, buff.Length);

                                if (readSize <= 0)
                                {
                                    break;
                                }

                                if (timeoutSpan < DateTime.Now - startedTime)
                                {
                                    throw new Exception("Response timed out");
                                }

                                totalSize += readSize;

                                if (resBodySizeMax < totalSize)
                                {
                                    throw new Exception("Response body too large.");
                                }

                                w.Write(buff, 0, readSize);
                            }
                            resBody = w.ToArray();
                        }
                }
            }
        }
Пример #7
0
 public int IndexOf(char chr)
 {
     return(DictionaryTools.Get(_map, chr, -1));
 }