<commit_before># encoding: utf-8

require 'sockjs/delayed-response-body'

module SockJS
  #Adapter for Thin Rack responses.  It's a TODO feature to support other
  #webservers and compatibility layers
  class Response
    extend Forwardable
    attr_reader :request, :status, :headers, :body
    attr_writer :status

    def initialize(request, status = nil, headers = nil, &block)
      # request.env["async.close"]
      # ["rack.input"].closed? # it's a stream
      @request, @status, @headers = request, status, headers || {}

      if request.http_1_0?
        SockJS.debug "Request is in HTTP/1.0, responding with HTTP/1.0"
        @body = DelayedResponseBody.new
      else
        @body = DelayedResponseChunkedBody.new
      end

      @body.callback do
        @request.succeed
      end

      @body.errback do
        @request.fail
      end

      block.call(self) if block

      set_connection_keep_alive_if_requested
    end

    def session=(session)
      @body.session = session
    end

    def turn_chunking_on(headers)
      headers["Transfer-Encoding"] = "chunked"
    end


    def write_head(status = nil, headers = nil)
      @status  = status.to_i  || @status  || raise("Please set the status!")
      @headers = headers || @headers

      if @headers["Content-Length"]
        raise "You can't use Content-Length with chunking!"
      end

      unless @request.http_1_0? || @status == 204
        turn_chunking_on(@headers)
      end

      SockJS.debug "Writing headers: #{@status.inspect}/#{@headers.inspect}"
      @request.async_callback.call([@status, @headers, @body])

      @head_written = true
    end

    def head_written?
      !! @head_written
    end

    def write(data)<commit_msg>Reverted last change<commit_after># encoding: utf-8

require 'sockjs/delayed-response-body'

module SockJS
  #Adapter for Thin Rack responses.  It's a TODO feature to support other
  #webservers and compatibility layers
  class Response
    extend Forwardable
    attr_reader :request, :status, :headers, :body
    attr_writer :status

    def initialize(request, status = nil, headers = nil, &block)
      # request.env["async.close"]
      # ["rack.input"].closed? # it's a stream
      @request, @status, @headers = request, status, headers || {}

      if request.http_1_0?
        SockJS.debug "Request is in HTTP/1.0, responding with HTTP/1.0"
        @body = DelayedResponseBody.new
      else
        @body = DelayedResponseChunkedBody.new
      end

      @body.callback do
        @request.succeed
      end

      @body.errback do
        @request.fail
      end

      block.call(self) if block

      set_connection_keep_alive_if_requested
    end

    def session=(session)
      @body.session = session
    end

    def turn_chunking_on(headers)
      headers["Transfer-Encoding"] = "chunked"
    end


    def write_head(status = nil, headers = nil)
      @status  = status  || @status  || raise("Please set the status!")
      @headers = headers || @headers

      if @headers["Content-Length"]
        raise "You can't use Content-Length with chunking!"
      end

      unless @request.http_1_0? || @status == 204
        turn_chunking_on(@headers)
      end

      SockJS.debug "Writing headers: #{@status.inspect}/#{@headers.inspect}"
      @request.async_callback.call([@status, @headers, @body])

      @head_written = true
    end

    def head_written?
      !! @head_written
    end

    def write(data)
{'fraction_non_alphanumeric': 0.10561342592592593, 'fraction_numerical': 0.006944444444444444, 'mean_word_length': 2.6085594989561587, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3805226', 'n_tokens_mistral': 1093, 'n_tokens_neox': 1035, 'n_words': 277}