My fault. After adding the necessary CRLF it works.
String sHeader = "HTTP/1.1 200 OK\r\n"
+" Server: Apache\r\n"
+" Content-Type: text/html\r\n"
+" Content-Encoding: gzip\r\n";
But when I receive the response I have only one header containing all header
fields together [Server: Apache Content-Type: text/html Content-Encoding: gzip]
and I can't iterate nor pick a special header out. I guess in my example above
I should have at least three headers. Something else what I did wrong?
Kind regards,
Michael
-----Ursprüngliche Nachricht-----
Von: Fankanowsky, Michael
Gesendet: Montag, 23. April 2012 10:33
An: [email protected]
Betreff: How to test compressed response
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;
v
// 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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]