Пример #1
0
        public void AddField(string text)
        {
            HttpField field = new HttpField();

            field.Parse(text);
            Fields.Add(field.Name, field);
        }
Пример #2
0
        void IHttpMessage.AddField(HttpField field)
        {
            switch (field.Name)
            {
            case HttpConst.ContentType:
                ContentType = field.Value;
                break;

            case HttpConst.ContentLength:
                ContentLength = int.Parse(field.Value);
                break;

            case HttpConst.Server:
                Server = field.Value;
                break;

            case HttpConst.Location:
                Location = field.Value;
                break;

            case HttpConst.TransferEncoding:
                TransferEncoding = (TransferEncodings)Enum.Parse(
                    typeof(TransferEncodings),
                    field.Value, true);
                break;

            default:
                break;
            }

            Head.AddField(field);
        }
Пример #3
0
        public void CreateStream()
        {
            if (ContentStream == null)
            {
                HttpField field = Fields[HttpConst.ContentDisposition];

                if (field != null)
                {
                    HttpParameter param = field.Parameters["filename"];

                    if (param == null)
                    {
                        ContentStream = (Stream) new MemoryStream();
                    }
                    else
                    {
                        FileStream tmp = new FileStream(Path.GetTempFileName(),
                                                        FileMode.OpenOrCreate);
                        ContentStream = (Stream)tmp;
                        IsFile        = true;

                        File =
                            new FileAttached(param.Value,
                                             Fields[HttpConst.ContentType].Value,
                                             tmp.Name);
                    }
                }
                else
                {
                    ContentStream = (Stream) new MemoryStream();
                }
            }
        }
Пример #4
0
        public void AddField(HttpField field)
        {
            var tmp = Fields[field.Name];

            if (tmp != null)
            {
                Fields[field.Name] += field.Value;
            }
            else
            {
                Fields.Add(field.Name, field);
            }
        }
 void ParseField(string lineData)
 {
     try
     {
         if (firstField)
         {
             ParseFirstField(lineData);
             firstField = false;
         }
         else
         {
             HttpField field = new HttpField();
             field.Parse(lineData);
             currentMessage.AddField(field);
         }
     }
     catch (Exception err)
     {
         throw new BadHttpException(lineData, err);
     }
 }
        void ParseLineMultipart(byte[] lineBytes)
        {
            string line = currentMessage.ContentTransferEncoding.GetString(lineBytes, 0, lineBytes.Length - 2);

            if (line == currentMessage.GetBoundaryStart())
            {
                if (currentBodyMultipart != null)
                {
                    AddCurrentBodyToRequest(lineBytes.Length + 2);
                }

                currentBodyMultipart       = currentMessage.CreateBody();
                currentBodyMultipart.state = 0;
            }
            else if (line == currentMessage.GetBoundaryEnd())
            {
                if (currentBodyMultipart != null)
                {
                    AddCurrentBodyToRequest(lineBytes.Length + 2);
                }

                // currentBodyMultipart.streamContent.Se

                // currentMessage.Body.IsCompleted = true;
                currentMessage.IsCompleted = true;
                firstField  = true;
                pendingHead = true;
            }
            else if (line == "" && currentBodyMultipart.state == 0)
            {
                currentBodyMultipart.state = 1;
            }
            else if (line != "" && currentBodyMultipart.state == 0)
            {
                HttpField field = new HttpField();
                field.Parse(line);

                currentBodyMultipart.Fields.Add(field.Name, field);
            }
        }
Пример #7
0
        public void AddField(HttpField field)
        {
            switch (field.Name)
            {
            case HttpConst.Host:
                Host = field.Value;
                break;

            case HttpConst.Accept:
                Accept.AddRange(field.Values);
                break;

            case HttpConst.AcceptLanguage:
                AcceptLanguage.AddRange(field.Values);
                break;

            case HttpConst.AcceptEncoding:
                AcceptEncoding.AddRange(field.Values);
                break;

            case HttpConst.AcceptCharset:
                AcceptCharset.AddRange(field.Values);

                if (AcceptCharset.Count > 0)
                {
                    ContentTransferEncoding = Encoding.GetEncoding(AcceptCharset[0]);
                }
                break;

            case HttpConst.KeepAlive:
                KeepAlive = field.Value;
                break;

            case HttpConst.Connection:
                Connection = field.Value;
                break;

            case HttpConst.UserAgent:
                UserAgent = field.RawValue;
                break;

            case HttpConst.Referer:
                Referer = field.Value;
                break;

            case HttpConst.Cookie:
                Cookie = field.Value;
                break;

            case HttpConst.IfUnmodifiedSince:
                // lastModified = HtmlTime.TimeHtml2Date(value);
                break;

            case HttpConst.IfModifiedSince:
                // se pueden recibir varios parametros "If-Modified-Since: Tue, 10 Oct 2006 13:16:15 GMT; length=13757"
                IfModifiedSince = HttpTime.TimeHtml2Date(field.RawValue);
                break;

            case HttpConst.IfNoneMatch:
                break;

            case HttpConst.ContentType:
                ContentType = field.Value;
                break;

            case HttpConst.ContentLength:
                ContentLength = int.Parse(field.Value);
                break;

            case HttpConst.ContentTransferEncoding:
                ContentTransferEncoding = Encoding.GetEncoding(field.Value);
                break;

            case HttpConst.Authorization:
                ParserUserAndPassword(field.Value);
                break;

            default:
                // currentRequest.RestHeaders.Add(tag.ToLower(), field);
                // Head.Fields.Add(field.Name, field);
                break;
            }

            Head.Fields.Add(field.Name, field);
        }
Пример #8
0
        public string GetParameter(string name, string param)
        {
            HttpField field = GetField(name);

            return(field != null?field.GetParameter(param) : null);
        }