Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8532087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:38:00+00:00 2026-06-11T09:38:00+00:00

On the server I’m forcing compression with a custom message handler. The handler checks

  • 0

On the server I’m forcing compression with a custom message handler. The handler checks the Accept-Encoding header and if it is supported (e.g. GZip) will swap out the HttpResponseMessage.Content with an instance of CompressedContent. This simply compresses the original content like so:

protected override async Task SerializeToStreamAsync(Stream stream, TransportContext context)
{
    Ensure.Argument.NotNull(stream, "stream");

    using (content) // original content
    {
        // creates a new GZip/Deflate stream
        var compressed = GetStream(CompressionMode.Compress, stream);
        await content.CopyToAsync(compressed);
        compressed.Dispose();
    }
}

On the client, we can achieve the decompression by checking the Content-Encoding header and using another HttpContent type to perform the decompression:

protected async override Task SerializeToStreamAsync(Stream stream, TransportContext context)
{
    Ensure.Argument.NotNull(stream, "stream");

    using (content)
    {
        var compressed = await content.ReadAsStreamAsync();
        var decompressed = GetStream(CompressionMode.Decompress, compressed);
        await decompressed.CopyToAsync(stream);
        decompressed.Dispose();
    }
}

The part I am unsure of is whether we should be using a custom HttpContent type to do the decompression. On the server it makes sense to do this since we don’t really have other way of touching the response stream. On the client however, this could be done by decompressing the standard StreamContent directly or even with a custom HttpClient implementation.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T09:38:02+00:00Added an answer on June 11, 2026 at 9:38 am

    Message handlers can be used on the client as well, in conjunction with HttpClient, to process the request/response. In your case that would be useful to provide a reverse process to that happening on the server.

    This is the beautiful symmetry of ASP.NET Web API.

    A great article on client side message handlers is here – http://byterot.blogspot.ch/2012/06/aspnet-web-api-client-delegating.html

    Another example can be found here, on Henrik’s blog – it’s a bit old (against beta), but the gist is still the same: http://blogs.msdn.com/b/henrikn/archive/2012/02/16/extending-httpclient-with-oauth-to-access-twitter.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Server side validation works great but client side will not work on some fields.
My server is somehow configured to accept any string as a existing subdomian. This
Server shutdown from power failure. Mysql will not start now. Disk is not full.
This server support version 662 and ealier. A downgrade path is not supported.. I
server { listen 80; server_name ~^(?<custom>.+)\.(test)?website\.com$; location ~ ^/event/(\d+)$ { proxy_pass_header Server; proxy_set_header Host
Server Error in '/' Application. Parser Error Description: An error occurred during the parsing
Server Errors below: If an error occurred, a HTTP status code 503 (Service Unavailable)
Server has created a socket and bound to a port and started a thread
Server.UrlEncode(My File.doc) returns My+File.doc, whereas the javascript escape(My File.doc) returns My%20File.doc. As far as
// Server.js var http = require('http'); var path = require('path'); var fs = require('fs');

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.