예제 #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;
            }
        }
예제 #2
0
파일: HttpClient.cs 프로젝트: Cocotus/NHttp
        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;
            }
        }
예제 #3
0
        public void UnsetParser()
        {
            Debug.Assert(_parser != null);

            _parser = null;
        }
예제 #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);
        }
예제 #5
0
파일: HttpClient.cs 프로젝트: Cocotus/NHttp
        public void UnsetParser()
        {
            Debug.Assert(_parser != null);

            _parser = null;
        }
예제 #6
0
파일: HttpClient.cs 프로젝트: Cocotus/NHttp
        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;
        }