Ejemplo n.º 1
0
        private void Reset()
        {
            _state   = ClientState.ReadingProlog;
            _context = null;

            if (_parser != null)
            {
                _parser.Dispose();
                _parser = null;
            }

            if (_writeStream != null)
            {
                _writeStream.Dispose();
                _writeStream = null;
            }

            if (InputStream != null)
            {
                InputStream.Dispose();
                InputStream = null;
            }

            ReadBuffer.Reset();

            Method         = null;
            Protocol       = null;
            Request        = null;
            Headers        = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
            PostParameters = null;

            if (MultiPartItems != null)
            {
                foreach (var item in MultiPartItems)
                {
                    if (item.Stream != null)
                    {
                        item.Stream.Dispose();
                    }
                }

                MultiPartItems = null;
            }
        }
Ejemplo n.º 2
0
        private void Reset()
        {
            _state = ClientState.ReadingProlog;
            _context = null;

            if (_parser != null)
            {
                _parser.Dispose();
                _parser = null;
            }

            if (_writeStream != null)
            {
                _writeStream.Dispose();
                _writeStream = null;
            }

            if (InputStream != null)
            {
                InputStream.Dispose();
                InputStream = null;
            }

            ReadBuffer.Reset();

            Method = null;
            Protocol = null;
            Request = null;
            Headers = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
            PostParameters = new NameValueCollection();

            if (MultiPartItems != null)
            {
                foreach (var item in MultiPartItems)
                {
                    if (item.Stream != null)
                        item.Stream.Dispose();
                }

                MultiPartItems = null;
            }
        }
Ejemplo n.º 3
0
        public void UnsetParser()
        {
            Debug.Assert(_parser != null);

            _parser = null;
        }
Ejemplo n.º 4
0
        private bool ProcessContentLengthHeader()
        {
            // Read the content.

            string contentLengthHeader;

            if (Headers.TryGetValue("Content-Length", out contentLengthHeader))
            {
                int contentLength;

                if (!int.TryParse(contentLengthHeader, out contentLength))
                {
                    throw new ProtocolException(String.Format("Could not parse Content-Length header '{0}'", contentLengthHeader));
                }

                string contentTypeHeader;
                string contentType      = null;
                string contentTypeExtra = null;

                if (Headers.TryGetValue("Content-Type", out contentTypeHeader))
                {
                    string[] parts = contentTypeHeader.Split(new[] { ';' }, 2);

                    contentType      = parts[0].Trim().ToLowerInvariant();
                    contentTypeExtra = parts.Length == 2 ? parts[1].Trim() : null;
                }

                if (_parser != null)
                {
                    _parser.Dispose();
                    _parser = null;
                }

                switch (contentType)
                {
                case "application/x-www-form-urlencoded":
                    _parser = new HttpUrlEncodedRequestParser(this, contentLength);
                    break;

                case "multipart/form-data":
                    string boundary = null;

                    if (contentTypeExtra != null)
                    {
                        string[] parts = contentTypeExtra.Split(new[] { '=' }, 2);

                        if (
                            parts.Length == 2 &&
                            String.Equals(parts[0], "boundary", StringComparison.OrdinalIgnoreCase)
                            )
                        {
                            boundary = parts[1];
                        }
                    }

                    if (boundary == null)
                    {
                        throw new ProtocolException("Expected boundary with multipart content type");
                    }

                    _parser = new HttpMultiPartRequestParser(this, contentLength, boundary);
                    break;

                default:
                    _parser = new HttpUnknownRequestParser(this, contentLength);
                    break;
                }

                // We've made a parser available. Recurs back to start processing
                // with the parser.

                ProcessContent();
                return(true);
            }

            return(false);
        }
Ejemplo n.º 5
0
        public void UnsetParser()
        {
            Debug.Assert(_parser != null);

            _parser = null;
        }
Ejemplo n.º 6
0
        private bool ProcessContentLengthHeader()
        {
            // Read the content.

            string contentLengthHeader;

            if (Headers.TryGetValue("Content-Length", out contentLengthHeader))
            {
                int contentLength;

                if (!int.TryParse(contentLengthHeader, out contentLength))
                    throw new ProtocolException(String.Format("Could not parse Content-Length header '{0}'", contentLengthHeader));

                string contentTypeHeader;
                string contentType = null;
                string contentTypeExtra = null;

                if (Headers.TryGetValue("Content-Type", out contentTypeHeader))
                {
                    string[] parts = contentTypeHeader.Split(new[] { ';' }, 2);

                    contentType = parts[0].Trim().ToLowerInvariant();
                    contentTypeExtra = parts.Length == 2 ? parts[1].Trim() : null;
                }

                if (_parser != null)
                {
                    _parser.Dispose();
                    _parser = null;
                }

                switch (contentType)
                {
                    case "application/x-www-form-urlencoded":
                        _parser = new HttpUrlEncodedRequestParser(this, contentLength);
                        break;

                    case "multipart/form-data":
                        string boundary = null;

                        if (contentTypeExtra != null)
                        {
                            string[] parts = contentTypeExtra.Split(new[] { '=' }, 2);

                            if (
                                parts.Length == 2 &&
                                String.Equals(parts[0], "boundary", StringComparison.OrdinalIgnoreCase)
                            )
                                boundary = parts[1];
                        }

                        if (boundary == null)
                            throw new ProtocolException("Expected boundary with multipart content type");

                        _parser = new HttpMultiPartRequestParser(this, contentLength, boundary);
                        break;

                    default:
                        _parser = new HttpUnknownRequestParser(this, contentLength);
                        break;
                }

                // We've made a parser available. Recurs back to start processing
                // with the parser.

                ProcessContent();
                return true;
            }

            return false;
        }