Пример #1
0
        private bool ParseBatchPart(bool isResponse, TextReader reader, InMemoryWebRequest part, string boundary, string endboundary)
        {
            bool   result = false;
            string line;

            if (isResponse)
            {
                part.ParseResponseStatus(reader);
            }
            else
            {
                part.ParseRequestVerb(reader);
            }

            if (isResponse)
            {
                part.ResponseHeaders.Clear();
                InMemoryWebRequest.ParseHeaders(reader, part.ResponseHeaders);
            }
            else
            {
                InMemoryWebRequest.ParseHeaders(reader, part.RequestHeaders);
                InMemoryWebRequest.ApplyHeadersToProperties(part);
            }

            StringBuilder sb       = new StringBuilder();
            string        lastLine = null;

            while ((line = reader.ReadLine()) != null)
            {
                if (line == boundary)
                {
                    break;
                }
                if (line == endboundary)
                {
                    result = true;
                    break;
                }
                if (lastLine != null)
                {
                    sb.AppendLine(lastLine);
                }
                lastLine = line;
            }
            // The last line must not end with a newline - the batch adds it there, but it's not actually part of the content
            sb.Append(lastLine);
            if (isResponse)
            {
                part.SetResponseStream(new MemoryStream(Encoding.UTF8.GetBytes(sb.ToString())));
            }
            else
            {
                part.SetRequestStreamAsText(sb.ToString());
            }
            return(result);
        }
Пример #2
0
        private void ParseResponse(Stream stream)
        {
            MemoryStream memoryStream = new MemoryStream();

            TestUtil.CopyStream(stream, memoryStream);
            memoryStream.Position = 0;
            using (TextReader reader = new StreamReader(memoryStream))
            {
                this.ParseResponseStatus(reader);
                this.ResponseHeaders.Clear();
                InMemoryWebRequest.ParseHeaders(reader, this.ResponseHeaders);
                reader.ReadLine();
                this.SetResponseStream(new MemoryStream(Encoding.UTF8.GetBytes(reader.ReadToEnd())));
            }
        }
Пример #3
0
        private void ParseRequest(Stream stream, Uri serviceRoot)
        {
            MemoryStream memoryStream = new MemoryStream();

            TestUtil.CopyStream(stream, memoryStream);
            memoryStream.Position = 0;
            using (TextReader reader = new StreamReader(memoryStream))
            {
                this.ParseRequestVerb(reader);
                this.RequestHeaders.Clear();
                InMemoryWebRequest.ParseHeaders(reader, this.RequestHeaders);
                ApplyHeadersToProperties(this);
                reader.ReadLine();
                this.SetRequestStreamAsText(reader.ReadToEnd());
            }
        }