Exemple #1
0
 private void Initialize()
 {
     RequestLine.Clear();
     HeaderList.Clear();
     MessageBody = null;
     c           = TextStore.ReadChar();
 }
Exemple #2
0
 private void Initialize(HttpMethod method)
 {
     Method = method;
     StatusLine.Clear();
     HeaderList.Clear();
     MessageBody = null;
     c           = TextStore.ReadChar();
 }
Exemple #3
0
        public void TestReplacingHeaders()
        {
            const string ReplacedContentType        = "text/plain; charset=iso-8859-1; name=body.txt";
            const string ReplacedContentDisposition = "inline; filename=body.txt";
            const string ReplacedContentLocation    = "http://www.example.com/location";
            const string ReplacedContentId          = "<content.id.2@localhost>";
            var          headers = new HeaderList();

            headers.Add(HeaderId.ContentId, "<content-id.1@localhost>");
            headers.Add("Content-Location", "http://www.location.com");
            headers.Insert(0, HeaderId.ContentDisposition, "attachment");
            headers.Insert(0, "Content-Type", "text/plain");

            Assert.IsTrue(headers.Contains(HeaderId.ContentType), "Expected the list of headers to contain HeaderId.ContentType.");
            Assert.IsTrue(headers.Contains("Content-Type"), "Expected the list of headers to contain a Content-Type header.");
            Assert.AreEqual(0, headers.LastIndexOf(HeaderId.ContentType), "Expected the Content-Type header to be the first header.");

            headers.Replace("Content-Disposition", ReplacedContentDisposition);
            Assert.AreEqual(4, headers.Count, "Unexpected number of headers after replacing Content-Disposition.");
            Assert.AreEqual(ReplacedContentDisposition, headers["Content-Disposition"], "Content-Disposition has unexpected value after replacing it.");
            Assert.AreEqual(1, headers.IndexOf("Content-Disposition"), "Replaced Content-Disposition not in the expected position.");

            headers.Replace(HeaderId.ContentType, ReplacedContentType);
            Assert.AreEqual(4, headers.Count, "Unexpected number of headers after replacing Content-Type.");
            Assert.AreEqual(ReplacedContentType, headers["Content-Type"], "Content-Type has unexpected value after replacing it.");
            Assert.AreEqual(0, headers.IndexOf("Content-Type"), "Replaced Content-Type not in the expected position.");

            headers.Replace(HeaderId.ContentId, Encoding.UTF8, ReplacedContentId);
            Assert.AreEqual(4, headers.Count, "Unexpected number of headers after replacing Content-Id.");
            Assert.AreEqual(ReplacedContentId, headers["Content-Id"], "Content-Id has unexpected value after replacing it.");
            Assert.AreEqual(2, headers.IndexOf("Content-Id"), "Replaced Content-Id not in the expected position.");

            headers.Replace("Content-Location", Encoding.UTF8, ReplacedContentLocation);
            Assert.AreEqual(4, headers.Count, "Unexpected number of headers after replacing Content-Location.");
            Assert.AreEqual(ReplacedContentLocation, headers["Content-Location"], "Content-Location has unexpected value after replacing it.");
            Assert.AreEqual(3, headers.IndexOf("Content-Location"), "Replaced Content-Location not in the expected position.");

            headers.RemoveAll("Content-Location");
            Assert.AreEqual(3, headers.Count, "Unexpected number of headers after removing Content-Location.");

            headers.Clear();

            headers.Add(HeaderId.Received, "received 1");
            headers.Add(HeaderId.Received, "received 2");
            headers.Add(HeaderId.Received, "received 3");
            headers.Add(HeaderId.ReturnPath, "return-path");

            headers[0] = new Header(HeaderId.ReturnPath, "new return-path");
            Assert.AreEqual("new return-path", headers[HeaderId.ReturnPath]);
            headers[0] = new Header(HeaderId.Received, "new received");
            Assert.AreEqual("new received", headers[HeaderId.Received]);
        }
		protected virtual void DoSetHeaders() {
			_RawHeaders.Clear();
			if (_Connection.Length > 0) {
				_RawHeaders.Values("Connection", _Connection);
			}
			if (_ContentVersion.Length > 0) {
				_RawHeaders.Values("Content-Version", _ContentVersion);
			}
			if (_ContentEncoding.Length > 0) {
				_RawHeaders.Values("Content-Encoding", _ContentEncoding);
			}
			if (_ContentLanguage.Length > 0) {
				_RawHeaders.Values("Content-Language", _ContentLanguage);
			}
			if (_ContentType.Length > 0) {
				_RawHeaders.Values("Content-Type", _ContentType);
			}
			if (_ContentLength >= 0) {
				_RawHeaders.Values("Content-Length", _ContentLength.ToString());
			}
			if (_CacheControl.Length > 0) {
				_RawHeaders.Values("Cache-control", _CacheControl);
			}
			if (_Date > DateTime.MinValue) {
				_RawHeaders.Values("Date", Http.DateTimeGmtToHttpStr(_Date));
			}
			if (_Expires > DateTime.MinValue) {
				_RawHeaders.Values("Expires", Http.DateTimeGmtToHttpStr(_Expires));
			}
			if (_Pragma.Length > 0) {
				_RawHeaders.Values("Pragma", _Pragma);
            }
#warning _CustomHeaders 
            //if (_CustomHeaders.Count > 0) {
            //    _RawHeaders.Text += string.IsNullOrEmpty(_RawHeaders.Text) ? string.Empty : "\r\n" + 
            //        _CustomHeaders.Text;
            //}
		}
		public virtual void Clear() {
			_Connection = "close";
			_ContentVersion = "";
			_ContentEncoding = "";
			_ContentLanguage = "";
			_ContentType = "";
			_ContentLength = -1;
			_ContentRangeStart = 0;
			_ContentRangeEnd = 0;
			_Date = new DateTime(0);
			_LastModified = new DateTime(0);
			_Expires = new DateTime(0);
			if (_RawHeaders != null) {
				_RawHeaders.Clear();
			}
			if (_CustomHeaders != null) {
				_CustomHeaders.Clear();
			}
		}
        protected override void DoProcessHeaders()
        {
            base.DoProcessHeaders();
            _Location        = _RawHeaders.Values("Location");
            _Server          = _RawHeaders.Values("Server");
            _ProxyConnection = _RawHeaders.Values("Server");
            string RangeDecode = _RawHeaders.Values("Content-Range");

            if (RangeDecode != "")
            {
                Genetibase.Network.Sockets.Global.Fetch(ref RangeDecode);
                _ContentRangeStart = Int32.Parse(Genetibase.Network.Sockets.Global.Fetch(ref RangeDecode, "-"));
                _ContentRangeEnd   = Int32.Parse(Genetibase.Network.Sockets.Global.Fetch(ref RangeDecode, "/"));
            }
            _ContentRangeStart = 0;
            _ContentRangeEnd   = 0;
            _WWWAuthenticate.Clear();
            _RawHeaders.Extract("WWW-Authenticate", _WWWAuthenticate);
            _ProxyAuthenticate.Clear();
            _RawHeaders.Extract("Proxy-Authenticate", _ProxyAuthenticate);
        }