<commit_before>if defined?(HTTPClient)

  class HTTPClient

    def do_get_block_with_webmock(req, proxy, conn, &block)
      do_get_with_webmock(req, proxy, conn, false, &block)
    end

    def do_get_stream_with_webmock(req, proxy, conn, &block)
      do_get_with_webmock(req, proxy, conn, true, &block)
    end

    def do_get_with_webmock(req, proxy, conn, stream = false, &block)
      request_signature = build_request_signature(req)

      WebMock::RequestRegistry.instance.requested_signatures.put(request_signature)

      if WebMock.registered_request?(request_signature)
        webmock_response = WebMock.response_for_request(request_signature)
        response = build_httpclient_response(webmock_response, stream, &block)
        res = conn.push(response)
        WebMock::CallbackRegistry.invoke_callbacks(
          {:lib => :http_client}, request_signature, webmock_response) 
        res
      elsif WebMock.net_connect_allowed?(request_signature.uri)
        res = if stream
          do_get_stream_without_webmock(req, proxy, conn, &block)
        else
          do_get_block_without_webmock(req, proxy, conn, &block)
        end
        webmock_response = build_webmock_response(res)
        WebMock::CallbackRegistry.invoke_callbacks(
          {:lib => :http_client, :real_request => true}, request_signature,
           webmock_response)
        res
      else
        raise WebMock::NetConnectNotAllowedError.new(request_signature)
      end
    end

    def do_request_async_with_webmock(method, uri, query, body, extheader)
      req = create_request(method, uri, query, body, extheader)
      request_signature = build_request_signature(req)
      
      if WebMock.registered_request?(request_signature) || WebMock.net_connect_allowed?(request_signature.uri)
        do_request_async_without_webmock(method, uri, query, body, extheader)
      else
        raise NetConnectNotAllowedError.new(request_signature)
      end
    end

    alias_method :do_get_block_without_webmock, :do_get_block
    alias_method :do_get_block, :do_get_block_with_webmock

    alias_method :do_get_stream_without_webmock, :do_get_stream
    alias_method :do_get_stream, :do_get_stream_with_webmock

    alias_method :do_request_async_without_webmock, :do_request_async
    alias_method :do_request_async, :do_request_async_with_webmock

    def build_httpclient_response(webmock_response, stream = false, &block)
      body = stream ? StringIO.new(webmock_response.body) : webmock_response.body
      response = HTTP::Message.new_response(body)
      response.header.init_response(webmock_response.status[0])<commit_msg>Added missing namespace prefix in execption class name<commit_after>if defined?(HTTPClient)

  class HTTPClient

    def do_get_block_with_webmock(req, proxy, conn, &block)
      do_get_with_webmock(req, proxy, conn, false, &block)
    end

    def do_get_stream_with_webmock(req, proxy, conn, &block)
      do_get_with_webmock(req, proxy, conn, true, &block)
    end

    def do_get_with_webmock(req, proxy, conn, stream = false, &block)
      request_signature = build_request_signature(req)

      WebMock::RequestRegistry.instance.requested_signatures.put(request_signature)

      if WebMock.registered_request?(request_signature)
        webmock_response = WebMock.response_for_request(request_signature)
        response = build_httpclient_response(webmock_response, stream, &block)
        res = conn.push(response)
        WebMock::CallbackRegistry.invoke_callbacks(
          {:lib => :http_client}, request_signature, webmock_response) 
        res
      elsif WebMock.net_connect_allowed?(request_signature.uri)
        res = if stream
          do_get_stream_without_webmock(req, proxy, conn, &block)
        else
          do_get_block_without_webmock(req, proxy, conn, &block)
        end
        webmock_response = build_webmock_response(res)
        WebMock::CallbackRegistry.invoke_callbacks(
          {:lib => :http_client, :real_request => true}, request_signature,
           webmock_response)
        res
      else
        raise WebMock::NetConnectNotAllowedError.new(request_signature)
      end
    end

    def do_request_async_with_webmock(method, uri, query, body, extheader)
      req = create_request(method, uri, query, body, extheader)
      request_signature = build_request_signature(req)
      
      if WebMock.registered_request?(request_signature) || WebMock.net_connect_allowed?(request_signature.uri)
        do_request_async_without_webmock(method, uri, query, body, extheader)
      else
        raise WebMock::NetConnectNotAllowedError.new(request_signature)
      end
    end

    alias_method :do_get_block_without_webmock, :do_get_block
    alias_method :do_get_block, :do_get_block_with_webmock

    alias_method :do_get_stream_without_webmock, :do_get_stream
    alias_method :do_get_stream, :do_get_stream_with_webmock

    alias_method :do_request_async_without_webmock, :do_request_async
    alias_method :do_request_async, :do_request_async_with_webmock

    def build_httpclient_response(webmock_response, stream = false, &block)
      body = stream ? StringIO.new(webmock_response.body) : webmock_response.body
      response = HTTP::Message.new_response(body)
      response.header.init_response(webmock_response.status[0])
{'fraction_non_alphanumeric': 0.07761868877166542, 'fraction_numerical': 0.00037678975131876413, 'mean_word_length': 4.085249042145594, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6949721', 'n_tokens_mistral': 1638, 'n_tokens_neox': 1669, 'n_words': 284}