Re: Return application octet-stream data

Noah Silverman <[email protected]> Tue, 18 Sep 2012 11:20:09 -0700
Newsgroups gmane.comp.web.fastcgi.devel
Message-ID <[email protected]>
--===============7084126169665096700==
Content-Type: multipart/alternative; boundary="Apple-Mail=_76811538-547B-432E-804E-919ED329582C"


--Apple-Mail=_76811538-547B-432E-804E-919ED329582C
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=us-ascii

Charles,

If you'll notice, in my C++ snippet, I am outputting a double carriage =
return between the headers and the body:

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";


--
Noah=20



On Sep 18, 2012, at 10:48 AM, Charles Thomas <[email protected]> =
wrote:

> =46rom what I understand of HTTP protocol Content-Length is used to =
determine how long the message is... not the occurrence of a null =
character in the data stream; and that content length starts after the =
newline separating headers from data.
>=20
> Some thoughts:
>=20
> 1) Did you separate the headers with a "\n" from the body
> 2) Is the content length truly the length of the data
> 3) Does the mime type have to be set correctly in order for server you =
are talking with to recognize,
> 4) Some times I have found that servers expect the Accept tag to =
contain specific reference to the type of file.
>=20
>=20
> Sent from my iPad
>=20
> On Sep 18, 2012, at 12:36 PM, Noah Silverman <[email protected]> =
wrote:
>=20
>> Very possibly, =20
>>=20
>> But since I don't control the serialization I have no way to manage =
that.
>>=20
>> Is there a way to force fastcgi to ignore a zero byte?
>>=20
>> --
>> Noah Silverman
>> Smart Media Corp.
>>=20
>>=20
>>=20
>> On Sep 18, 2012, at 10:28 AM, Jay Sprenkle <[email protected]> =
wrote:
>>=20
>>> 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
>>=20
>> _______________________________________________
>> FastCGI-developers mailing list
>> FastCGI-developers-xGejAJT2w6xVgU18Zptdi0EOCMrvLtNR@public.gmane.org
>> http://mailman.fastcgi.com/mailman/listinfo/fastcgi-developers


--Apple-Mail=_76811538-547B-432E-804E-919ED329582C
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
	charset=us-ascii

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html =
charset=3Dus-ascii"></head><body style=3D"word-wrap: break-word; =
-webkit-nbsp-mode: space; -webkit-line-break: after-white-space; =
"><div>Charles,</div><div><br></div><div>If you'll notice, in my C++ =
snippet, I am outputting a double carriage return between the headers =
and the =
body:</div><div><br></div><div>bid_response.SerializeToString(&amp;post_re=
sponse)<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";</div><div><br></div><br><div>
<div>--</div><div>Noah&nbsp;</div><div><br></div><br =
class=3D"Apple-interchange-newline">

</div>
<br><div><div>On Sep 18, 2012, at 10:48 AM, Charles Thomas &lt;<a =
href=3D"mailto:[email protected]">[email protected]</a>&gt; =
wrote:</div><br class=3D"Apple-interchange-newline"><blockquote =
type=3D"cite"><div bgcolor=3D"#FFFFFF"><div>=46rom what I understand of =
HTTP protocol Content-Length is used to determine how long the message =
is... not the occurrence of a null character in the data stream; and =
that content length starts after the newline separating headers from =
data.</div><div><br></div><div>Some =
thoughts:</div><div><br></div><div>1) Did you separate the headers with =
a "\n" from the body</div><div>2) Is the content length truly the length =
of the data</div><div>3) Does the mime type have to be set correctly in =
order for server you are talking with to recognize,</div><div>4) Some =
times I have found that servers expect the Accept tag to contain =
specific reference to the type of file.</div><div><br><br>Sent from my =
iPad</div><div><br>On Sep 18, 2012, at 12:36 PM, Noah Silverman &lt;<a =
href=3D"mailto:[email protected]">[email protected]</a>&gt; =
wrote:<br><br></div><div></div><blockquote type=3D"cite"><meta =
http-equiv=3D"Content-Type" content=3D"text/html =
charset=3Diso-8859-1"><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=3D"Apple-interchange-newline">

</div>
<br><div><div>On Sep 18, 2012, at 10:28 AM, Jay Sprenkle &lt;<a =
href=3D"mailto:[email protected]">[email protected]</a>&gt; =
wrote:</div><br class=3D"Apple-interchange-newline"><blockquote =
type=3D"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=3D"gmail_quote">On Tue, Sep 18, 2012 at 11:38 AM, Noah Silverman =
<span dir=3D"ltr">&lt;<a href=3D"mailto:[email protected]" =
target=3D"_blank">[email protected]</a>&gt;</span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"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=3D"https://developers.google.com/protocol-buffers/docs/encoding" =
target=3D"_blank">https://developers.google.com/protocol-buffers/docs/enco=
ding</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>
=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<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>
=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<br>
location ~ test.cgi$ {<br>
&nbsp; &nbsp; &nbsp; &nbsp; fastcgi_pass &nbsp; <a =
href=3D"http://127.0.0.1:8000/" target=3D"_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=3D"mailto:FastCGI-developers-xGejAJT2w6xVgU18Zptdi0EOCMrvLtNR@public.gmane.org">FastCGI-developers@=
mailman.fastcgi.com</a><br>
<a href=3D"http://mailman.fastcgi.com/mailman/listinfo/fastcgi-developers"=
 =
target=3D"_blank">http://mailman.fastcgi.com/mailman/listinfo/fastcgi-deve=
lopers</a><br>
</blockquote></div><br><br clear=3D"all"><div><br></div>-- =
<br>---<br><em =
style=3D"font-family:Verdana,Helvetica,sans-serif;font-size:12px;backgroun=
d-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=3D"font-family:Verdana,Helvetica,sans-serif;font-size:12px;backgroun=
d-color:rgb(255,255,255)">--</em></div><div><em =
style=3D"font-family:Verdana,Helvetica,sans-serif;font-size:12px;backgroun=
d-color:rgb(255,255,255)">The Democrats are the left wing.</em></div>
<div><em =
style=3D"font-family:Verdana,Helvetica,sans-serif;font-size:12px;backgroun=
d-color:rgb(255,255,255)">The Republicans are the right =
wing.</em></div><div><em =
style=3D"font-family:Verdana,Helvetica,sans-serif;font-size:12px;backgroun=
d-color:rgb(255,255,255)">We all know how well a bird flies with just =
one wing.</em></div>
<br>
</div>
</blockquote></div><br></blockquote><blockquote =
type=3D"cite"><span>_______________________________________________</span>=
<br><span>FastCGI-developers mailing list</span><br><span><a =
href=3D"mailto:FastCGI-developers-xGejAJT2w6xVgU18Zptdi0EOCMrvLtNR@public.gmane.org">FastCGI-developers@=
mailman.fastcgi.com</a></span><br><span><a =
href=3D"http://mailman.fastcgi.com/mailman/listinfo/fastcgi-developers">ht=
tp://mailman.fastcgi.com/mailman/listinfo/fastcgi-developers</a></span><br=
></blockquote></div></blockquote></div><br></body></html>=

--Apple-Mail=_76811538-547B-432E-804E-919ED329582C--

--===============7084126169665096700==
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

--===============7084126169665096700==--