示例#1
0
 public CoreResponseData(StatusLineValues values, HttpResponseHeaders headers,Stream connectStream)
 {
     this.StatusCode = (HttpStatusCode)values.StatusCode;
     this.StatusDescription = values.StatusDescription;
     this.ContentLength = values.ContentLength;
     if (values.MajorVersion == 1 && values.MinorVersion == 1)
     {
         this.HttpVersion = HttpVersion.HTTP11;
     }
     else if (values.MajorVersion == 2 && values.MinorVersion == 0)
     {
         this.HttpVersion = HttpVersion.HTTP20;
     }
     this.ResponseHeaders = headers;
     this.ConnectStream = connectStream;
 }
示例#2
0
 private DataParseStatus ParseResponseData(ArraySegment<byte> data, ref int bytesScanned, ref bool requestDone)
 {
     var result = DataParseStatus.NeedMoreData;
     requestDone = false;
     switch (_readState)
     {
         case ReadState.Start:
             {                       
                 _readState = ReadState.StatusLine;
                 _statusState = BeforeVersionNumbers;
                 _totalResponseHeadersLength = 0;
                 _statusLineValues = new StatusLineValues()
                 {
                     MajorVersion = 0,
                     MinorVersion = 0,
                     StatusCode = 0,
                     StatusDescription = ""
                 };
                 goto case ReadState.StatusLine;
             }
         case ReadState.StatusLine:
             {
                 var parseStatus = this.ParseStatusLine(data, ref bytesScanned);
                 if (parseStatus == DataParseStatus.Done)
                 {
                     _readState = ReadState.Headers;
                     _responseHeaders = new HttpResponseHeaders();
                     goto case ReadState.Headers;
                 }
                 else if (parseStatus != DataParseStatus.NeedMoreData)
                 {
                     result = parseStatus;
                     break;
                 }
                 break;
             }
         case ReadState.Headers:
             {
                 if (bytesScanned >= data.Count)
                 {
                     //need more data
                     break;
                 }
                 var parseStatus = _responseHeaders.ParseHeaders(data, ref bytesScanned, ref _totalResponseHeadersLength, _maximumResponseHeadersLength);
                 if (parseStatus == DataParseStatus.Invalid || parseStatus == DataParseStatus.DataTooBig)
                 {
                     result = parseStatus;
                     break;
                 }                            
                 else if (parseStatus == DataParseStatus.Done)
                 {
                     //if StatusCode  is BadRequest or Continue                            
                     goto case ReadState.Data;
                 }
                 break;
             }
         case ReadState.Data:
             {
                 requestDone = true;
                 result = DataParseStatus.Done;
                 break;
             }
     }
     return result;
 }