private void SetAuthChallenge(StringCollection header, string fieldName, IEnumerable authChallenge)
 {
     if (authChallenge != null)
     {
         foreach (string str in authChallenge)
         {
             HeaderFieldList.AddHeaderField(header, fieldName, str);
         }
     }
 }
Beispiel #2
0
        protected virtual void AssignContentType(StringCollection header)
        {
            string contentType = this.ContentType;

            if (!StringUtils.IsEmpty(contentType))
            {
                contentType = AddHttpFieldItem(AddHttpFieldItem(contentType, "boundary", this.Boundary), "charset", this.CharSet);
                HeaderFieldList.AddHeaderField(header, "Content-Type", contentType);
            }
        }
Beispiel #3
0
 protected override void InternalAssignHeader(StringCollection header)
 {
     HeaderFieldList.AddHeaderField(header, "Accept", this.Accept);
     HeaderFieldList.AddHeaderField(header, "Accept-Charset", this.AcceptCharSet);
     HeaderFieldList.AddHeaderField(header, "Accept-Encoding", this.AcceptEncoding);
     HeaderFieldList.AddHeaderField(header, "Accept-Language", this.AcceptLanguage);
     HeaderFieldList.AddHeaderField(header, "Range", this.Range);
     HeaderFieldList.AddHeaderField(header, "Referer", this.Referer);
     HeaderFieldList.AddHeaderField(header, "Host", this.Host);
     HeaderFieldList.AddHeaderField(header, "User-Agent", this.UserAgent);
     HeaderFieldList.AddHeaderField(header, "Authorization", this.Authorization);
     HeaderFieldList.AddHeaderField(header, "Proxy-Authorization", this.ProxyAuthorization);
     base.InternalAssignHeader(header);
 }
 protected override void InternalAssignHeader(StringCollection header)
 {
     HeaderFieldList.AddHeaderField(header, "Allow", this.Allow);
     HeaderFieldList.AddHeaderField(header, "Accept-Ranges", this.AcceptRanges);
     HeaderFieldList.AddHeaderField(header, "Age", this.Age);
     HeaderFieldList.AddHeaderField(header, "Content-Range", this.ContentRange);
     HeaderFieldList.AddHeaderField(header, "ETag", this.ETag);
     HeaderFieldList.AddHeaderField(header, "Location", this.Location);
     HeaderFieldList.AddHeaderField(header, "Retry-After", this.RetryAfter);
     HeaderFieldList.AddHeaderField(header, "Server", this.Server);
     this.SetAuthChallenge(header, "WWW-Authenticate", this.Authenticate);
     this.SetAuthChallenge(header, "Proxy-Authenticate", this.ProxyAuthenticate);
     base.InternalAssignHeader(header);
 }
Beispiel #5
0
        public void SetRequestCookies(StringCollection requestHeader)
        {
            this.RemoveCookies(requestHeader);
            string str = "";

            foreach (CookieItem item in this)
            {
                str = str + this.BuildRequestCookie(item) + "; ";
            }
            if (!StringUtils.IsEmpty(str))
            {
                str = str.Substring(0, str.Length - "; ".Length);
            }
            HeaderFieldList.AddHeaderField(requestHeader, "Cookie", str);
        }
Beispiel #6
0
 protected virtual void InternalAssignHeader(StringCollection header)
 {
     HeaderFieldList.AddHeaderField(header, "Content-Encoding", this.ContentEncoding);
     HeaderFieldList.AddHeaderField(header, "Content-Language", this.ContentLanguage);
     HeaderFieldList.AddHeaderField(header, "Content-Length", this.ContentLength);
     HeaderFieldList.AddHeaderField(header, "Content-Version", this.ContentVersion);
     this.AssignContentType(header);
     HeaderFieldList.AddHeaderField(header, "Date", this.Date);
     HeaderFieldList.AddHeaderField(header, "Expires", this.Expires);
     HeaderFieldList.AddHeaderField(header, "LastModified", this.LastModified);
     HeaderFieldList.AddHeaderField(header, "Transfer-Encoding", this.TransferEncoding);
     HeaderFieldList.AddHeaderField(header, "Cache-Control", this.CacheControl);
     HeaderFieldList.AddHeaderField(header, "Connection", this.Connection);
     HeaderFieldList.AddHeaderField(header, "Proxy-Connection", this.ProxyConnection);
     if (this.ExtraFields != null)
     {
         header.AddRange(this.ExtraFields);
     }
 }
Beispiel #7
0
        private void PrepareRequestHeader(HttpTunnelStatus tunnelStatus, StringCollection requestHeader,
                                          Stream requestBody)
        {
            string str2;

            RemoveRequestLine(requestHeader);
            RemoveHeaderTrailer(requestHeader);
            string absolutePath = Url.AbsolutePath;

            if (IsUseProxy())
            {
                switch (tunnelStatus)
                {
                case HttpTunnelStatus.None:
                    absolutePath = Url.AbsoluteUri;
                    break;

                case HttpTunnelStatus.Connect:
                    absolutePath = string.Format("{0}:{1}", Url.Host, Url.Port);
                    break;
                }
            }
            if (StringUtils.IsEmpty(absolutePath))
            {
                absolutePath = "/";
            }
            requestHeader.Insert(0, string.Format("{0} {1} {2}", method, absolutePath, httpVersions[(int)HttpVersion]));
            var fieldList = new HeaderFieldList();

            HeaderFieldList.GetHeaderFieldList(0, requestHeader, fieldList);
            HeaderFieldList.RemoveHeaderField(requestHeader, fieldList, "Host");
            fieldList.Clear();
            HeaderFieldList.GetHeaderFieldList(0, requestHeader, fieldList);
            if (AllowCompression &&
                StringUtils.IsEmpty(HeaderFieldList.GetHeaderFieldValue(requestHeader, fieldList, "Accept-Encoding")))
            {
                HeaderFieldList.AddHeaderField(requestHeader, "Accept-Encoding", "gzip, deflate");
            }
            if (!StringUtils.IsEmpty(Url.Host))
            {
                str2 = Url.Host + GetPortIfNeed(Url.Port);
            }
            else
            {
                str2 = base.Server + GetPortIfNeed(base.Port);
            }
            HeaderFieldList.AddHeaderField(requestHeader, "Host", str2);
            if (StringUtils.IsEmpty(HeaderFieldList.GetHeaderFieldValue(requestHeader, fieldList, "User-Agent")))
            {
                HeaderFieldList.AddHeaderField(requestHeader, "User-Agent", UserAgent);
            }
            string val = HeaderFieldList.GetHeaderFieldValue(requestHeader, fieldList, "Content-Length");

            if (requestBody.Length == 0L)
            {
                HeaderFieldList.RemoveHeaderField(requestHeader, fieldList, "Content-Length");
                fieldList.Clear();
                HeaderFieldList.GetHeaderFieldList(0, requestHeader, fieldList);
                HeaderFieldList.RemoveHeaderField(requestHeader, fieldList, "Content-Type");
                fieldList.Clear();
                HeaderFieldList.GetHeaderFieldList(0, requestHeader, fieldList);
            }
            else if (StringUtils.IsEmpty(val) &&
                     ((tunnelStatus == HttpTunnelStatus.Connect) || (requestBody.Length > 0L)))
            {
                HeaderFieldList.AddHeaderField(requestHeader, "Content-Length", requestBody.Length.ToString());
            }
            if (!AllowCaching &&
                StringUtils.IsEmpty(HeaderFieldList.GetHeaderFieldValue(requestHeader, fieldList,
                                                                        cacheFields[(int)HttpVersion])))
            {
                HeaderFieldList.AddHeaderField(requestHeader, cacheFields[(int)HttpVersion], "no-cache");
            }
            if (KeepConnection &&
                StringUtils.IsEmpty(HeaderFieldList.GetHeaderFieldValue(requestHeader, fieldList,
                                                                        connFields[IsUseProxy() ? 1 : 0])))
            {
                HeaderFieldList.AddHeaderField(requestHeader, connFields[IsUseProxy() ? 1 : 0], "Keep-Alive");
            }
            if (AllowCookies)
            {
                Cookies.SetRequestCookies(requestHeader);
            }
            requestHeader.Add("");
        }