receive the response from the server, set @rval, notify caller
357353
def call(hash)
      logger.debug { "continuation req_id #{req_id}, got hash: #{hash.inspect}" }
      @rval = hash.values_at(*METH_TO_ASYNC_RESULT_KEYS.fetch(meth))
      logger.debug { "delivering result #{@rval.inspect}" }
      deliver!
    end
1253509
def _response(status, body=nil, headers={})
      body = [body].compact
      headers = headers.merge("Content-Type" => "application/json")
      Rack::Response.new(body, status, headers).finish
    end
1269252
private void responseClient(RequestResponseClass clazz, Object listener, User user) {
		if(!clazz.isResponseToClient()) return;
		String command = clazz.getResponseCommand();
		ISFSObject params = (ISFSObject) new ParamTransformer(context)
		        .transform(listener).getObject();
		send(command, params, user);
	}
28723
function execute(req, res) {
  req.conn.monitor(this);
  res.send(null, Constants.OK);
}
471471
def _result_handler(self, response: Dict[str, Any]):
        
        res = response.get("MESSAGE")
        ID = res.get("ID")
        result = res.get("RESULT")
        fut = self.tasks.get(ID)
        fut.set_result(result)
        return True
6912
def _notify(self, data):
        """"""
        payload = tlv.decode(
            payload=data.get('payload'),
            content_type=data.get('ct'),
            decode_b64=True
        )
        super(CurrentResourceValue, self)._notify(payload)
        # after one response, close the channel
        self.ensure_stopped()
323073
def _server_response_handler(self, response: Dict[str, Any]):
        
        code = response.get("CODE")
        if code == 100:
            if self.debug:
                print("auth succeed")
            self._login_fut.set_result(response)
        if code == 101:
            if self.debug:
                print('pong')
        return True
177225
def _handle_response(self, msg_id, result=None, error=None):
        """"""
        request_future = self._server_request_futures.pop(msg_id, None)

        if not request_future:
            log.warn("Received response to unknown message id %s", msg_id)
            return

        if error is not None:
            log.debug("Received error response to message %s: %s", msg_id, error)
            request_future.set_exception(JsonRpcException.from_dict(error))

        log.debug("Received result for message %s: %s", msg_id, result)
        request_future.set_result(result)
1070496
def give_response(response, deferred)
      @delayer.new do
        next if deferred.spoiled?
        deferred.exit_await
        fiber.resume(response).accept_request(worker: self,
                                              deferred: deferred)
      end
      nil
    end
811561
function getResponse()
    {
        $this->incoming_payload = '';

        if ($this->io_method() == 'socket') {
            // loop until headers have been retrieved
            $data = '';
            while (!isset($lb)) {

                // We might EOF during header read.
                if (feof($this->fp)) {
                    $this->incoming_payload = $data;
                    $this->debug('found no headers before EOF after length ' . strlen($data));
                    $this->debug("received before EOF:\n" . $data);
                    $this->setError('server failed to send headers');

                    return FALSE;
                }

                $tmp    = fgets($this->fp, 256);
                $tmplen = strlen($tmp);
                $this->debug("read line of $tmplen bytes: " . trim($tmp));

                if ($tmplen == 0) {
                    $this->incoming_payload = $data;
                    $this->debug('socket read of headers timed out after length ' . strlen($data));
                    $this->debug("read before timeout: " . $data);
                    $this->setError('socket read of headers timed out');

                    return FALSE;
                }

                $data .= $tmp;
                $pos  = strpos($data, "\r\n\r\n");
                if ($pos > 1) {
                    $lb = "\r\n";
                } else {
                    $pos = strpos($data, "\n\n");
                    if ($pos > 1) {
                        $lb = "\n";
                    }
                }
                // remove 100 headers
                if (isset($lb) && preg_match('/^HTTP\/1.1 100/', $data)) {
                    unset($lb);
                    $data = '';
                }//
            }
            // store header data
            $this->incoming_payload .= $data;
            $this->debug('found end of headers after length ' . strlen($data));
            // process headers
            $header_data            = trim(substr($data, 0, $pos));
            $header_array           = explode($lb, $header_data);
            $this->incoming_headers = [];
            $this->incoming_cookies = [];
            foreach ($header_array as $header_line) {
                $arr = explode(':', $header_line, 2);
                if (count($arr) > 1) {
                    $header_name                          = strtolower(trim($arr[0]));
                    $this->incoming_headers[$header_name] = trim($arr[1]);
                    if ($header_name == 'set-cookie') {
                        // TODO: allow multiple cookies from parseCookie
                        $cookie = $this->parseCookie(trim($arr[1]));
                        if ($cookie) {
                            $this->incoming_cookies[] = $cookie;
                            $this->debug('found cookie: ' . $cookie['name'] . ' = ' . $cookie['value']);
                        } else {
                            $this->debug('did not find cookie in ' . trim($arr[1]));
                        }
                    }
                } elseif (isset($header_name)) {
                    // append continuation line to previous header
                    $this->incoming_headers[$header_name] .= $lb . ' ' . $header_line;
                }
            }

            // loop until msg has been received
            if (isset($this->incoming_headers['transfer-encoding']) && strtolower($this->incoming_headers['transfer-encoding']) == 'chunked') {
                $content_length = 2147483647;    // ignore any content-length header
                $chunked        = TRUE;
                $this->debug("want to read chunked content");
            } elseif (isset($this->incoming_headers['content-length'])) {
                $content_length = $this->incoming_headers['content-length'];
                $chunked        = FALSE;
                $this->debug("want to read content of length $content_length");
            } else {
                $content_length = 2147483647;
                $chunked        = FALSE;
                $this->debug("want to read content to EOF");
            }
            $data = '';
            do {
                if ($chunked) {
                    $tmp    = fgets($this->fp, 256);
                    $tmplen = strlen($tmp);
                    $this->debug("read chunk line of $tmplen bytes");
                    if ($tmplen == 0) {
                        $this->incoming_payload = $data;
                        $this->debug('socket read of chunk length timed out after length ' . strlen($data));
                        $this->debug("read before timeout:\n" . $data);
                        $this->setError('socket read of chunk length timed out');

                        return FALSE;
                    }
                    $content_length = hexdec(trim($tmp));
                    $this->debug("chunk length $content_length");
                }
                $strlen = 0;
                while (($strlen < $content_length) && (!feof($this->fp))) {
                    $readlen = min(8192, $content_length - $strlen);
                    $tmp     = fread($this->fp, $readlen);
                    $tmplen  = strlen($tmp);
                    $this->debug("read buffer of $tmplen bytes");
                    if (($tmplen == 0) && (!feof($this->fp))) {
                        $this->incoming_payload = $data;
                        $this->debug('socket read of body timed out after length ' . strlen($data));
                        $this->debug("read before timeout:\n" . $data);
                        $this->setError('socket read of body timed out');

                        return FALSE;
                    }
                    $strlen += $tmplen;
                    $data   .= $tmp;
                }
                if ($chunked && ($content_length > 0)) {
                    $tmp    = fgets($this->fp, 256);
                    $tmplen = strlen($tmp);
                    $this->debug("read chunk terminator of $tmplen bytes");
                    if ($tmplen == 0) {
                        $this->incoming_payload = $data;
                        $this->debug('socket read of chunk terminator timed out after length ' . strlen($data));
                        $this->debug("read before timeout:\n" . $data);
                        $this->setError('socket read of chunk terminator timed out');

                        return FALSE;
                    }
                }
            }
            while ($chunked && ($content_length > 0) && (!feof($this->fp)));
            if (feof($this->fp)) {
                $this->debug('read to EOF');
            }
            $this->debug('read body of length ' . strlen($data));
            $this->incoming_payload .= $data;
            $this->debug('received a total of ' . strlen($this->incoming_payload) . ' bytes of data from server');

            // close filepointer
            if (
                (isset($this->incoming_headers['connection']) && strtolower($this->incoming_headers['connection']) == 'close') ||
                (!$this->persistentConnection) || feof($this->fp)
            ) {
                fclose($this->fp);
                $this->fp = FALSE;
                $this->debug('closed socket');
            }

            // connection was closed unexpectedly
            if ($this->incoming_payload == '') {
                $this->setError('no response from server');

                return FALSE;
            }

            // decode transfer-encoding
//		if(isset($this->incoming_headers['transfer-encoding']) && strtolower($this->incoming_headers['transfer-encoding']) == 'chunked'){
//			if(!$data = $this->decodeChunked($data, $lb)){
//				$this->setError('Decoding of chunked data failed');
//				return false;
//			}
            //print "<pre>\nde-chunked:\n---------------\n$data\n\n---------------\n</pre>";
            // set decoded payload
//			$this->incoming_payload = $header_data.$lb.$lb.$data;
//		}

        } elseif ($this->io_method() == 'curl') {
            // send and receive
            $this->debug('send and receive with cURL');
            $this->incoming_payload = curl_exec($this->ch);
            $data                   = $this->incoming_payload;

            $cErr = curl_error($this->ch);
            if ($cErr != '') {
                $err = 'cURL ERROR: ' . curl_errno($this->ch) . ': ' . $cErr . '<br>';
                // TODO: there is a PHP bug that can cause this to SEGV for CURLINFO_CONTENT_TYPE
                foreach (curl_getinfo($this->ch) as $k => $v) {
                    if (is_array($v)) {
                        $this->debug("$k: " . json_encode($v));
                    } else {
                        $this->debug("$k: $v<br>");
                    }
                }
                $this->debug($err);
                $this->setError($err);
                curl_close($this->ch);

                return FALSE;
            } else {
                //echo '<pre>';
                //var_dump(curl_getinfo($this->ch));
                //echo '</pre>';
            }
            // close curl
            $this->debug('No cURL error, closing cURL');
            curl_close($this->ch);

            // try removing skippable headers
            $savedata = $data;
            while ($this->isSkippableCurlHeader($data)) {
                $this->debug("Found HTTP header to skip");
                if ($pos = strpos($data, "\r\n\r\n")) {
                    $data = ltrim(substr($data, $pos));
                } elseif ($pos = strpos($data, "\n\n")) {
                    $data = ltrim(substr($data, $pos));
                }
            }

            if ($data == '') {
                // have nothing left; just remove 100 header(s)
                $data = $savedata;
                while (preg_match('/^HTTP\/1.1 100/', $data)) {
                    if ($pos = strpos($data, "\r\n\r\n")) {
                        $data = ltrim(substr($data, $pos));
                    } elseif ($pos = strpos($data, "\n\n")) {
                        $data = ltrim(substr($data, $pos));
                    }
                }
            }

            // separate content from HTTP headers
            if ($pos = strpos($data, "\r\n\r\n")) {
                $lb = "\r\n";
            } elseif ($pos = strpos($data, "\n\n")) {
                $lb = "\n";
            } else {
                $this->debug('no proper separation of headers and document');
                $this->setError('no proper separation of headers and document');

                return FALSE;
            }
            $header_data  = trim(substr($data, 0, $pos));
            $header_array = explode($lb, $header_data);
            $data         = ltrim(substr($data, $pos));
            $this->debug('found proper separation of headers and document');
            $this->debug('cleaned data, stringlen: ' . strlen($data));
            // clean headers
            foreach ($header_array as $header_line) {
                $arr = explode(':', $header_line, 2);
                if (count($arr) > 1) {
                    $header_name                          = strtolower(trim($arr[0]));
                    $this->incoming_headers[$header_name] = trim($arr[1]);
                    if ($header_name == 'set-cookie') {
                        // TODO: allow multiple cookies from parseCookie
                        $cookie = $this->parseCookie(trim($arr[1]));
                        if ($cookie) {
                            $this->incoming_cookies[] = $cookie;
                            $this->debug('found cookie: ' . $cookie['name'] . ' = ' . $cookie['value']);
                        } else {
                            $this->debug('did not find cookie in ' . trim($arr[1]));
                        }
                    }
                } elseif (isset($header_name)) {
                    // append continuation line to previous header
                    $this->incoming_headers[$header_name] .= $lb . ' ' . $header_line;
                }
            }
        }

        $this->response_status_line = $header_array[0];
        $arr                        = explode(' ', $this->response_status_line, 3);
        $http_version               = $arr[0];
        $http_status                = intval($arr[1]);
        $http_reason                = count($arr) > 2 ? $arr[2] : '';

        // see if we need to resend the request with http digest authentication
        if (isset($this->incoming_headers['location']) && ($http_status == 301 || $http_status == 302)) {
            $this->debug("Got $http_status $http_reason with Location: " . $this->incoming_headers['location']);
            $this->setURL($this->incoming_headers['location']);
            $this->tryagain = TRUE;

            return FALSE;
        }

        // see if we need to resend the request with http digest authentication
        if (isset($this->incoming_headers['www-authenticate']) && $http_status == 401) {
            $this->debug("Got 401 $http_reason with WWW-Authenticate: " . $this->incoming_headers['www-authenticate']);
            if (strstr($this->incoming_headers['www-authenticate'], "Digest ")) {
                $this->debug('Server wants digest authentication');
                // remove "Digest " from our elements
                $digestString = str_replace('Digest ', '', $this->incoming_headers['www-authenticate']);

                // parse elements into array
                $digestElements = explode(',', $digestString);
                foreach ($digestElements as $val) {
                    $tempElement                    = explode('=', trim($val), 2);
                    $digestRequest[$tempElement[0]] = str_replace("\"", '', $tempElement[1]);
                }

                // should have (at least) qop, realm, nonce
                if (isset($digestRequest['nonce'])) {
                    $this->setCredentials($this->username, $this->password, 'digest', $digestRequest);
                    $this->tryagain = TRUE;

                    return FALSE;
                }
            }
            $this->debug('HTTP authentication failed');
            $this->setError('HTTP authentication failed');

            return FALSE;
        }

        if (
            ($http_status >= 300 && $http_status <= 307) ||
            ($http_status >= 400 && $http_status <= 417) ||
            ($http_status >= 501 && $http_status <= 505)
        ) {
            $this->setError("Unsupported HTTP response status $http_status $http_reason (soapclient->response has contents of the response)");

            return FALSE;
        }

        // decode content-encoding
        if (isset($this->incoming_headers['content-encoding']) && $this->incoming_headers['content-encoding'] != '') {
            if (strtolower($this->incoming_headers['content-encoding']) == 'deflate' || strtolower($this->incoming_headers['content-encoding']) == 'gzip') {
                // if decoding works, use it. else assume data wasn't gzencoded
                if (function_exists('gzinflate')) {
                    //$timer->setMarker('starting decoding of gzip/deflated content');
                    // IIS 5 requires gzinflate instead of gzuncompress (similar to IE 5 and gzdeflate v. gzcompress)
                    // this means there are no Zlib headers, although there should be
                    $this->debug('The gzinflate function exists');
                    $datalen = strlen($data);
                    if ($this->incoming_headers['content-encoding'] == 'deflate') {
                        if ($degzdata = @gzinflate($data)) {
                            $data = $degzdata;
                            $this->debug('The payload has been inflated to ' . strlen($data) . ' bytes');
                            if (strlen($data) < $datalen) {
                                // test for the case that the payload has been compressed twice
                                $this->debug('The inflated payload is smaller than the gzipped one; try again');
                                if ($degzdata = @gzinflate($data)) {
                                    $data = $degzdata;
                                    $this->debug('The payload has been inflated again to ' . strlen($data) . ' bytes');
                                }
                            }
                        } else {
                            $this->debug('Error using gzinflate to inflate the payload');
                            $this->setError('Error using gzinflate to inflate the payload');
                        }
                    } elseif ($this->incoming_headers['content-encoding'] == 'gzip') {
                        if ($degzdata = @gzinflate(substr($data, 10))) {    // do our best
                            $data = $degzdata;
                            $this->debug('The payload has been un-gzipped to ' . strlen($data) . ' bytes');
                            if (strlen($data) < $datalen) {
                                // test for the case that the payload has been compressed twice
                                $this->debug('The un-gzipped payload is smaller than the gzipped one; try again');
                                if ($degzdata = @gzinflate(substr($data, 10))) {
                                    $data = $degzdata;
                                    $this->debug('The payload has been un-gzipped again to ' . strlen($data) . ' bytes');
                                }
                            }
                        } else {
                            $this->debug('Error using gzinflate to un-gzip the payload');
                            $this->setError('Error using gzinflate to un-gzip the payload');
                        }
                    }
                    //$timer->setMarker('finished decoding of gzip/deflated content');
                    //print "<xmp>\nde-inflated:\n---------------\n$data\n-------------\n</xmp>";
                    // set decoded payload
                    $this->incoming_payload = $header_data . $lb . $lb . $data;
                } else {
                    $this->debug('The server sent compressed data. Your php install must have the Zlib extension compiled in to support this.');
                    $this->setError('The server sent compressed data. Your php install must have the Zlib extension compiled in to support this.');
                }
            } else {
                $this->debug('Unsupported Content-Encoding ' . $this->incoming_headers['content-encoding']);
                $this->setError('Unsupported Content-Encoding ' . $this->incoming_headers['content-encoding']);
            }
        } else {
            $this->debug('No Content-Encoding header');
        }

        if (strlen($data) == 0) {
            $this->debug('no data after headers!');
            $this->setError('no data present after HTTP headers');

            return FALSE;
        }

        return $data;
    }
767162
function receive(msg) {
  var requests = [];
  var responses = [];

  if (!this.active) {
    return this;
  }

  // If we got JSON, parse it
  if (typeof msg === 'string') {
    try {
      msg = JSON.parse(msg);
    } catch (e) {
      // The specification doesn't force us to respond in error, ignoring
      return this;
    }
  }

  // If we get a standard single-type batch, dispatch it
  if (msg.constructor === Array) {
    if (msg.length === 0) {
      return this;
    }
    // Hint of request batch
    if (typeof msg[0].method === 'string') {
      requests = msg;
    } else {
      responses = msg;
    }
  } else if (typeof msg === 'object') {
    // Could we be a 'dual-batch' extended message?
    if (
      typeof msg.requests !== 'undefined'
      && typeof msg.responses !== 'undefined'
    ) {
      requests = msg.requests;
      responses = msg.responses;
    } else if (typeof msg.method === 'string') {
      // We're a single request
      requests.push(msg);
    } else {
      // We must be a single response
      responses.push(msg);
    }
  }

  responses.forEach(deliverResponse.bind(this));
  requests.forEach(serveRequest.bind(this));
  return this;
}
161611
def _read_response(self):
    
    result = self.buf.read_line().decode("utf-8")
    if not result:
      raise NoResponseError("No response received from server.")

    msg = self._read_message()
    if result != "ok":
      raise InvalidResponseError(msg)

    return msg
531502
function emit(retry) {
    if (self._interrupted) {
      // The request's callback will already have been called.
      return;
    }

    var hreq = self._createHandshakeRequest(adapter, !retry);

    var writable = self._writableFactory.call(self, function (err, readable) {
      if (err) {
        cb(err);
        return;
      }
      readable.on('data', function (obj) {
        debug('received response %s', obj.id);
        // We don't check that the prefix matches since the ID likely hasn't
        // been propagated to the response (see default stateless codec).
        var buf = Buffer.concat(obj.payload);
        try {
          var parts = readHead(HANDSHAKE_RESPONSE_TYPE, buf);
          var hres = parts.head;
          if (hres.serverHash) {
            adapter = self._getAdapter(hres);
          }
        } catch (err) {
          cb(err);
          return;
        }
        self.emit('handshake', hreq, hres);
        if (hres.match === 'NONE') {
          process.nextTick(function() { emit(true); });
          return;
        }
        // Change the default adapter.
        self._adapter = adapter;
        cb(null, parts.tail, adapter);
      });
    });

    writable.write({
      id: id,
      payload: [HANDSHAKE_REQUEST_TYPE.toBuffer(hreq), reqBuf]
    });
    if (self._endWritable) {
      writable.end();
    }
  }
524244
def Receive(self, replytype, **kw):
        '''
        ''' 
        self.ReceiveSOAP(**kw)
        ps = self.ps
        tp = _find_type(ps.body_root)
        isarray = ((type(tp) in (tuple,list) and tp[1] == 'Array') or _find_arraytype(ps.body_root))
        if self.typesmodule is None or isarray:
            return _Binding.Receive(self, replytype, **kw)

        if ps.IsAFault():
            msg = FaultFromFaultMessage(ps)
            raise FaultException(msg)

        tc = replytype
        if hasattr(replytype, 'typecode'):
            tc = replytype.typecode

        #Ignore response wrapper
        reply = {}
        for elt in _child_elements(ps.body_root):
            name = str(elt.localName)
            reply[name] = self.__parse_child(elt)

        if self.address is not None:
            self.address.checkResponse(ps, kw.get('wsaction'))

        return reply
277509
def handleResponseEnd(self):
        
        try:
            if not self._finished:
                reactor.callInThread(
                    self.resource.cacheContent,
                    self.father,
                    self._response,
                    self.buffer
                )
            proxy.ProxyClient.handleResponseEnd(self)
        except RuntimeError:
            # because we don't care if the user hits
            # refresh before the request is done
            pass
7603
def on_headers(self, response, exc=None):
        ''''''

        if response.status_code == 101:
            connection = response.connection
            request = response.request
            handler = request.websocket_handler
            if not handler:
                handler = WS()
            parser = request.client.frame_parser(kind=1)
            consumer = partial(WebSocketClient.create,
                               response, handler, parser)
            connection.upgrade(consumer)
            response.event('post_request').fire()
            websocket = connection.current_consumer()
            response.request_again = lambda r: websocket
1079100
function sendResponse (err, resources) {
    // Extract the "data" of each Resource
    resources = _.map(resources, "data");

    // Use the current date/time as the "last-modified" header
    res.swagger.lastModified = new Date();

    // Set the response body (unless it's already been set by other middleware)
    if (err || res.body) {
      next(err);
    }
    else if (!res.swagger.isCollection) {
      // Response body is a single value, so only return the first item in the collection
      res.body = _.first(resources);
      next();
    }
    else {
      // Response body is the resource that was created/update/deleted
      res.body = resources;
      next();
    }
  }