diff options
| author | Arnaud Le Blanc <lbarnaud@php.net> | 2008-11-13 10:14:04 +0000 |
|---|---|---|
| committer | Arnaud Le Blanc <lbarnaud@php.net> | 2008-11-13 10:14:04 +0000 |
| commit | 8c4151ad72b6c5a82b341aaf59d2c31521ca4341 (patch) | |
| tree | ccc7c01da54fd7f7a02d03d7017e78a359aa254e /sapi/apache2handler/sapi_apache2.c | |
| parent | 06119f4748066e61163764bbb31d1db4b21b6d07 (diff) | |
| download | php-git-8c4151ad72b6c5a82b341aaf59d2c31521ca4341.tar.gz | |
Added header_remove() (chsc at peytz dotdk, Arnaud)
[DOC] proto void header_remove([string header_name])
Removes an HTTP header previously set using header()
The header_name parameter is optionnal, all headers are
removed if it is not set
[SAPIs] The header_handler callback in sapi_module_struct has
been changed, it now take a new argument.
When it is set to SAPI_HEADER_DELETE, sapi_header->header is
the name of an header, header_handler has to delete it.
When it is set to SAPI_HEADER_DELETE_ALL, header_handler has
to delete all headers.
When sapi_header_op_enum is SAPI_HEADER_ADD or _REPLACE,
sapi_header->header is in the form "Name: value", header_handler
has to add or replace the given header.
In all cases, header_handler must not free sapi_header or
sapi_header->header. SAPI_HEADER_ADD must be returned if the
header has been added or replaced, or 0 in other cases.
Diffstat (limited to 'sapi/apache2handler/sapi_apache2.c')
| -rw-r--r-- | sapi/apache2handler/sapi_apache2.c | 61 |
1 files changed, 38 insertions, 23 deletions
diff --git a/sapi/apache2handler/sapi_apache2.c b/sapi/apache2handler/sapi_apache2.c index b8671c59d4..cf2e1427be 100644 --- a/sapi/apache2handler/sapi_apache2.c +++ b/sapi/apache2handler/sapi_apache2.c @@ -83,40 +83,55 @@ php_apache_sapi_ub_write(const char *str, uint str_length TSRMLS_DC) } static int -php_apache_sapi_header_handler(sapi_header_struct *sapi_header,sapi_headers_struct *sapi_headers TSRMLS_DC) +php_apache_sapi_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers TSRMLS_DC) { php_struct *ctx; char *val, *ptr; ctx = SG(server_context); - val = strchr(sapi_header->header, ':'); + switch (op) { + case SAPI_HEADER_DELETE: + apr_table_unset(ctx->r->headers_out, sapi_header->header); + return 0; - if (!val) { - sapi_free_header(sapi_header); - return 0; - } - ptr = val; + case SAPI_HEADER_DELETE_ALL: + apr_table_clear(ctx->r->headers_out); + return 0; + + case SAPI_HEADER_ADD: + case SAPI_HEADER_REPLACE: + val = strchr(sapi_header->header, ':'); - *val = '\0'; + if (!val) { + return 0; + } + ptr = val; + + *val = '\0'; - do { - val++; - } while (*val == ' '); + do { + val++; + } while (*val == ' '); + + if (!strcasecmp(sapi_header->header, "content-type")) { + if (ctx->content_type) { + efree(ctx->content_type); + } + ctx->content_type = estrdup(val); + } else if (op == SAPI_HEADER_REPLACE) { + apr_table_set(ctx->r->headers_out, sapi_header->header, val); + } else { + apr_table_add(ctx->r->headers_out, sapi_header->header, val); + } - if (!strcasecmp(sapi_header->header, "content-type")) { - if (ctx->content_type) { - efree(ctx->content_type); - } - ctx->content_type = estrdup(val); - } else if (sapi_header->replace) { - apr_table_set(ctx->r->headers_out, sapi_header->header, val); - } else { - apr_table_add(ctx->r->headers_out, sapi_header->header, val); + *ptr = ':'; + + return SAPI_HEADER_ADD; + + default: + return 0; } - *ptr = ':'; - - return SAPI_HEADER_ADD; } static int |
