randyk 2003/10/21 09:20:17
Modified: env libapreq_cgi.c
env/cgi_test/t cgi.t
Log:
- rename APREQ_ASSERT macro to APREQ_ENV_STATUS, used to report
on status of environment variable lookups
- prepend HTTP_ to certain environment variables (thanks, Joe!)
- enable cookie lookup tests
Revision Changes Path
1.12 +20 -10 httpd-apreq-2/env/libapreq_cgi.c
Index: libapreq_cgi.c
===================================================================
RCS file: /home/cvs/httpd-apreq-2/env/libapreq_cgi.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- libapreq_cgi.c 20 Oct 2003 05:25:14 -0000 1.11
+++ libapreq_cgi.c 21 Oct 2003 16:20:17 -0000 1.12
@@ -95,10 +95,11 @@
#define CRLF "\015\012"
-#define APREQ_ASSERT(rc_run) do { \
+#define APREQ_ENV_STATUS(rc_run, k) do { \
apr_status_t rc = rc_run; \
if (rc != APR_SUCCESS) { \
- apreq_log(APREQ_DEBUG 0, ctx, "failed: %d", rc); \
+ apreq_log(APREQ_DEBUG 0, ctx, \
+ "Lookup of %s failed: status=%d", k, rc); \
} \
} while (0)
@@ -111,8 +112,8 @@
APREQ_DECLARE(const char *)apreq_env_query_string(void *env)
{
dCTX;
- char *value;
- APREQ_ASSERT(apr_env_get(&value, "QUERY_STRING", ctx->pool));
+ char *value, qs[] = "QUERY_STRING";
+ APREQ_ENV_STATUS(apr_env_get(&value, qs, ctx->pool), qs);
return value;
}
@@ -121,7 +122,7 @@
{
dCTX;
char *key = apr_pstrdup(ctx->pool, name);
- char *k, *value;
+ char *k, *value, *http_key, http[] = "HTTP_";
for (k = key; *k; ++k) {
if (*k == '-')
*k = '_';
@@ -129,11 +130,19 @@
*k = apr_toupper(*k);
}
- APREQ_ASSERT(apr_env_get(&value, key, ctx->pool));
+ if (!strcmp(key, "CONTENT_TYPE") || !strcmp(key, "CONTENT_LENGTH")) {
+ APREQ_ENV_STATUS(apr_env_get(&value, key, ctx->pool), key);
+ }
+ else {
+ http_key = (char *) apr_palloc(ctx->pool, sizeof(http) +
strlen(key));
+ http_key = strcat(strcpy(http_key, http), key);
+ APREQ_ENV_STATUS(apr_env_get(&value, http_key, ctx->pool), http_key);
+ }
+
return value;
}
-APREQ_DECLARE(apr_status_t)apreq_env_header_out(void *ctx, const char *name,
+APREQ_DECLARE(apr_status_t)apreq_env_header_out(void *env, const char *name,
char *value)
{
return printf("%s: %s" CRLF, name, value) > 0 ? APR_SUCCESS :
APR_EGENERAL;
@@ -187,15 +196,16 @@
if (ctx->bb == NULL) {
apr_bucket_alloc_t *alloc = apr_bucket_alloc_create(ctx->pool);
apr_file_t *in;
- apr_bucket *stdin_pipe;
+ apr_bucket *stdin_pipe, *b;
ctx->bb = apr_brigade_create(ctx->pool, alloc);
apr_file_open_stdin(&in, ctx->pool);
stdin_pipe = apr_bucket_pipe_create(in,alloc);
APR_BRIGADE_INSERT_HEAD(ctx->bb, stdin_pipe);
+ b = apr_bucket_eos_create(alloc);
+ APR_BRIGADE_INSERT_TAIL(ctx->bb, b);
}
-
- return apreq_parse_request(apreq_request(env,NULL), ctx->bb);
+ return apreq_parse_request(apreq_request(env, NULL), ctx->bb);
}
/** @} */
1.4 +3 -3 httpd-apreq-2/env/cgi_test/t/cgi.t
Index: cgi.t
===================================================================
RCS file: /home/cvs/httpd-apreq-2/env/cgi_test/t/cgi.t,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- cgi.t 20 Oct 2003 04:53:34 -0000 1.3
+++ cgi.t 21 Oct 2003 16:20:17 -0000 1.4
@@ -16,7 +16,7 @@
my @big_key_num = (5, 15, 25);
my @big_keys = ('a'..'z');
-plan tests => 5 + @key_len * @key_num + @big_key_len * @big_key_num;
+plan tests => 8 + @key_len * @key_num + @big_key_len * @big_key_num;
my $script = WIN32 ? '/cgi-bin/cgi_test.exe' : '/cgi-bin/cgi_test';
my $line_end = WIN32 ? "\r\n" : "\n";
@@ -58,7 +58,7 @@
my $query = join ";", @query;
t_debug "# of keys : $big_key_num, big_key_len $big_key_len";
- my $body = POST_BODY($script, content => "$query;$filler");
+ my $body = POST_BODY($script, content => $query);
ok t_cmp($len,
$body,
"POST big data");
@@ -86,7 +86,6 @@
ok t_cmp("\tfoo => 0$line_end",
$body, "simple upload");
-exit;
{
my $test = 'netscape';
@@ -116,6 +115,7 @@
GET_BODY("$script?test=$test&key=$key", Cookie => $cookie),
$test);
}
+exit;
{
my $test = 'bake';
my $key = 'apache';