summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cgi_main.c28
-rw-r--r--ext/standard/head.c4
-rw-r--r--main.h2
-rw-r--r--main/SAPI.c7
-rw-r--r--main/SAPI.h2
-rw-r--r--main/main.c11
-rw-r--r--output.c4
-rw-r--r--output.h4
8 files changed, 45 insertions, 17 deletions
diff --git a/cgi_main.c b/cgi_main.c
index 792e2fe9c6..4f4b41bba1 100644
--- a/cgi_main.c
+++ b/cgi_main.c
@@ -76,6 +76,15 @@ static int zend_cgibin_ub_write(const char *str, uint str_length)
}
+static void sapi_cgi_send_header(sapi_header_struct *sapi_header, void *server_context)
+{
+ if (sapi_header) {
+ PHPWRITE_H(sapi_header->header, sapi_header->header_len);
+ }
+ PHPWRITE_H("\r\n", 2);
+}
+
+
static sapi_module_struct sapi_module = {
"PHP Language", /* name */
@@ -83,6 +92,10 @@ static sapi_module_struct sapi_module = {
php_module_shutdown_wrapper, /* shutdown */
zend_cgibin_ub_write, /* unbuffered write */
+
+ NULL, /* header handler */
+ NULL, /* send headers handler */
+ sapi_cgi_send_header, /* send header handler */
};
@@ -117,8 +130,15 @@ static void php_cgi_usage(char *argv0)
static void init_request_info(SLS_D)
{
+ char *request_method = getenv("REQUEST_METHOD");
+
SG(request_info).query_string = getenv("QUERY_STRING");
SG(request_info).request_uri = getenv("PATH_INFO");
+ if (request_method && !strcmp(request_method, "HEAD")) {
+ SG(request_info).headers_only = 1;
+ } else {
+ SG(request_info).headers_only = 0;
+ }
}
@@ -215,7 +235,7 @@ any .htaccess restrictions anywhere on your site you can leave doc_root undefine
switch (c) {
case 'f':
if (!_cgi_started){
- if (php_request_startup(CLS_C ELS_CC PLS_CC)==FAILURE) {
+ if (php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC)==FAILURE) {
php_module_shutdown();
return FAILURE;
}
@@ -228,7 +248,7 @@ any .htaccess restrictions anywhere on your site you can leave doc_root undefine
break;
case 'v':
if (!_cgi_started) {
- if (php_request_startup(CLS_C ELS_CC PLS_CC)==FAILURE) {
+ if (php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC)==FAILURE) {
php_module_shutdown();
return FAILURE;
}
@@ -238,7 +258,7 @@ any .htaccess restrictions anywhere on your site you can leave doc_root undefine
break;
case 'i':
if (!_cgi_started) {
- if (php_request_startup(CLS_C ELS_CC PLS_CC)==FAILURE) {
+ if (php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC)==FAILURE) {
php_module_shutdown();
return FAILURE;
}
@@ -286,7 +306,7 @@ any .htaccess restrictions anywhere on your site you can leave doc_root undefine
#endif
if (!_cgi_started) {
- if (php_request_startup(CLS_C ELS_CC PLS_CC)==FAILURE) {
+ if (php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC)==FAILURE) {
php_module_shutdown();
return FAILURE;
}
diff --git a/ext/standard/head.c b/ext/standard/head.c
index d2cd7eeb07..8e757a3e07 100644
--- a/ext/standard/head.c
+++ b/ext/standard/head.c
@@ -76,7 +76,7 @@ PHPAPI void php3_noheader(void)
}
-#ifndef ZTS
+#ifdef APACHE
/* Adds header information */
void php4i_add_header_information(char *header_information, uint header_length)
{
@@ -227,7 +227,7 @@ void php3_Header(INTERNAL_FUNCTION_PARAMETERS)
-#ifndef ZTS
+#ifdef APACHE
/*
* php3_header() flushes the header info built up using calls to
* the Header() function. If type is 1, a redirect to str is done.
diff --git a/main.h b/main.h
index df3455c9c9..3bf385f976 100644
--- a/main.h
+++ b/main.h
@@ -39,7 +39,7 @@
#include "php_globals.h"
#include "SAPI.h"
-PHPAPI int php_request_startup(CLS_D ELS_DC PLS_DC);
+PHPAPI int php_request_startup(CLS_D ELS_DC PLS_DC SLS_DC);
PHPAPI void php_request_shutdown(void *dummy);
PHPAPI void php_request_shutdown_for_exec(void *dummy);
PHPAPI int php_module_startup(sapi_module_struct *sf);
diff --git a/main/SAPI.c b/main/SAPI.c
index 12499aee3b..af8f1f0b39 100644
--- a/main/SAPI.c
+++ b/main/SAPI.c
@@ -97,6 +97,7 @@ SAPI_API int sapi_add_header(const char *header_line, uint header_line_len)
SAPI_API int sapi_send_headers()
{
int retval;
+ sapi_header_struct default_header = { DEFAULT_CONTENT_TYPE, sizeof(DEFAULT_CONTENT_TYPE)-1 };
SLS_FETCH();
if (SG(headers_sent)) {
@@ -115,7 +116,13 @@ SAPI_API int sapi_send_headers()
return SUCCESS;
break;
case SAPI_HEADER_DO_SEND:
+ if (SG(sapi_headers).content_type.header) {
+ sapi_module.send_header(&SG(sapi_headers).content_type, SG(server_context));
+ } else {
+ sapi_module.send_header(&default_header, SG(server_context));
+ }
zend_llist_apply_with_argument(&SG(sapi_headers).headers, (void (*)(void *, void *)) sapi_module.send_header, SG(server_context));
+ sapi_module.send_header(NULL, SG(server_context));
SG(headers_sent) = 1;
return SUCCESS;
break;
diff --git a/main/SAPI.h b/main/SAPI.h
index 58ef0c081a..b6e225257d 100644
--- a/main/SAPI.h
+++ b/main/SAPI.h
@@ -90,7 +90,7 @@ struct _sapi_module_struct {
int (*header_handler)(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers);
int (*send_headers)(sapi_headers_struct *sapi_headers SLS_DC);
- void (*send_header)(void *server_context, sapi_header_struct *sapi_header);
+ void (*send_header)(sapi_header_struct *sapi_header, void *server_context);
};
diff --git a/main/main.c b/main/main.c
index d1ccc629e4..60d4bab7a2 100644
--- a/main/main.c
+++ b/main/main.c
@@ -597,7 +597,7 @@ static void php_message_handler_for_zend(long message, void *data)
-int php_request_startup(CLS_D ELS_DC PLS_DC)
+int php_request_startup(CLS_D ELS_DC PLS_DC SLS_DC)
{
PG(unclean_shutdown) = 0;
@@ -628,12 +628,11 @@ int php_request_startup(CLS_D ELS_DC PLS_DC)
php3_printf("Unable to initialize request info.\n");
return FAILURE;
}
-
+ sapi_activate(SLS_C);
init_compiler(CLS_C ELS_CC);
init_executor(CLS_C ELS_CC);
startup_scanner(CLS_C);
-
return SUCCESS;
}
@@ -661,11 +660,11 @@ void php_request_shutdown(void *dummy)
CLS_FETCH();
ELS_FETCH();
PLS_FETCH();
+ SLS_FETCH();
php3_header();
zend_end_ob_buffering(1);
-
php3_call_shutdown_functions();
php_ini_rshutdown();
@@ -679,6 +678,8 @@ void php_request_shutdown(void *dummy)
php3_unset_timeout();
+ sapi_deactivate(SLS_C);
+
#if CGI_BINARY
fflush(stdout);
if(request_info.php_argv0) {
@@ -1193,7 +1194,7 @@ PHPAPI int apache_php3_module_main(request_rec *r, int fd, int display_source_mo
SG(server_context) = r;
- if (php_request_startup(CLS_C ELS_CC PLS_CC) == FAILURE) {
+ if (php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC) == FAILURE) {
return FAILURE;
}
php3_TreatHeaders();
diff --git a/output.c b/output.c
index 327ed06fb8..d7ffcc981e 100644
--- a/output.c
+++ b/output.c
@@ -19,8 +19,8 @@
#include "SAPI.h"
/* output functions */
-int (*zend_body_write)(const char *str, uint str_length); /* string output */
-int (*zend_header_write)(const char *str, uint str_length); /* unbuffer string output */
+PHPAPI int (*zend_body_write)(const char *str, uint str_length); /* string output */
+PHPAPI int (*zend_header_write)(const char *str, uint str_length); /* unbuffer string output */
static int zend_ub_body_write(const char *str, uint str_length);
static int zend_ub_body_write_no_header(const char *str, uint str_length);
static int zend_b_body_write(const char *str, uint str_length);
diff --git a/output.h b/output.h
index ae6602351b..b7523d645d 100644
--- a/output.h
+++ b/output.h
@@ -6,8 +6,8 @@
PHPAPI void zend_output_startup();
/* exported output functions */
-int (*zend_body_write)(const char *str, uint str_length); /* string output */
-int (*zend_header_write)(const char *str, uint str_length); /* unbuffer string output */
+PHPAPI int (*zend_body_write)(const char *str, uint str_length); /* string output */
+PHPAPI int (*zend_header_write)(const char *str, uint str_length); /* unbuffer string output */
void zend_start_ob_buffering();
void zend_end_ob_buffering(int send_buffer);
int zend_ob_get_buffer(pval *p);