Question

I am building web server. I want to send gzipped html page but something is wrong with my code:

...
char response[] = "HTTP/1.1 200 OK\r\n"
"Content-Type: text/html; charset=UTF-8\r\n"
"Content-Encoding: gzip\r\n"
"Connection: keep-alive\r\n"
"Server: michal\r\n"
"Set-Cookie: nazwa=test\r\n"
"Date: Mon, 24 Feb 2014 11:39:26 GMT\r\n"
"Vary: Accept-Encoding\r\n\r\n";
std::string body =
"<html><body><h1>It works!</h1>"
"<p>This is the default web page for this server.</p>"
"<p>The web server software is running but no content has been added, yet.</p>"
"<form method='post' action='/' enctype='multipart/form-data' ><input type='file' name='pliczek1'/><input type='submit' name='sub' value='sender' /><input type='checkbox' name='add[]' value='100001_used' ><input type='hidden' name='hidd' value='testowy hiddenik' /><input type='checkbox' name='add[]' value='100002_used' ><textarea name='txtform'>tekstowe poleąś</textarea></form>"
"</body></html>\r\n\r\n";

...

std::string responseStr = response;
responseStr += compress_string(body);
std::cout << responseStr;
write(client_fd, responseStr.c_str(), responseStr.length());
close(client_fd);

I am using compress_string function: http://pastebin.com/kFGgvVbF Without compress_string and Content-Encoding everything works fine so, something wrong is with compressing/sending/headers. Page is not loading in browser. In FF displays error with encoding of content. What's wrong ? How to fix it ?

Was it helpful?

Solution

I have found the solution. Everything with code is OK but I had to change Content-Encoding header to "deflate" instead of gzipc!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top