Noah Silverman
2012-09-18 16:38:09 UTC
Hello,
I am attempting to write a small CGI client in C++ that will use Google's protocol buffers to manage data. I am using the latest release of fast cig, with Nginx.
Google's protocol buffers library serializes a string into a "binary format". I need to be able to send that format back as a response. (Details on the format are here: https://developers.google.com/protocol-buffers/docs/encoding)
My test program sends an POST request to the server, and expects an application/octet-stream back of a serialized string from the CGI script.
I am able to start and run the application fine.
My CGI code is able to successfully receive the POST and pass the data fro the received string. That works great.
The problem is in returning back a response. I am able to create and serialized a proper response (using protobuf library). I can then dump the contents to a log file and verify that they are perfect. HOWEVER, the receiving program is unable to recognize the binary response sent back from the CGI. Somehow, it is getting mangled in sending the response. I can't figure out why.
Any and all suggestion are welcome.
Thank You,
--
Noah
Relevant code snippets:
CGI snippet
==========================================================
string post_response;
bid_response.SerializeToString(&post_response)
cout << "Status: 200 OK\r\n";
cout << "Content-type: application/octet-stream\r\n\r\n";
cout << post_response << "\n";
Nginx config
==========================================================
location ~ test.cgi$ {
fastcgi_pass 127.0.0.1:8000;
include fastcgi_params;
default_type application/octet-stream;
fastcgi_pass_header http;
}
I am attempting to write a small CGI client in C++ that will use Google's protocol buffers to manage data. I am using the latest release of fast cig, with Nginx.
Google's protocol buffers library serializes a string into a "binary format". I need to be able to send that format back as a response. (Details on the format are here: https://developers.google.com/protocol-buffers/docs/encoding)
My test program sends an POST request to the server, and expects an application/octet-stream back of a serialized string from the CGI script.
I am able to start and run the application fine.
My CGI code is able to successfully receive the POST and pass the data fro the received string. That works great.
The problem is in returning back a response. I am able to create and serialized a proper response (using protobuf library). I can then dump the contents to a log file and verify that they are perfect. HOWEVER, the receiving program is unable to recognize the binary response sent back from the CGI. Somehow, it is getting mangled in sending the response. I can't figure out why.
Any and all suggestion are welcome.
Thank You,
--
Noah
Relevant code snippets:
CGI snippet
==========================================================
string post_response;
bid_response.SerializeToString(&post_response)
cout << "Status: 200 OK\r\n";
cout << "Content-type: application/octet-stream\r\n\r\n";
cout << post_response << "\n";
Nginx config
==========================================================
location ~ test.cgi$ {
fastcgi_pass 127.0.0.1:8000;
include fastcgi_params;
default_type application/octet-stream;
fastcgi_pass_header http;
}