<commit_before>

module Stella::Data::HTTP
  class Request < Storable
    include Gibbler::Complex
    
    # A string representing a raw HTTP request
    attr_reader :raw_data
    
    # A hash containing blocks to be executed depending on the HTTP response status.
    # The hash keys are numeric HTTP Status Codes. 
    #
    #     200 => { ... }
    #     304 => { ... }
    #     500 => { ... }
    #
    attr_accessor :response_handler
    
    field :desc
    field :header 
    field :uri
    field :wait
    field :params
    field :body 
    field :http_method
    field :http_version
    field :content_type
    
    def has_body?
      !@body.nil? && !@body.empty?
    end
    
    def initialize (method, uri_str, version="1.1", &definition)
      @uri = (uri_str.is_a? String) ? URI.parse(uri_str) : uri
      @http_method, @http_version = method, version
      @headers, @params, @response_handler = {}, {}, {}
      @wait = 0
      @desc = "Request"
      @body = Stella::Data::HTTP::Body.new
      instance_eval &definition unless definition.nil?
    end
    
    def desc(*args)
      @desc = args.first unless args.empty?
      @desc
    end
    
    def content_type(*args)
      @content_type = args.first unless args.empty?
      @content_type
    end
    
    def wait(*args)
      @wait = args.first unless args.empty?
      @wait
    end
    
    def headers(*args)
      @headers.merge! args.first unless args.empty?
      @headers
    end
    alias_method :header, :headers
    
    def params(*args)
      @params.merge! args.first unless args.empty?
      @params
    end
    alias_method :param, :params
    
    def response(*args, &definition)
      if definition.nil?
        @response_handler
      else
        args << 200 if args.empty?
        args.each do |status|
          @response_handler[status] = definition
        end
      end
    end
    
    # +content+ can be literal content or a file path
    def body(*args)
      return @body if args.empty?
      content, form_param, content_type = *args
      
      @body.form_param = form_param if form_param<commit_msg>Add sleep alias for request definitions<commit_after>

module Stella::Data::HTTP
  class Request < Storable
    include Gibbler::Complex
    
    # A string representing a raw HTTP request
    attr_reader :raw_data
    
    # A hash containing blocks to be executed depending on the HTTP response status.
    # The hash keys are numeric HTTP Status Codes. 
    #
    #     200 => { ... }
    #     304 => { ... }
    #     500 => { ... }
    #
    attr_accessor :response_handler
    
    field :desc
    field :header 
    field :uri
    field :wait
    field :params
    field :body 
    field :http_method
    field :http_version
    field :content_type
    
    def has_body?
      !@body.nil? && !@body.empty?
    end
    
    def initialize (method, uri_str, version="1.1", &definition)
      @uri = (uri_str.is_a? String) ? URI.parse(uri_str) : uri
      @http_method, @http_version = method, version
      @headers, @params, @response_handler = {}, {}, {}
      @wait = 0
      @desc = "Request"
      @body = Stella::Data::HTTP::Body.new
      instance_eval &definition unless definition.nil?
    end
    
    def desc(*args)
      @desc = args.first unless args.empty?
      @desc
    end
    
    def content_type(*args)
      @content_type = args.first unless args.empty?
      @content_type
    end
    
    def wait(*args)
      @wait = args.first unless args.empty?
      @wait
    end
    alias_method :sleep, :wait
    
    def headers(*args)
      @headers.merge! args.first unless args.empty?
      @headers
    end
    alias_method :header, :headers
    
    def params(*args)
      @params.merge! args.first unless args.empty?
      @params
    end
    alias_method :param, :params
    
    def response(*args, &definition)
      if definition.nil?
        @response_handler
      else
        args << 200 if args.empty?
        args.each do |status|
          @response_handler[status] = definition
        end
      end
    end
    
    # +content+ can be literal content or a file path
    def body(*args)
      return @body if args.empty?
      content, form_param, content_type = *args
      
      @body.form_param = form_param if form_param
{'fraction_non_alphanumeric': 0.09838747370881047, 'fraction_numerical': 0.0070109838747370885, 'mean_word_length': 2.076923076923077, 'pattern_counts': {'":': 0, '<': 9, '<?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': '4368572', 'n_tokens_mistral': 1320, 'n_tokens_neox': 1291, 'n_words': 373}