Hi all,

I just want to test the handling of compressed responses. I have some java code 
which can do the compression of content and which listens to http get requests. 
But I actually have no idea how to send the response respectively which 
streams/writers to use and how to combine the message header and the compressed 
content.
My last try was building a byteArray:

int contentLength = 0;
String sHeader = "HTTP/1.1 200 OK"
                           +" Server: Apache"
                           +" Content-Type: text/html"
                           +" Content-Encoding: gzip";

// parameter String message comes with call of method
byte[] content = message.getBytes("ISO-8859-1");
byte[] compressedContent = new byte[1000];
byte[] bHeader;
byte[] response;
int numOfBytes;

Deflater def = new Deflater(Deflater.BEST_COMPRESSION);
def.setInput(content);
def.finish();
contentLength = def.deflate(compressedContent);
sHeader += " Content-Length: "+contentLength;
bHeader = sHeader.getBytes("ISO-8859-1");
numOfBytes = bHeader.length + compressedContent.length;
response = new byte[numOfBytes];
System.arraycopy(bHeader, 0, response, 0, bHeader.length);
System.arraycopy(compressedContent, 0, response, 
                 bHeader.length, compressedContent.length);

But on client side I receive a ClientProtocolException: Invalid header.

Any hints?

Kind regards,

Michael
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to