private HttpRequestMessage CreateRequest(string httpMethod, string absoluteUrl, object request) { this.PopulateRequestMetadata(request); var httpReq = new HttpRequestMessage(new HttpMethod(httpMethod), absoluteUrl); foreach (var name in Headers.AllKeys) { httpReq.Headers.Add(name, Headers[name]); } httpReq.Headers.Add(HttpHeaders.Accept, ContentType); if (HttpUtils.HasRequestBody(httpMethod) && request != null) { if (request is HttpContent httpContent) { httpReq.Content = httpContent; } else { if (request is string str) { httpReq.Content = new StringContent(str); } else if (request is byte[] bytes) { httpReq.Content = new ByteArrayContent(bytes); } else if (request is Stream stream) { httpReq.Content = new StreamContent(stream); } else { httpReq.Content = new StringContent(request.ToJson(), Encoding.UTF8, ContentType); } var compressor = StreamCompressors.Get(RequestCompressionType); if (compressor != null) { httpReq.Content = new CompressContent(httpReq.Content, compressor); } } } ApplyWebRequestFilters(httpReq); Interlocked.Increment(ref activeAsyncRequests); return(httpReq); }
public static Stream GetInputStream(this IRequest req, Stream stream) { var enc = req.GetContentEncoding(); var compressor = enc != null ? StreamCompressors.Get(enc) : null; if (compressor != null) { return(compressor.Decompress(stream)); } return(stream); }
public override string?GetCompressionType(IRequest request) { if (request.RequestPreferences.AcceptsDeflate && StreamCompressors.SupportsEncoding(CompressionTypes.Deflate)) { return(CompressionTypes.Deflate); } if (request.RequestPreferences.AcceptsGzip && StreamCompressors.SupportsEncoding(CompressionTypes.GZip)) { return(CompressionTypes.GZip); } return(null); }
public static byte[] DecompressBytes(this byte[] gzBuffer, string compressionType) => StreamCompressors.GetRequired(compressionType).DecompressBytes(gzBuffer);
public static Stream Decompress(this Stream gzStream, string compressionType) => !string.IsNullOrEmpty(compressionType) ? StreamCompressors.GetRequired(compressionType).Decompress(gzStream) : gzStream;
public static byte[] CompressBytes(this byte[] bytes, string compressionType) => StreamCompressors.GetRequired(compressionType).Compress(bytes);
public static Stream CompressStream(this Stream stream, string compressionType) => StreamCompressors.GetRequired(compressionType).Compress(stream);
public static byte[] Compress(this string text, string compressionType, Encoding?encoding = null) => StreamCompressors.GetRequired(compressionType).Compress(text, encoding);
public static IStreamCompressor GetCompressor(this IRequest request) { var encoding = request.GetCompressionType(); return(encoding != null?StreamCompressors.Get(encoding) : null); }
public void Can_zip_and_unzip_bytes_using_Gzip() { DoesCompress(StreamCompressors.GetRequired(CompressionTypes.GZip), "hello zip"); }
public void Can_zip_and_unzip_bytes_using_DeflateStream() { DoesCompress(StreamCompressors.GetRequired(CompressionTypes.Deflate), "hello zip"); }
public void Can_zip_and_unzip_bytes_using_BrotliStream() { DoesCompress(StreamCompressors.Assert("br"), "hello zip"); //CompressionTypes.Brotli }