Counting…to get the headers.

8 views
Skip to first unread message

Kevin Ingwersen

unread,
Sep 1, 2013, 12:52:04 PM9/1/13
to appj...@googlegroups.com
Hey.

So I have finally made it to get php5.4 as precompile from the latest MAMP package. So I have an easier and mor enatural way of running PHP code within appJS. So far, so good. Now however I am getting the output of the headers! X.X

So, the document is interpreted all rubbishly; it starts with the Content-type and X-Powered-By header lines.

Does anybody know, how I could modify the following functions to figure out when the headers start/end?

$PHP = spawn(exe, ["-q", "-f", MAIN+url.substring(1), qstring], {'env':env});
var allData = "";
var code = 200;
$PHP.stdout.on('data',function(data) {
allData += data;
});
$PHP.stderr.on("data",function(data) {
console.log("[Error]: "+data);
allData += data;
code = 500;
});
$PHP.stdout.on('end',function() {
response.send(code,mimetype,allData);
});

And yes, the two options, -f and -q, do nothing x)

Regards, Ingwie
PS: neat little trick: the shebang line appearently accepts relative paths too ;). This way I run my php-cli scripts with my php54 binaries.

Simon Horton

unread,
Sep 2, 2013, 4:59:31 AM9/2/13
to appj...@googlegroups.com

Hi Kevin,

If I remember correctly then you can just search for \n\n I.e. two end of line characters to indicate headers are over.

I think as well headers are sent on one like so you could parse them by splitting on end of line (character 10). Then when you get a line that is blank the headers are over (same as searching for two end of line above).

Simon

--
You received this message because you are subscribed to the Google Groups "appjs-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to appjs-dev+...@googlegroups.com.
To post to this group, send email to appj...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Kevin Ingwersen

unread,
Sep 2, 2013, 5:03:58 AM9/2/13
to appj...@googlegroups.com
Hey!

Well thank you, I will try that out. Currently i am using a rather dirty way: split, splice, join. not the finest, but at least working solution. BTW, what is the method which allows the router to pre-set the headers? because then they'd at least be useful o.o

Regards, Ingwie

Simon Horton

unread,
Sep 2, 2013, 5:11:05 AM9/2/13
to appj...@googlegroups.com

Hi Kevin,

If you mean in nodejs then the handler function gets two objects - request and response. So look at response object and you can then set the headers, I cannot remember if it was a setHeader function or if there was just a headers array but it should be quite straight forward.

Simon

Kevin Ingwersen

unread,
Sep 2, 2013, 5:12:17 AM9/2/13
to appj...@googlegroups.com
It is compatible with appjs' router? thats where I am at to parse my PHP stuff correctly.

Simon Horton

unread,
Sep 2, 2013, 5:17:57 AM9/2/13
to appj...@googlegroups.com

Look for a response object appjs still needs to send headers to browser so it should be there. You can do console.log(response) if you want to view the object.

Simon

Reply all
Reply to author
Forward
0 new messages