Send client HTTP request

 @param [String] request client HTTP request

 @return [Hash] HTTP response
344024
def send_request(request)
      response_error = { 'uri' => '',
                         'duration' => '0',
                         'http_version' => '1.0',
                         'headers' => "Server: #{@banner}\n",
                         'body' => '' }

      # parse client request
      begin
        if request.to_s !~ %r{\A(CONNECT|GET|HEAD|DELETE|POST|PUT|OPTIONS) https?://}
          if request.to_s !~ /^Host: ([^\s]+)\r?\n/
            logger.warn('No host specified')
            raise SSRFProxy::HTTP::Error::InvalidClientRequest,
                  'No host specified'
          end
        end
        req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
        req.parse(StringIO.new(request))
      rescue => e
        logger.info('Received malformed client HTTP request.')
        error_msg = 'Error -- Invalid request: ' \
                    "Received malformed client HTTP request: #{e.message}"
        print_error(error_msg)
        response_error['code'] = '502'
        response_error['message'] = 'Bad Gateway'
        response_error['status_line'] = "HTTP/#{response_error['http_version']}"
        response_error['status_line'] << " #{response_error['code']}"
        response_error['status_line'] << " #{response_error['message']}"
        return response_error
      end
      uri = req.request_uri

      # send request
      response = nil
      logger.info("Requesting URL: #{uri}")
      status_msg = "Request  -> #{req.request_method}"
      status_msg << " -> PROXY[#{@ssrf.proxy.host}:#{@ssrf.proxy.port}]" unless @ssrf.proxy.nil?
      status_msg << " -> SSRF[#{@ssrf.url.host}:#{@ssrf.url.port}] -> URI[#{uri}]"
      print_status(status_msg)

      begin
        response = @ssrf.send_request(request.to_s)
      rescue SSRFProxy::HTTP::Error::InvalidClientRequest => e
        logger.info(e.message)
        error_msg = "Error -- Invalid request: #{e.message}"
        print_error(error_msg)
        response_error['code'] = '502'
        response_error['message'] = 'Bad Gateway'
        response_error['status_line'] = "HTTP/#{response_error['http_version']}"
        response_error['status_line'] << " #{response_error['code']}"
        response_error['status_line'] << " #{response_error['message']}"
        return response_error
      rescue SSRFProxy::HTTP::Error::InvalidResponse => e
        logger.info(e.message)
        error_msg = 'Response <- 503'
        error_msg << " <- PROXY[#{@ssrf.proxy.host}:#{@ssrf.proxy.port}]" unless @ssrf.proxy.nil?
        error_msg << " <- SSRF[#{@ssrf.url.host}:#{@ssrf.url.port}] <- URI[#{uri}]"
        error_msg << " -- Error: #{e.message}"
        print_error(error_msg)
        response_error['code'] = '503'
        response_error['message'] = 'Service Unavailable'
        response_error['status_line'] = "HTTP/#{response_error['http_version']}"
        response_error['status_line'] << " #{response_error['code']}"
        response_error['status_line'] << " #{response_error['message']}"
        return response_error
      rescue SSRFProxy::HTTP::Error::ConnectionFailed => e
        logger.info(e.message)
        error_msg = 'Response <- 503'
        error_msg << " <- PROXY[#{@ssrf.proxy.host}:#{@ssrf.proxy.port}]" unless @ssrf.proxy.nil?
        error_msg << " <- SSRF[#{@ssrf.url.host}:#{@ssrf.url.port}] <- URI[#{uri}]"
        error_msg << " -- Error: #{e.message}"
        print_error(error_msg)
        response_error['code'] = '503'
        response_error['message'] = 'Service Unavailable'
        response_error['status_line'] = "HTTP/#{response_error['http_version']}"
        response_error['status_line'] << " #{response_error['code']}"
        response_error['status_line'] << " #{response_error['message']}"
        return response_error
      rescue SSRFProxy::HTTP::Error::ConnectionTimeout => e
        logger.info(e.message)
        error_msg = 'Response <- 504'
        error_msg << " <- PROXY[#{@ssrf.proxy.host}:#{@ssrf.proxy.port}]" unless @ssrf.proxy.nil?
        error_msg << " <- SSRF[#{@ssrf.url.host}:#{@ssrf.url.port}] <- URI[#{uri}]"
        error_msg << " -- Error: #{e.message}"
        print_error(error_msg)
        response_error['code'] = '504'
        response_error['message'] = 'Timeout'
        response_error['status_line'] = "HTTP/#{response_error['http_version']}"
        response_error['status_line'] << " #{response_error['code']}"
        response_error['status_line'] << " #{response_error['message']}"
        return response_error
      rescue => e
        logger.warn(e.message)
        error_msg = "Error -- Unexpected error: #{e.backtrace.join("\n")}"
        print_error(error_msg)
        response_error['code'] = '502'
        response_error['message'] = 'Bad Gateway'
        response_error['status_line'] = "HTTP/#{response_error['http_version']}"
        response_error['status_line'] << " #{response_error['code']} "
        response_error['status_line'] << " #{response_error['message']}"
        return response_error
      end

      # return response
      status_msg = "Response <- #{response['code']}"
      status_msg << " <- PROXY[#{@ssrf.proxy.host}:#{@ssrf.proxy.port}]" unless @ssrf.proxy.nil?
      status_msg << " <- SSRF[#{@ssrf.url.host}:#{@ssrf.url.port}] <- URI[#{uri}]"
      status_msg << " -- Title[#{response['title']}]" unless response['title'].eql?('')
      status_msg << " -- [#{response['body'].size} bytes]"
      print_good(status_msg)
      response
    end
343247
def send_request(self, request):
        
        assert isinstance(request, Request)
        if request.block1 or (request.payload is not None and len(request.payload) > defines.MAX_PAYLOAD):
            host, port = request.destination
            key_token = hash(str(host) + str(port) + str(request.token))
            if request.block1:
                num, m, size = request.block1
            else:
                num = 0
                m = 1
                size = defines.MAX_PAYLOAD

            self._block1_sent[key_token] = BlockItem(size, num, m, size, request.payload, request.content_type)
            request.payload = request.payload[0:size]
            del request.block1
            request.block1 = (num, m, size)
        elif request.block2:
            host, port = request.destination
            key_token = hash(str(host) + str(port) + str(request.token))
            num, m, size = request.block2
            item = BlockItem(size, num, m, size, "", None)
            self._block2_sent[key_token] = item
            return request
        return request
492103
def request(method, path, params={}, body=nil, headers={}, options={}, &block)
      options = { :mashify => true }.merge(options)
      req = http.build_request(method)
      req.path = path
      req.params.update(Util.clean_params(params)) if params
      req.body = body
      req.headers.update(headers) if headers
      block.call(req) if block
      logger.debug { Util.curl_format(req) }

      if @http_threadsafe
        env = req.to_env(http)
        check_response(http.app.call(env), options)
      else
        @request_mtx.synchronize {
          env = req.to_env(http)
          check_response(http.app.call(env), options)
        }
      end
    end
1151746
def send(self, request):
        ''''''
        return self.session.send(request(self.url, self.auth))
908801
def request(method = :get, path = '/files/', params = {})
      response = @api_connection.send method, path, params
      response.body
    end
337846
def http_post(url, data)
    req = HTTPI::Request.new(:url => url, :body => data)
    return HTTPI.post(req).body
  end
1197727
def http_client=(client)
      unless client.kind_of?(Net::HTTP) or client.nil?
        raise ArgumentError, "`client` expected to be a kind of `Net::HTTP`, `#{client.class}` given"
      end
      @http_client = client
    end
220266
def send_http_request
      net_http_options = [uri.host, uri.port, use_ssl: true]
      ActiveSupport::Notifications.instrument 'request.yt' do |payload|
        payload[:method] = @method
        payload[:request_uri] = uri
        payload[:response] = Net::HTTP.start(*net_http_options) do |http|
          http.request http_request
        end
      end
    end
849097
def send_request(params)
      params['response'] = 'json'
      params['apiKey'] = @api_key
      print_debug_output JSON.pretty_generate(params) if @debug

      data = params_to_data(params)
      uri = URI.parse "#{@api_url}?#{data}&signature=#{create_signature(data)}"

      http = Net::HTTP.new(uri.host, uri.port)
      if uri.scheme == 'https'
        http.use_ssl = true
        http.verify_mode = OpenSSL::SSL::VERIFY_NONE
      end

      begin
        response = http.request(Net::HTTP::Get.new(uri.request_uri))
      rescue
        raise ConnectionError, "API URL \'#{@api_url}\' is not reachable."
      end

      begin
        body = JSON.parse(response.body).values.first
      rescue JSON::ParserError
        raise ParseError,
          "Response from server is not readable. Check if the API endpoint (#{@api_url}) is valid and accessible."
      end

      if response.is_a?(Net::HTTPOK)
        return body unless body.respond_to?(:keys)
        if body.size == 2 && body.key?('count')
          return body.reject { |key, _| key == 'count' }.values.first
        elsif body.size == 1 && body.values.first.respond_to?(:keys)
          item = body.values.first
          return (item.is_a?(Array) || item.is_a?(Hash)) ? item : []
        else
          body.reject! { |key, _| key == 'count' } if body.key?('count')
          body.size == 0 ? [] : body
        end
      else
        message = body['errortext'] rescue body
        raise ApiError, "Status #{response.code}: #{message}."
      end
    end
195529
def send_HTTP_request(exchange, routing_key, message)
      http_message = format_HTTP_message(message)

      message_id = AlchemyFlux::Service.generateUUID()

      http_message_options = {
        message_id:          message_id,
        type:               'http',
        reply_to:            @response_queue_name,
        content_encoding:   '8bit',
        content_type:       'application/json',
        expiration:          @options[:timeout],
        mandatory:           true
      }

      response_queue = Queue.new
      @transactions[message_id] = response_queue

      send_message(exchange, routing_key, http_message, http_message_options)

      EventMachine.add_timer(@options[:timeout]/1000.0) do
        response_queue = @transactions.delete message_id
        response_queue << TimeoutError if response_queue
      end

      response_queue.pop
    end
1328906
def send_message(
        self, request: str, response_expected: bool, **kwargs: Any
    ) -> Response:
        
        response = self.session.post(self.endpoint, data=request.encode(), **kwargs)
        return Response(response.text, raw=response)
1230323
def core__send_request_success(payload)
      response = { result: true, error_message: nil }
      response[:payload] = payload if payload
      render json: response
    end
881086
private boolean send(String request)
    {
        needRateLimit = !client.send(request, false);
        attemptedToSend = true;
        return !needRateLimit;
    }
807490
def request(method, path, params={})
      headers = @default_headers.merge({'Authorization' => "Bearer #{@access_token}"})
      result = http_client.send_request(method, path, {
        :params  => params,
        :headers => headers
      })
      result
    end
427987
def send_recv( request )
      connection.write( request.to_protocol )
      line = connection.readline
      resp = KJess::Response.parse( line )
      resp.read_more( connection )
      raise resp if resp.error?
      return resp
    end
1204563
def send_request(ref, msg_id, arg, b)
      @msg.send_request(stream, ref, msg_id, arg, b)
    end
995983
def send_request(request)
      api_name = Protocol.api_name(request.api_key)

      # Default notification payload.
      notification = {
        broker_host: @host,
        api: api_name,
        request_size: 0,
        response_size: 0,
      }

      raise IdleConnection if idle?

      @logger.push_tags(api_name)
      @instrumenter.instrument("request.connection", notification) do
        open unless open?

        @correlation_id += 1

        @logger.debug "Sending #{api_name} API request #{@correlation_id} to #{to_s}"

        write_request(request, notification)

        response_class = request.response_class
        response = wait_for_response(response_class, notification) unless response_class.nil?

        @last_request = Time.now

        response
      end
    rescue SystemCallError, EOFError, IOError => e
      close

      raise ConnectionError, "Connection error #{e.class}: #{e}"
    ensure
      @logger.pop_tags
    end