Project

General

Profile

« Previous | Next » 

Revision 104dde69

Added by Andreas Kohlbecker almost 11 years ago

gzip compression optional depending on whether php is compiled with zlib support

View differences:

7.x/modules/cdm_dataportal/cdm_api/cdm_api.module
653 653
 */
654 654
function proxy_content($uri, $hook = NULL) {
655 655
  $args = func_get_args();
656

  
656
  $do_gzip = function_exists('gzencode');
657 657
  $uriEncoded = array_shift($args);
658 658
  $uri = urldecode($uriEncoded);
659 659
  $hook = array_shift($args);
......
719 719

  
720 720
      $obj = cdm_ws_get($uri, NULL, NULL, NULL, TRUE);
721 721

  
722
      $theme_result = NULL;
722
      $reponse_data = NULL;
723 723

  
724 724
      if (function_exists('compose_' . $hook)){
725 725
        // call compose hook
726 726

  
727 727
        $elements =  call_user_func('compose_' . $hook, $obj);
728 728
        // pass the render array to drupal_render()
729
        $theme_result = drupal_render($elements);
729
        $reponse_data = drupal_render($elements);
730 730
      } else {
731 731
        // call theme hook
732 732

  
......
741 741
              'tree_node_callback' => isset($args[2]) ? $args[2] : FALSE,
742 742
              'element_name'=> isset($args[3]) ? $args[3] : FALSE,
743 743
            );
744
            $theme_result = theme($hook, $variables);
744
            $reponse_data = theme($hook, $variables);
745 745
            break;
746 746

  
747 747
          case 'cdm_media_caption':
......
758 758
              ),
759 759
              'fileUri' => isset($args[1]) ? $args[1] : NULL,
760 760
            );
761
            $theme_result = theme($hook, $variables);
761
            $reponse_data = theme($hook, $variables);
762 762
            break;
763 763

  
764 764
          default:
......
770 770
            break;
771 771
        } // END of theme hook switch
772 772
      } // END of tread as theme hook
773

  
774
      $compressed = gzencode($theme_result, 2, FORCE_GZIP);
773
      if($do_gzip){
774
        $reponse_data = gzencode($reponse_data, 2, FORCE_GZIP);
775
        drupal_add_http_header('Content-Length', strlen($reponse_data));
776
      }
775 777
      drupal_add_http_header('Content-Type', 'text/html; charset=utf-8');
776
      drupal_add_http_header('Content-Length', strlen($compressed));
777 778
      drupal_add_http_header('Content-Encoding', 'gzip');
778
      print $compressed;
779
      print $reponse_data;
779 780
    } // END of handle $hook either as compose ot theme hook
780 781
  }
781 782
}

Also available in: Unified diff