joes 2004/07/07 19:10:05
Modified: env test_cgi.c
glue/perl/t/apreq cgi.t
src apreq_env.c
Log:
glue/perl/t/apreq/cgi.t has same problem: headers are sent before cookies are
baked. These problems were masked because of different io buffering mechanisms
between apr_file_io and stdio. Both tests are reworked slightly to keep similar
logic between them.
Revision Changes Path
1.12 +10 -12 httpd-apreq-2/env/test_cgi.c
Index: test_cgi.c
===================================================================
RCS file: /home/cvs/httpd-apreq-2/env/test_cgi.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- test_cgi.c 8 Jul 2004 01:56:00 -0000 1.11
+++ test_cgi.c 8 Jul 2004 02:10:05 -0000 1.12
@@ -79,6 +79,7 @@
else if (test && key) {
const apreq_jar_t *jar = apreq_jar(pool, NULL);
apreq_cookie_t *cookie;
+ char *dest;
apreq_log(APREQ_DEBUG 0, pool, "Fetching Cookie %s", key->v.data);
cookie = apreq_cookie(jar, key->v.data);
@@ -91,23 +92,20 @@
if (strcmp(test->v.data, "bake") == 0) {
apreq_cookie_bake(cookie, pool);
- apr_file_printf(out, "%s", "Content-Type: text/plain\n\n");
}
else if (strcmp(test->v.data, "bake2") == 0) {
apreq_cookie_bake2(cookie, pool);
- apr_file_printf(out, "%s", "Content-Type: text/plain\n\n");
}
+
+ apr_file_printf(out, "%s", "Content-Type: text/plain\n\n");
+ dest = apr_pcalloc(pool, cookie->v.size + 1);
+ if (apreq_decode(dest, cookie->v.data, cookie->v.size) >= 0)
+ apr_file_printf(out, "%s", dest);
else {
- char *dest = apr_pcalloc(pool, cookie->v.size + 1);
- apr_file_printf(out, "%s", "Content-Type: text/plain\n\n");
- if (apreq_decode(dest, cookie->v.data, cookie->v.size) >= 0)
- apr_file_printf(out, "%s", dest);
- else {
- apreq_log(APREQ_ERROR APR_EGENERAL, pool,
- "Bad cookie encoding: %s",
- cookie->v.data);
- exit(-1);
- }
+ apreq_log(APREQ_ERROR APR_EGENERAL, pool,
+ "Bad cookie encoding: %s",
+ cookie->v.data);
+ exit(-1);
}
}
1.3 +3 -1 httpd-apreq-2/glue/perl/t/apreq/cgi.t
Index: cgi.t
===================================================================
RCS file: /home/cvs/httpd-apreq-2/glue/perl/t/apreq/cgi.t,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- cgi.t 19 Jun 2004 15:38:18 -0000 1.2
+++ cgi.t 8 Jul 2004 02:10:05 -0000 1.3
@@ -158,7 +158,6 @@
use Apache::Cookie;
my $p = APR::Pool->new();
-print "Content-Type: text/plain\n\n";
apreq_log("Creating Apache::Request object");
my $req = Apache::Request->new($p);
@@ -170,6 +169,7 @@
my $key = $req->param("key");
if ($foo || $bar) {
+ print "Content-Type: text/plain\n\n";
if ($foo) {
apreq_log("foo => $foo");
print "\tfoo => $foo\n";
@@ -190,12 +190,14 @@
elsif ($test eq "bake2") {
$cookies{$key}->bake2;
}
+ print "Content-Type: text/plain\n\n";
print $cookies{$key}->value;
}
}
else {
my $len = 0;
+ print "Content-Type: text/plain\n\n";
apreq_log("Fetching all parameters");
for ($req->param) {
my $param = $req->param($_);
1.13 +1 -0 httpd-apreq-2/src/apreq_env.c
Index: apreq_env.c
===================================================================
RCS file: /home/cvs/httpd-apreq-2/src/apreq_env.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- apreq_env.c 8 Jul 2004 01:56:00 -0000 1.12
+++ apreq_env.c 8 Jul 2004 02:10:05 -0000 1.13
@@ -190,6 +190,7 @@
apr_status_t s = apr_file_open_stdout(&out, p);
apreq_log(APREQ_DEBUG s, p, "Setting header: %s => %s", name, value);
bytes = apr_file_printf(out, "%s: %s" CRLF, name, value);
+ apr_file_flush(out);
return bytes > 0 ? APR_SUCCESS : APR_EGENERAL;
}