Send a response back to the client
 Response can be a symbol indicating the status code or a Reel::Response
497534
def respond(response, headers_or_body = {}, body = nil)
      raise StateError, "not in header state" if @response_state != :headers

      if headers_or_body.is_a? Hash
        headers = headers_or_body
      else
        headers = {}
        body = headers_or_body
      end

      if @keepalive
        headers[CONNECTION] = KEEP_ALIVE
      else
        headers[CONNECTION] = CLOSE
      end

      case response
      when Symbol, Fixnum, Integer
        response = Response.new(response, headers, body)
      when Response
      else raise TypeError, "invalid response: #{response.inspect}"
      end

      if current_request
        current_request.handle_response(response)
      else
        raise RequestError
      end

      # Enable streaming mode
      if response.chunked? and response.body.nil?
        @response_state = :chunked_body
      elsif @keepalive
        reset_request
      else
        @current_request = nil
        @parser.reset
        @request_fsm.transition :closed
      end
    rescue IOError, SystemCallError, RequestError
      # The client disconnected early, or there is no request
      @keepalive = false
      @request_fsm.transition :closed
      @parser.reset
      @current_request = nil
    end
482911
public void sendResponse(int code, String response) {
        if(con.isClosed()) return;

        if(response == null || response.isEmpty()) {
            response = "Unknown";
        }

        try {
            if(response.charAt(0) == '-') {
                writer.write(code + response + "\r\n");
            } else {
                writer.write(code + " " + response + "\r\n");
            }
            writer.flush();
        } catch(IOException ex) {
            Utils.closeQuietly(this);
        }
        responseSent = true;
    }
302122
private void sendResponse(final HttpServletResponse res, final CmsSpellcheckingRequest request) throws IOException {

        final PrintWriter pw = res.getWriter();
        final JSONObject response = getJsonFormattedSpellcheckResult(request);
        pw.println(response.toString());
        pw.close();
    }
516560
function sendResponse(success) {
        success = success || false;
        response.status(200);
        response.contentType('application/json');
        response.send(JSON.stringify({success: success}));
      }
725861
def _handle_response(self, response):
        
        if not str(response.status_code).startswith('2'):
            raise build_api_error(response)
        return response
1147113
function Response(req, res) {
  if (!(this instanceof Response))
    return new Response(req, res);

  EventEmitter.call(this);

  this.req = req;
  this.res = res;
  this.sent = false;
  this.readable = false;
  this.writable = true;
  this.statusCode = 200;
  this.res.statusCode = 200;

  if (req)
    this.init(req, res);
}
293751
def server
    reply = json_get(target, '/login', key_style)
    return reply if reply && (reply[:prompts] || reply['prompts'])
    raise BadResponse, "Invalid response from target #{target}"
  end
352529
function responseStatus(res) {
  if (res.status >= 200 && res.status < 300) {
    return res;
  } else {
    var error = new Error(res.statusText);
    error.response = res;
    throw customError('responseStatus', error);
  }
}
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
18966
def _post_response(self, params):
        
        return self._session.post(
            self._api_url, data=params, timeout=self._timeout
        ).json(encoding="utf8")
998452
def check_response(response):
    
    if response.status_code < 200 or response.status_code > 300:
        raise ServerError('API requests returned with error: %s'
                          % response.status_code)

    try:
        response_text = loads(response.text)
    except ValueError:
        raise ServerError('The API did not returned a JSON string.')

    if not response_text:
        raise EmptyResponse()

    if 'failure' in response_text:
        if response_text['failure'] == 'Falscher Dateityp':
            raise UnsupportedFormat('Please look at picflash.org '
                                    'witch formats are supported')
        else:
            raise UnkownError(response_text['failure'])
415047
function respondText(res, code, text) {
  res.statusCode = code;
  res.setHeader('Content-Type', 'text/plain');
  return res.end(text.toString());
}
1355454
def _decode_response(response):
    
    status_code = response.status_code

    message = "Status code " + str(status_code)
    try:
      message = CraftAIClient._parse_body(response)["message"]
    except (CraftAiInternalError, KeyError, TypeError):
      pass

    if status_code in [200, 201, 204, 207]:
      return CraftAIClient._parse_body(response)
    else:
      raise CraftAIClient._get_error_from_status(status_code, message)
    return None
713967
def _wrap_response(request, data=None, metadata=None, status=200):
        
        envelope = metadata or {}

        if data is not None:
            envelope['data'] = data

        return web.Response(
            status=status,
            content_type='application/json',
            text=json.dumps(
                envelope,
                indent=2,
                separators=(',', ': '),
                sort_keys=True))
438376
def handle_response(response)
      if response.is_a?(Result)
        token = response.token
        if (result = OperationResult.from_results(response))
          if result.non_delivery?
            @non_delivery_stats.update(result.content.nil? ? "nil" : result.content)
          elsif result.error?
            @result_error_stats.update(result.content.nil? ? "nil" : result.content)
          end
          @result_stats.update(result.status)
        else
          @result_stats.update(response.results.nil? ? "nil" : response.results)
        end

        if (pending_request = @pending_requests[token])
          if result && result.non_delivery? && pending_request.kind == :send_request
            if result.content == OperationResult::TARGET_NOT_CONNECTED
              # Log and temporarily ignore so that timeout retry mechanism continues, but save reason for use below if timeout
              # Leave purging of associated request until final response, i.e., success response or retry timeout
              if (parent_token = pending_request.retry_parent_token)
                @pending_requests[parent_token].non_delivery = result.content
              else
                pending_request.non_delivery = result.content
              end
              Log.info("Non-delivery of <#{token}> because #{result.content}")
            elsif result.content == OperationResult::RETRY_TIMEOUT && pending_request.non_delivery
              # Request timed out but due to another non-delivery reason, so use that reason since more germane
              response.results = OperationResult.non_delivery(pending_request.non_delivery)
              deliver_response(response, pending_request)
            else
              deliver_response(response, pending_request)
            end
          else
            deliver_response(response, pending_request)
          end
        elsif result && result.non_delivery?
          Log.info("Non-delivery of <#{token}> because #{result.content}")
        else
          Log.debug("No pending request for response #{response.to_s([])}")
        end
      end
      true
    end
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
1222961
def check_response(self, resp):
        

        # For successful API call, response code will be 200 (OK)
        if resp.ok:
            json = resp.json()
            self.response = ResponseHolder()
            self.response.response = json

            # Check the code
            if 'status' not in json:
                raise InvalidResponse('No status field')

            self.response.status = self.field_to_long(json['status'])
            if self.response.status != EBConsts.STATUS_OK:
                txt_status = self.get_text_status(json)
                raise InvalidStatus('Status is %s (%04X)'
                                    % (txt_status if txt_status is not None else "", self.response.status))

            if self.response_checker is not None:
                self.response_checker(self.response)

            return self.response

        else:
            # If response code is not ok (200), print the resulting http error code with description
            resp.raise_for_status()
        pass