|
27 | 27 | #include "SAPI.h"
|
28 | 28 |
|
29 | 29 | #include "ext/standard/php_smart_str.h"
|
| 30 | +#include "ext/standard/php_standard.h" |
30 | 31 |
|
31 | 32 | #include "apr_strings.h"
|
32 | 33 | #include "ap_config.h"
|
@@ -440,12 +441,23 @@ static int php_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
|
440 | 441 | php_apache_request_ctor(f, ctx TSRMLS_CC);
|
441 | 442 |
|
442 | 443 | apr_file_name_get(&path, ((apr_bucket_file *) b->data)->fd);
|
443 |
| - zfd.type = ZEND_HANDLE_FILENAME; |
444 |
| - zfd.filename = (char *) path; |
445 |
| - zfd.free_filename = 0; |
446 |
| - zfd.opened_path = NULL; |
447 |
| - |
448 |
| - php_execute_script(&zfd TSRMLS_CC); |
| 444 | + |
| 445 | + /* Determine if we need to parse the file or show the source */ |
| 446 | + if (!strncmp(ctx->r->handler, "application/x-httpd-php", sizeof("application/x-httpd-php"))) { |
| 447 | + zfd.type = ZEND_HANDLE_FILENAME; |
| 448 | + zfd.filename = (char *) path; |
| 449 | + zfd.free_filename = 0; |
| 450 | + zfd.opened_path = NULL; |
| 451 | + |
| 452 | + php_execute_script(&zfd TSRMLS_CC); |
| 453 | + } else { |
| 454 | + zend_syntax_highlighter_ini syntax_highlighter_ini; |
| 455 | + |
| 456 | + php_get_highlight_struct(&syntax_highlighter_ini); |
| 457 | + |
| 458 | + highlight_file((char *)path, &syntax_highlighter_ini TSRMLS_CC); |
| 459 | + } |
| 460 | + |
449 | 461 | php_apache_request_dtor(f TSRMLS_CC);
|
450 | 462 |
|
451 | 463 | ctx->request_processed = 1;
|
@@ -560,10 +572,13 @@ static void php_add_filter(request_rec *r, ap_filter_t *f)
|
560 | 572 |
|
561 | 573 | static void php_insert_filter(request_rec *r)
|
562 | 574 | {
|
563 |
| - if (r->content_type && |
564 |
| - strcmp(r->content_type, "application/x-httpd-php") == 0) { |
565 |
| - php_add_filter(r, r->output_filters); |
566 |
| - php_add_filter(r, r->input_filters); |
| 575 | + int content_type_len = strlen("application/x-httpd-php"); |
| 576 | + |
| 577 | + if (r->content_type && !strncmp(r->content_type, "application/x-httpd-php", content_type_len-1)) { |
| 578 | + if (r->content_type[content_type_len] == '\0' || !strncmp(r->content_type+content_type_len, "-source", strlen("-source"))) { |
| 579 | + php_add_filter(r, r->output_filters); |
| 580 | + php_add_filter(r, r->input_filters); |
| 581 | + } |
567 | 582 | }
|
568 | 583 | }
|
569 | 584 |
|
|
0 commit comments