charset = SG(default_charset) ? SG(default_charset) : SAPI_DEFAULT_CHARSET;
if (strncasecmp(mimetype, "text/", 5) == 0 && strcasecmp(charset, "none") != 0) {
- int len = strlen(mimetype) + sizeof(";charset=") + strlen(charset);
+ int len = strlen(mimetype) + sizeof("; charset=") + strlen(charset);
content_type = emalloc(len);
- strlcpy(content_type, mimetype, len);
- strlcat(content_type, ";charset=", len);
- strlcat(content_type, charset, len);
+ snprintf(content_type, len, "%s; charset=%s", mimetype, charset);
} else {
content_type = estrdup(mimetype);
}
return content_type;
}
+
+SAPI_API void sapi_get_default_content_type_header(sapi_header_struct *default_header SLS_DC)
+{
+ char *default_content_type = sapi_get_default_content_type(SLS_C);
+ int default_content_type_len = strlen(default_content_type);
+
+ default_header->header_len = (sizeof("Content-type: ")-1) + default_content_type_len;
+ default_header->header = emalloc(default_header->header_len+1);
+ memcpy(default_header->header, "Content-type: ", sizeof("Content-type: "));
+ memcpy(default_header->header+sizeof("Content-type: ")-1, default_content_type, default_content_type_len);
+ default_header->header[default_header->header_len] = 0;
+}
+
/*
* Add charset on content-type header if the MIME type starts with
* "text/", the default_charset directive is not set to "none" and
if (SG(request_info).current_user) {
efree(SG(request_info).current_user);
}
- if (SG(sapi_headers).default_content_type) {
- efree(SG(sapi_headers).default_content_type);
- }
if (sapi_module.deactivate) {
sapi_module.deactivate(SLS_C);
}
}
zend_llist_apply_with_argument(&SG(sapi_headers).headers, (void (*)(void *, void *)) sapi_module.send_header, SG(server_context));
if(SG(sapi_headers).send_default_content_type) {
- if (SG(sapi_headers).default_content_type != NULL) {
- sapi_header_struct default_header;
- int len = SG(sapi_headers).default_content_type_size + sizeof("Content-type: ");
-
- default_header.header = emalloc(len);
- strcpy(default_header.header, "Content-type: ");
- strlcat(default_header.header, SG(sapi_headers).default_content_type, len);
- default_header.header[len - 1] = '\0';
- default_header.header_len = len - 1;
- sapi_module.send_header(&default_header,SG(server_context));
- efree(default_header.header);
- } else {
- sapi_header_struct default_header = { SAPI_DEFAULT_CONTENT_TYPE_HEADER, sizeof(SAPI_DEFAULT_CONTENT_TYPE_HEADER) - 1 };
- sapi_module.send_header(&default_header,SG(server_context));
- }
+ char *default_content_type = sapi_get_default_content_type(SLS_C);
+ int default_content_type_len = strlen(default_content_type);
+ sapi_header_struct default_header;
+
+ sapi_get_default_content_type_header(&default_header SLS_CC);
+ sapi_module.send_header(&default_header, SG(server_context));
+ sapi_free_header(&default_header);
}
sapi_module.send_header(NULL, SG(server_context));
SG(headers_sent) = 1;
typedef struct {
zend_llist headers;
int http_response_code;
- char *default_content_type;
- size_t default_content_type_size;
unsigned char send_default_content_type;
char *http_status_line;
} sapi_headers_struct;
SAPI_API char *sapi_getenv(char *name, int name_len);
SAPI_API char *sapi_get_default_content_type(SLS_D);
+SAPI_API void sapi_get_default_content_type_header(sapi_header_struct *default_header SLS_DC);
SAPI_API size_t sapi_apply_default_charset(char **mimetype, size_t len SLS_DC);
struct _sapi_module_struct {
#define SAPI_DEFAULT_MIMETYPE "text/html"
#define SAPI_DEFAULT_CHARSET "iso-8859-1"
-#define SAPI_DEFAULT_CONTENT_TYPE SAPI_DEFAULT_MIMETYPE ";charset=" SAPI_DEFAULT_CHARSET
-#define SAPI_DEFAULT_CONTENT_TYPE_HEADER "Content-type: " SAPI_DEFAULT_CONTENT_TYPE
#define SAPI_PHP_VERSION_HEADER "X-Powered-By: PHP/" PHP_VERSION
#define SAPI_POST_READER_FUNC(post_reader) void post_reader(SLS_D)
LPEXTENSION_CONTROL_BLOCK lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context);
HSE_SEND_HEADER_EX_INFO header_info;
char status_buf[MAX_STATUS_LENGTH];
- sapi_header_struct default_content_type = { SAPI_DEFAULT_CONTENT_TYPE, sizeof(SAPI_DEFAULT_CONTENT_TYPE)-1 };
+ sapi_header_struct default_content_type;
PLS_FETCH();
/* Obtain headers length */
if (SG(sapi_headers).send_default_content_type) {
+ sapi_get_default_content_type_header(&default_content_type SLS_CC);
accumulate_header_length(&default_content_type, (void *) &total_length);
}
zend_llist_apply_with_argument(&SG(sapi_headers).headers, (void (*)(void *, void *)) accumulate_header_length, (void *) &total_length);
combined_headers_ptr = combined_headers;
if (SG(sapi_headers).send_default_content_type) {
concat_header(&default_content_type, (void *) &combined_headers_ptr);
+ sapi_free_header(&default_content_type); /* we no longer need it */
}
zend_llist_apply_with_argument(&SG(sapi_headers).headers, (void (*)(void *, void *)) concat_header, (void *) &combined_headers_ptr);
*combined_headers_ptr++ = '\r';