[svn:mod_parrot] r483 - in mod_parrot/trunk: lib lib/ModParrot/Apache src t/response/TestAPI

[email protected] Sun, 9 Nov 2008 08:23:11 -0800 (PST)
Newsgroups perl.cvs.mod_parrot
Message-ID <[email protected]>
Author: jhorwitz
Date: Sun Nov  9 08:23:09 2008
New Revision: 483

Modified:
   mod_parrot/trunk/lib/ModParrot/Apache/RequestRec.pir
   mod_parrot/trunk/lib/mod_parrot.pir
   mod_parrot/trunk/src/nci.c
   mod_parrot/trunk/t/response/TestAPI/request_rec.pir

Log:
add header accessor methods and tests


Modified: mod_parrot/trunk/lib/ModParrot/Apache/RequestRec.pir
==============================================================================
--- mod_parrot/trunk/lib/ModParrot/Apache/RequestRec.pir	(original)
+++ mod_parrot/trunk/lib/ModParrot/Apache/RequestRec.pir	Sun Nov  9 08:23:09 2008
@@ -538,6 +538,86 @@
     .return(dircfg)
 .end
 
+=back
+
+=item C<PMC headers_in()>
+
+=over 4
+
+Return the request headers as an APR;Table object.
+
+=back
+
+=cut
+
+.sub headers_in :method
+    .local pmc headers, table, func, r
+
+    func = get_root_global ['ModParrot'; 'NCI'], 'request_rec_headers_in'
+    getattribute r, self, 'r'
+    headers = func(r)
+
+    $P0 = get_class [ 'ModParrot'; 'APR'; 'Table' ]
+    $P1 = new 'Hash'
+    $P1['apr_table'] = headers
+    table = new $P0, $P1
+
+    .return(table)
+.end
+
+=item C<PMC headers_out()>
+
+=over 4
+
+Return the response headers as an APR;Table object.
+
+=back
+
+=cut
+
+.sub headers_out :method
+    .local pmc headers, table, func, r
+
+    func = get_root_global ['ModParrot'; 'NCI'], 'request_rec_headers_out'
+    getattribute r, self, 'r'
+    headers = func(r)
+
+    $P0 = get_class [ 'ModParrot'; 'APR'; 'Table' ]
+    $P1 = new 'Hash'
+    $P1['apr_table'] = headers
+    table = new $P0, $P1
+
+    .return(table)
+.end
+
+=item C<PMC err_headers_out()>
+
+=over 4
+
+Return the non-200 response headers as an APR;Table object.  Persists across
+internal redirects.
+
+=back
+
+=cut
+
+.sub err_headers_out :method
+    .local pmc headers, table, func, r
+
+    func = get_root_global ['ModParrot'; 'NCI'], 'request_rec_err_headers_out'
+    getattribute r, self, 'r'
+    headers = func(r)
+
+    $P0 = get_class [ 'ModParrot'; 'APR'; 'Table' ]
+    $P1 = new 'Hash'
+    $P1['apr_table'] = headers
+    table = new $P0, $P1
+
+    .return(table)
+.end
+
+=back
+
 =head1 AUTHOR
 
 Jeff Horwitz

Modified: mod_parrot/trunk/lib/mod_parrot.pir
==============================================================================
--- mod_parrot/trunk/lib/mod_parrot.pir	(original)
+++ mod_parrot/trunk/lib/mod_parrot.pir	Sun Nov  9 08:23:09 2008
@@ -54,6 +54,15 @@
     dlfunc func, nul, "mpnci_request_rec_per_dir_config", "pJp"
     set_root_global [ 'ModParrot'; 'NCI' ], "request_rec_per_dir_config", func
 
+    dlfunc func, nul, "mpnci_request_rec_headers_in", "pJp"
+    set_root_global [ 'ModParrot'; 'NCI' ], "request_rec_headers_in", func
+
+    dlfunc func, nul, "mpnci_request_rec_headers_out", "pJp"
+    set_root_global [ 'ModParrot'; 'NCI' ], "request_rec_headers_out", func
+
+    dlfunc func, nul, "mpnci_request_rec_err_headers_out", "pJp"
+    set_root_global [ 'ModParrot'; 'NCI' ], "request_rec_err_headers_out", func
+
     dlfunc func, nul, "mpnci_rwrite", "iJPip"
     set_root_global [ 'ModParrot'; 'NCI' ], "rwrite", func
 

Modified: mod_parrot/trunk/src/nci.c
==============================================================================
--- mod_parrot/trunk/src/nci.c	(original)
+++ mod_parrot/trunk/src/nci.c	Sun Nov  9 08:23:09 2008
@@ -134,6 +134,22 @@
     return(r->notes);
 }
 
+apr_table_t *mpnci_request_rec_headers_in(Parrot_Interp interp, request_rec *r)
+{
+    return(r->headers_in);
+}
+
+apr_table_t *mpnci_request_rec_headers_out(Parrot_Interp interp, request_rec *r)
+{
+    return(r->headers_out);
+}
+
+apr_table_t *mpnci_request_rec_err_headers_out(Parrot_Interp interp,
+                                               request_rec *r)
+{
+    return(r->err_headers_out);
+}
+
 /* We implement ap_get_basic_auth_pw as a wrapper because there is no NCI
  * signature type that handles the function's char ** password parameter.
  * Instead, we return the results in a PMC array passed in from the caller.

Modified: mod_parrot/trunk/t/response/TestAPI/request_rec.pir
==============================================================================
--- mod_parrot/trunk/t/response/TestAPI/request_rec.pir	(original)
+++ mod_parrot/trunk/t/response/TestAPI/request_rec.pir	Sun Nov  9 08:23:09 2008
@@ -9,7 +9,7 @@
 
     ap_const = get_root_global [ 'ModParrot'; 'Apache'; 'Constants' ], 'table'
 
-    r.'puts'("1..34\n")
+    r.'puts'("1..37\n")
 
   # XXX this should be fatal on failure
   START_1:
@@ -383,10 +383,46 @@
     pop_eh
     if $I0 == 0 goto OK_34
   NOT_OK_34:
-    r.'puts("not ")
+    r.'puts'("not ")
   OK_34:
     r.'puts'("ok 34 - null read()\n")
 
+  START_35:
+    push_eh NOT_OK_35
+    $P0 = r.'headers_in'()
+    pop_eh
+    $S0 = typeof $P0
+    printerr $S0
+    if $S0 == 'ModParrot;APR;Table' goto OK_35
+  NOT_OK_35:
+    r.'puts'("not ")
+  OK_35:
+    r.'puts'("ok 35 - headers_in()\n")
+
+  START_36:
+    push_eh NOT_OK_36
+    $P0 = r.'headers_out'()
+    pop_eh
+    $S0 = typeof $P0
+    printerr $S0
+    if $S0 == 'ModParrot;APR;Table' goto OK_36
+  NOT_OK_36:
+    r.'puts'("not ")
+  OK_36:
+    r.'puts'("ok 36 - headers_in()\n")
+
+  START_37:
+    push_eh NOT_OK_37
+    $P0 = r.'err_headers_out'()
+    pop_eh
+    $S0 = typeof $P0
+    printerr $S0
+    if $S0 == 'ModParrot;APR;Table' goto OK_37
+  NOT_OK_37:
+    r.'puts'("not ")
+  OK_37:
+    r.'puts'("ok 37 - headers_in()\n")
+
     # STILL TODO (not tested in original client-side tests)
     # assbackwards
     # proxyreq