You are here

function soap_server::send_response in Salesforce Suite 5

Same name in this branch
  1. 5 includes/nusoap.php \soap_server::send_response()
  2. 5 includes/nusoap.orig.php \soap_server::send_response()
Same name and namespace in other branches
  1. 5.2 includes/nusoap.php \soap_server::send_response()
  2. 5.2 includes/nusoap.orig.php \soap_server::send_response()

* sends an HTTP response * * The following fields are set by this function (when successful) * * outgoing_headers * response * * @access private

2 calls to soap_server::send_response()
soap_server::service in includes/nusoap.php
* processes request and returns response * *
soap_server::service in includes/nusoap.orig.php
* processes request and returns response * *

File

includes/nusoap.php, line 3712

Class

soap_server
soap_server allows the user to create a SOAP server that is capable of receiving messages and returning responses

Code

function send_response() {
  $this
    ->debug('Enter send_response');
  if ($this->fault) {
    $payload = $this->fault
      ->serialize();
    $this->outgoing_headers[] = "HTTP/1.0 500 Internal Server Error";
    $this->outgoing_headers[] = "Status: 500 Internal Server Error";
  }
  else {
    $payload = $this->responseSOAP;

    // Some combinations of PHP+Web server allow the Status
    // to come through as a header.  Since OK is the default
    // just do nothing.
    // $this->outgoing_headers[] = "HTTP/1.0 200 OK";
    // $this->outgoing_headers[] = "Status: 200 OK";
  }

  // add debug data if in debug mode
  if (isset($this->debug_flag) && $this->debug_flag) {
    $payload .= $this
      ->getDebugAsXMLComment();
  }
  $this->outgoing_headers[] = "Server: {$this->title} Server v{$this->version}";
  ereg('\\$Revisio' . 'n: ([^ ]+)', $this->revision, $rev);
  $this->outgoing_headers[] = "X-SOAP-Server: {$this->title}/{$this->version} (" . $rev[1] . ")";

  // Let the Web server decide about this

  //$this->outgoing_headers[] = "Connection: Close\r\n";
  $payload = $this
    ->getHTTPBody($payload);
  $type = $this
    ->getHTTPContentType();
  $charset = $this
    ->getHTTPContentTypeCharset();
  $this->outgoing_headers[] = "Content-Type: {$type}" . ($charset ? '; charset=' . $charset : '');

  //begin code to compress payload - by John

  // NOTE: there is no way to know whether the Web server will also compress
  // this data.
  if (strlen($payload) > 1024 && isset($this->headers) && isset($this->headers['accept-encoding'])) {
    if (strstr($this->headers['accept-encoding'], 'gzip')) {
      if (function_exists('gzencode')) {
        if (isset($this->debug_flag) && $this->debug_flag) {
          $payload .= "<!-- Content being gzipped -->";
        }
        $this->outgoing_headers[] = "Content-Encoding: gzip";
        $payload = gzencode($payload);
      }
      else {
        if (isset($this->debug_flag) && $this->debug_flag) {
          $payload .= "<!-- Content will not be gzipped: no gzencode -->";
        }
      }
    }
    elseif (strstr($this->headers['accept-encoding'], 'deflate')) {

      // Note: MSIE requires gzdeflate output (no Zlib header and checksum),
      // instead of gzcompress output,
      // which conflicts with HTTP 1.1 spec (http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.5)
      if (function_exists('gzdeflate')) {
        if (isset($this->debug_flag) && $this->debug_flag) {
          $payload .= "<!-- Content being deflated -->";
        }
        $this->outgoing_headers[] = "Content-Encoding: deflate";
        $payload = gzdeflate($payload);
      }
      else {
        if (isset($this->debug_flag) && $this->debug_flag) {
          $payload .= "<!-- Content will not be deflated: no gzcompress -->";
        }
      }
    }
  }

  //end code
  $this->outgoing_headers[] = "Content-Length: " . strlen($payload);
  reset($this->outgoing_headers);
  foreach ($this->outgoing_headers as $hdr) {
    header($hdr, false);
  }
  print $payload;
  $this->response = join("\r\n", $this->outgoing_headers) . "\r\n\r\n" . $payload;
}