/// <summary> /// Processa o cabeçalho com o tamanho do conteúdo. /// </summary> /// <returns></returns> private bool ProcessContentLengthHeader() { 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; } ProcessContent(); return(true); } return(false); }
/// <summary> /// Remove o parse da instancia. /// </summary> public void UnsetParser() { _parser = null; }