You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Stas Bekman <st...@stason.org> on 2003/02/19 04:41:15 UTC
[patch] proper backcompat $r->send_http_header
Currently, $r->send_http_header can't be called before the response stage, so
the 1.0 code won't run out of the box. This is an attempt to solve that problem.
I haven't committed it, because I'm not sure whether the following assumption
will stand:
- wb->header_parse = MpDirPARSE_HEADERS(dcfg) ? 1 : 0;
+ wb->header_parse = (!r->content_type && MpDirPARSE_HEADERS(dcfg)) ? 1 :
What I say is that if the content_type is already set, we don't need to parse
headers. Does it make sense? Or could there be some subtle cases where some
pre-response handler will set the content-type, but the response handler will
be a cgi script that will send a different content-type header? I think that
this is quite possible. In that case I'm not sure how to handle this. We need
a way to tell the response stage to skip headers parsing if send_http_header
was called.
Index: Changes
===================================================================
RCS file: /home/cvs/modperl-2.0/Changes,v
retrieving revision 1.127
diff -u -r1.127 Changes
--- Changes 19 Feb 2003 00:32:45 -0000 1.127
+++ Changes 19 Feb 2003 03:37:17 -0000
@@ -10,6 +10,12 @@
=item 1.99_09-dev
+move $r->send_http_header implementation to Apache::compat. adjust
+modperl_response_init() to parse headers only if told to and
+$r->content_type wasn't set already. This allows the 1.0 code to run
+unchanged if $r->send_http_header is called before the response
+change.
+
add Apache::Bundle2 [Stas]
Apache::Reload now supports the PerlPreConnectionHandler invocation
Index: lib/Apache/compat.pm
===================================================================
RCS file: /home/cvs/modperl-2.0/lib/Apache/compat.pm,v
retrieving revision 1.79
diff -u -r1.79 compat.pm
--- lib/Apache/compat.pm 17 Feb 2003 09:47:31 -0000 1.79
+++ lib/Apache/compat.pm 19 Feb 2003 03:37:17 -0000
@@ -154,6 +154,11 @@
return Apache::current_callback();
}
+sub send_http_header {
+ my ($r, $type) = @_;
+ $r->content_type($type) if defined $type;
+}
+
#to support $r->server_root_relative
*server_root_relative = \&Apache::server_root_relative;
Index: src/modules/perl/mod_perl.c
===================================================================
RCS file: /home/cvs/modperl-2.0/src/modules/perl/mod_perl.c,v
retrieving revision 1.151
diff -u -r1.151 mod_perl.c
--- src/modules/perl/mod_perl.c 4 Feb 2003 06:52:15 -0000 1.151
+++ src/modules/perl/mod_perl.c 19 Feb 2003 03:37:17 -0000
@@ -733,7 +733,7 @@
wb->pool = r->pool;
wb->filters = &r->output_filters;
wb->outcnt = 0;
- wb->header_parse = MpDirPARSE_HEADERS(dcfg) ? 1 : 0;
+ wb->header_parse = (!r->content_type && MpDirPARSE_HEADERS(dcfg)) ? 1 : 0;
wb->r = r;
}
Index: t/response/TestCompat/apache.pm
===================================================================
RCS file: /home/cvs/modperl-2.0/t/response/TestCompat/apache.pm,v
retrieving revision 1.4
diff -u -r1.4 apache.pm
--- t/response/TestCompat/apache.pm 17 Feb 2003 09:03:17 -0000 1.4
+++ t/response/TestCompat/apache.pm 19 Feb 2003 03:37:17 -0000
@@ -55,3 +55,6 @@
1;
+__END__
+# so we can test whether send_httpd_header() works fine
+PerlOptions +ParseHeaders
Index: xs/Apache/Response/Apache__Response.h
===================================================================
RCS file: /home/cvs/modperl-2.0/xs/Apache/Response/Apache__Response.h,v
retrieving revision 1.8
diff -u -r1.8 Apache__Response.h
--- xs/Apache/Response/Apache__Response.h 17 Jan 2003 02:26:31 -0000 1.8
+++ xs/Apache/Response/Apache__Response.h 19 Feb 2003 03:37:17 -0000
@@ -13,28 +13,6 @@
rcfg->wbucket->header_parse = 0; \
}
-/* XXX: should only be part of Apache::compat */
-static MP_INLINE void
-mpxs_Apache__RequestRec_send_http_header(pTHX_ request_rec *r,
- const char *type)
-{
- MP_dRCFG;
-
- if (type) {
- ap_set_content_type(r, apr_pstrdup(r->pool, type));
- }
-
- if (rcfg->wbucket) {
- /* turn off PerlOptions +ParseHeaders */
- rcfg->wbucket->header_parse = 0;
- }
- else {
- /* the response is not initialized yet */
- Perl_croak(aTHX_ "send_http_header() can't be called before "
- "the response phase");
- }
-}
-
static MP_INLINE void
mpxs_Apache__RequestRec_set_last_modified(request_rec *r, apr_time_t mtime)
{
Index: xs/maps/modperl_functions.map
===================================================================
RCS file: /home/cvs/modperl-2.0/xs/maps/modperl_functions.map,v
retrieving revision 1.53
diff -u -r1.53 modperl_functions.map
--- xs/maps/modperl_functions.map 17 Feb 2003 09:03:17 -0000 1.53
+++ xs/maps/modperl_functions.map 19 Feb 2003 03:37:17 -0000
@@ -56,7 +56,6 @@
MODULE=Apache::Response PACKAGE=Apache::RequestRec
DEFINE_send_cgi_header | | request_rec *:r, SV *:buffer
- mpxs_Apache__RequestRec_send_http_header | | r, type=NULL
mpxs_Apache__RequestRec_set_last_modified | | r, mtime=0
Index: xs/tables/current/ModPerl/FunctionTable.pm
===================================================================
RCS file: /home/cvs/modperl-2.0/xs/tables/current/ModPerl/FunctionTable.pm,v
retrieving revision 1.104
diff -u -r1.104 FunctionTable.pm
--- xs/tables/current/ModPerl/FunctionTable.pm 31 Jan 2003 04:20:20 -0000 1.104
+++ xs/tables/current/ModPerl/FunctionTable.pm 19 Feb 2003 03:37:17 -0000
@@ -5529,24 +5529,6 @@
]
},
{
- 'return_type' => '',
- 'name' => 'mpxs_Apache__RequestRec_send_http_header',
- 'args' => [
- {
- 'type' => 'PerlInterpreter *',
- 'name' => 'my_perl'
- },
- {
- 'type' => 'request_rec *',
- 'name' => 'r'
- },
- {
- 'type' => 'const char *',
- 'name' => 'type'
- }
- ]
- },
- {
'return_type' => 'int',
'name' => 'mpxs_Apache__RequestRec_OPEN',
'args' => [
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: [patch] proper backcompat $r->send_http_header
Posted by Stas Bekman <st...@stason.org>.
Geoffrey Young wrote:
>
>
> Stas Bekman wrote:
>
>> Currently, $r->send_http_header can't be called before the response
>> stage, so the 1.0 code won't run out of the box. This is an attempt to
>> solve that problem.
>>
>> I haven't committed it, because I'm not sure whether the following
>> assumption will stand:
>>
>> - wb->header_parse = MpDirPARSE_HEADERS(dcfg) ? 1 : 0;
>> + wb->header_parse = (!r->content_type && MpDirPARSE_HEADERS(dcfg))
>> ? 1 :
>>
>
> can you explain what's going on here? I see that you've made
> compat.pm's send_http_header() almost a no-op, which looks just fine to
> me. I would have thought that was sufficient.
>
> so, what is all the rest of this? can't 2.0 users just rely on the
> header filter to do the work? if 2.0 users call send_http_header() when
> they shouldn't, shouldn't we just throw an error instead of appeasing
> improper use of the API?
>
> or are you talking about legacy 1.0 code running without compat.pm? I
> guess I don't get what's going on here (not that I have to :)
Yes, I'm talking about exactly that. We should turn the headers parsing off,
if 1.0 code has called send_http_header.
We actually need the same functionality for 2.0. Because what happens if there
are two registry scripts running from the same location which is configured to
parse headers? If the script doesn't send headers in plain text, the script
would have failed. I haven't realized that I've already fixed that while
writing a bunch of test scripts for ModPerl::Registry. I did this testing
already at a later stage in:
MP_INLINE apr_status_t modperl_wbucket_pass(modperl_wbucket_t *wb,
const char *buf, apr_size_t len)
{
[...]
if (wb->header_parse && !wb->r->content_type) {
/* parse headers */
[...]
so that solution is needed for both 1.0 and 2.0.
Therefore I go ahead and make send_http_header a NOOP + $r->content_type if it
passes the type. And in the future we will probably see if my solution stands
or not.
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: [patch] proper backcompat $r->send_http_header
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
Stas Bekman wrote:
> Currently, $r->send_http_header can't be called before the response
> stage, so the 1.0 code won't run out of the box. This is an attempt to
> solve that problem.
>
> I haven't committed it, because I'm not sure whether the following
> assumption will stand:
>
> - wb->header_parse = MpDirPARSE_HEADERS(dcfg) ? 1 : 0;
> + wb->header_parse = (!r->content_type && MpDirPARSE_HEADERS(dcfg)) ?
> 1 :
>
can you explain what's going on here? I see that you've made compat.pm's
send_http_header() almost a no-op, which looks just fine to me. I would
have thought that was sufficient.
so, what is all the rest of this? can't 2.0 users just rely on the header
filter to do the work? if 2.0 users call send_http_header() when they
shouldn't, shouldn't we just throw an error instead of appeasing improper
use of the API?
or are you talking about legacy 1.0 code running without compat.pm? I guess
I don't get what's going on here (not that I have to :)
--Geoff
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org