Re: Return application octet-stream data

Noah Silverman <[email protected]> Tue, 18 Sep 2012 10:36:06 -0700
Newsgroups gmane.comp.web.fastcgi.devel
Message-ID <[email protected]>
--===============1654302556416534800==
Content-Type: multipart/alternative; boundary="Apple-Mail=_20ED2A53-FAD9-4608-9914-07CB91EE6B4B"


--Apple-Mail=_20ED2A53-FAD9-4608-9914-07CB91EE6B4B
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=iso-8859-1

Very possibly, =20

But since I don't control the serialization I have no way to manage =
that.

Is there a way to force fastcgi to ignore a zero byte?

--
Noah Silverman
Smart Media Corp.



On Sep 18, 2012, at 10:28 AM, Jay Sprenkle <[email protected]> wrote:

> Just a wild guess:
> Perhaps your serialized data contains a byte containing zero which is =
being taken as an end marker (prematurely terminating the response)?
>=20
> On Tue, Sep 18, 2012 at 11:38 AM, Noah Silverman =
<[email protected]> wrote:
> Hello,
>=20
> 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.
>=20
> 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)
>=20
>  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.
>=20
> I am able to start and run the application fine.
>=20
> My CGI code is able to successfully receive the POST and pass the data =
fro the received string.  That works great.
>=20
> 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.
>=20
> Any and all suggestion are welcome.
>=20
> Thank You,
>=20
> --
> Noah
>=20
> Relevant code snippets:
>=20
>=20
> CGI snippet
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D
> 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";
>=20
>=20
> Nginx config
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D
> location ~ test.cgi$ {
>         fastcgi_pass   127.0.0.1:8000;
>         include        fastcgi_params;
>         default_type application/octet-stream;
>         fastcgi_pass_header http;
> }
> _______________________________________________
> FastCGI-developers mailing list
> FastCGI-developers-xGejAJT2w6xVgU18Zptdi0EOCMrvLtNR@public.gmane.org
> http://mailman.fastcgi.com/mailman/listinfo/fastcgi-developers
>=20
>=20
>=20
> --=20
> ---
> "Why do you have that banana in your ear?"=20
> "To keep away the alligators."
> "But there are no alligators here."
> "See! It's working!"
> --
> The Democrats are the left wing.
> The Republicans are the right wing.
> We all know how well a bird flies with just one wing.
>=20


--Apple-Mail=_20ED2A53-FAD9-4608-9914-07CB91EE6B4B
Content-Transfer-Encoding: 7bit
Content-Type: text/html;
	charset=iso-8859-1

<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Very possibly, &nbsp;</div><div><br></div><div>But since I don't control the serialization I have no way to manage that.</div><div><br></div><div>Is there a way to force fastcgi to ignore a zero byte?</div><br><div>
<div>--</div><div>Noah Silverman</div><div>Smart Media Corp.</div><div><br></div><br class="Apple-interchange-newline">

</div>
<br><div><div>On Sep 18, 2012, at 10:28 AM, Jay Sprenkle &lt;<a href="mailto:[email protected]">[email protected]</a>&gt; wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Just a wild guess:<div>Perhaps your serialized data contains a byte containing zero which is being taken as an end marker (prematurely terminating the response)?<br><br><div class="gmail_quote">On Tue, Sep 18, 2012 at 11:38 AM, Noah Silverman <span dir="ltr">&lt;<a href="mailto:[email protected]" target="_blank">[email protected]</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br>
<br>
I am attempting to write a small CGI client in C++ that will use Google's protocol buffers to manage data. &nbsp;I am using the latest release of fast cig, with Nginx.<br>
<br>
Google's protocol buffers library serializes a string into a "binary format". &nbsp;I need to be able to send that format back as a response. &nbsp;(Details on the format are here: <a href="https://developers.google.com/protocol-buffers/docs/encoding" target="_blank">https://developers.google.com/protocol-buffers/docs/encoding</a>)<br>

<br>
&nbsp;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.<br>
<br>
I am able to start and run the application fine.<br>
<br>
My CGI code is able to successfully receive the POST and pass the data fro the received string. &nbsp;That works great.<br>
<br>
The problem is in returning back a response. &nbsp;I am able to create and serialized a proper response (using protobuf library). &nbsp;I can then dump the contents to a log file and verify that they are perfect. &nbsp;HOWEVER, the receiving program is unable to recognize the binary response sent back from the CGI. &nbsp;Somehow, it is getting mangled in sending the response. &nbsp;I can't figure out why.<br>

<br>
Any and all suggestion are welcome.<br>
<br>
Thank You,<br>
<br>
--<br>
Noah<br>
<br>
Relevant code snippets:<br>
<br>
<br>
CGI snippet<br>
==========================================================<br>
string post_response;<br>
bid_response.SerializeToString(&amp;post_response)<br>
cout &lt;&lt; "Status: 200 OK\r\n";<br>
cout &lt;&lt; "Content-type: application/octet-stream\r\n\r\n";<br>
cout &lt;&lt; post_response &lt;&lt; "\n";<br>
<br>
<br>
Nginx config<br>
==========================================================<br>
location ~ test.cgi$ {<br>
&nbsp; &nbsp; &nbsp; &nbsp; fastcgi_pass &nbsp; <a href="http://127.0.0.1:8000/" target="_blank">127.0.0.1:8000</a>;<br>
&nbsp; &nbsp; &nbsp; &nbsp; include &nbsp; &nbsp; &nbsp; &nbsp;fastcgi_params;<br>
&nbsp; &nbsp; &nbsp; &nbsp; default_type application/octet-stream;<br>
&nbsp; &nbsp; &nbsp; &nbsp; fastcgi_pass_header http;<br>
}<br>
_______________________________________________<br>
FastCGI-developers mailing list<br>
<a href="mailto:FastCGI-developers-xGejAJT2w6xVgU18Zptdi0EOCMrvLtNR@public.gmane.org">FastCGI-developers-xGejAJT2w6xVgU18Zptdi0EOCMrvLtNR@public.gmane.org</a><br>
<a href="http://mailman.fastcgi.com/mailman/listinfo/fastcgi-developers" target="_blank">http://mailman.fastcgi.com/mailman/listinfo/fastcgi-developers</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>---<br><em style="font-family:Verdana,Helvetica,sans-serif;font-size:12px;background-color:rgb(255,255,255)">"Why do you have that banana in your ear?"&nbsp;<br>
"To keep away the alligators."<br>"But there are no alligators here."<br>"See! It's working!"</em>
<div><em style="font-family:Verdana,Helvetica,sans-serif;font-size:12px;background-color:rgb(255,255,255)">--</em></div><div><em style="font-family:Verdana,Helvetica,sans-serif;font-size:12px;background-color:rgb(255,255,255)">The Democrats are the left wing.</em></div>
<div><em style="font-family:Verdana,Helvetica,sans-serif;font-size:12px;background-color:rgb(255,255,255)">The Republicans are the right wing.</em></div><div><em style="font-family:Verdana,Helvetica,sans-serif;font-size:12px;background-color:rgb(255,255,255)">We all know how well a bird flies with just one wing.</em></div>
<br>
</div>
</blockquote></div><br></body></html>
--Apple-Mail=_20ED2A53-FAD9-4608-9914-07CB91EE6B4B--

--===============1654302556416534800==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
FastCGI-developers mailing list
FastCGI-developers-xGejAJT2w6xVgU18Zptdi0EOCMrvLtNR@public.gmane.org
http://mailman.fastcgi.com/mailman/listinfo/fastcgi-developers

--===============1654302556416534800==--