public bool TrySetFor(MessageHead head) { ThrowIfEnded(); BodyType?bodyType = BodyType.TryDetectFor(head); if (bodyType == null) { return(false); } CompressionType compression = bodyType.Value.CompressionType; TransferEncoding transfer = bodyType.Value.TransferEncoding; int contentLength = bodyType.Value.ContentLength; if (IsSet) { Reset(); } TransferEncoding = transfer; if (transfer == TransferEncoding.Raw) { ContentLength = contentLength; State = BodyParserState.RawRead; } else if (transfer == TransferEncoding.Chunked) { State = BodyParserState.Chunked_Length; StringQueue = new StringQueue(); } if (transfer != TransferEncoding.None) { CompressionType = compression; switch (compression) { case CompressionType.None: ContentTransform = new RawUnifiedDuplex(); break; case CompressionType.Gzip: ContentTransform = new GzipDecompressor(); break; case CompressionType.Deflate: ContentTransform = new DeflateDecompressor(); break; case CompressionType.Compress: return(false); default: return(false); } } IsSet = true; return(true); }
public void Compress(CompressionType compressionType) { if (IsSet) { throw new InvalidOperationException("Explicitly setting compression type must be performed before headers get sent"); } Compression = compressionType; switch (compressionType) { case CompressionType.None: ContentTransform = new RawUnifiedDuplex(); IsCompressionSet = false; break; case CompressionType.Gzip: ContentTransform = new GzipCompressor(CompressionLevel); IsCompressionSet = true; break; case CompressionType.Deflate: ContentTransform = new DeflateCompressor(CompressionLevel); IsCompressionSet = true; break; case CompressionType.Compress: throw new NotImplementedException("Got Compress, an unimplemented compression, as compression type"); default: throw new ArgumentException("Got Unknown as compression type"); } }
public bool TrySetFor(MessageHead head) { ThrowIfEnded(); BodyType?bodyType = BodyType.TryDetectFor(head); if (bodyType == null) { return(false); } CompressionType compression = bodyType.Value.CompressionType; TransferEncoding transfer = bodyType.Value.TransferEncoding; int contentLength = bodyType.Value.ContentLength; if (IsSet) { Finish(); } IsSet = true; TransferEncoding = transfer; ContentLength = contentLength; if (Compression != CompressionType.Unknown) { return(true); } Compression = compression; switch (compression) { case CompressionType.None: ContentTransform = new RawUnifiedDuplex(); IsCompressionSet = false; break; case CompressionType.Gzip: ContentTransform = new GzipCompressor(CompressionLevel); IsCompressionSet = true; break; case CompressionType.Deflate: ContentTransform = new DeflateCompressor(CompressionLevel); IsCompressionSet = true; break; case CompressionType.Compress: return(false); default: return(false); } return(true); }
public OutgoingMessage(Connection <Incoming, Outgoing> connection) { Connection = connection; BodyBuffer = new RawUnifiedDuplex(); Head = new Outgoing(); }