This is a migrated thread and some comments may be shown as answers.

e.Response.Content in an HTTPResponseHandler returning gzipped content in chrome

3 Answers 18 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 12 Jan 2015, 10:06 PM
I have an HTTPResponseHandler defined that examines the content returned by the server, to see if the server has sent back the response I am waiting for. The response from the server forthe ContentEncoding parameter of the response is 'gzip'. In IE, I simply look at the string response from Encoding.ASCII.GetString(e.Response.Content) to see if it is the response from the server I am expecting, and all is well. However, when the browser is Chrome, the Response.Content is not being decompressed by the WebAii proxy, and I get a gzipped string back - so I cannot tell if I'm getting what I want back from the server - is there something in the proxy I have to do to tell it to decompress the response?

3 Answers, 1 is accepted

Sort by
0
Accepted
Cody
Telerik team
answered on 15 Jan 2015, 07:03 PM
Hi Steve,

First the WebAii proxy won't automatically decompress the response for you.  It may be that when using IE, depending on the version of IE you're using, the request header is telling the server it cannot accept compressed content.  As a result the server will not return compressed content. Then when you run the test in Chrome, the request header in Chrome tells the server it can accept compressed content and thus you are getting compressed content only in Chrome.

The easiest solution is to modify the outgoing header and remove the Accept-Encoding header from it. This will force the server to always send uncompressed content and you can easily parse the content.

The secondary solution is to write code to decompress the content. Something like this: 
string sBody;
 byte[] content = e.Response.GetUnchunkedContent();
string sEncoding = e.Response.Headers.GetValues("Content-Encoding");
 if (!String.IsNullOrEmpty(sEncoding))
 {
   if ("gzip".Equals(sEncoding, StringComparison.OrdinalIgnoreCase))
   {
       MemoryStream decompressed = HttpUtilities.DecodeHttpContent("gzip", new MemoryStream(content));
       sBody = Encoding.UTF8.GetString(decompressed.GetBuffer(), 0, (int)decompressed.Length);
   }
   else if ("deflate".Equals(sEncoding, StringComparison.OrdinalIgnoreCase))
   {
       MemoryStream decompressed = HttpUtilities.DecodeHttpContent("deflate", new MemoryStream(content));
       sBody = Encoding.UTF8.GetString(decompressed.GetBuffer(), 0, (int)decompressed.Length);
   }
 }
 else
{
     sBody = Encoding.UTF8.GetString(content);
 }



Regards,
Cody
Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
Steve
Top achievements
Rank 1
answered on 03 Feb 2015, 10:02 PM
Thank you - this is actually very helpful.  I guess I could set up a BeforeRequestListener to go in and strip the Accept-Encoding entry before the request actually goes to the server, couldn't I?
0
Cody
Telerik team
answered on 05 Feb 2015, 07:48 PM
Hi Steve,

I am glad I could help! Yes you can use BeforeRequestListener to strip the Accept-Encoding entry.

Regards,
Cody
Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
Tags
General Discussions
Asked by
Steve
Top achievements
Rank 1
Answers by
Cody
Telerik team
Steve
Top achievements
Rank 1
Share this question
or