<commit_before>require 'http/parser'
require 'tamarin/statuses'

module Tamarin
	
	class Connection

		attr_accessor :socket, :parser, :app
		
		def initialize(socket, app)
			@socket = socket
			@parser = Http::Parser.new(self)
			@app = app
		end

		def process
			until socket.closed? || socket.eof?
				data = socket.readpartial(1024)
				parser << data
			end
		end

		def on_message_complete
			puts "parser #{parser.headers}" 
			puts "parser #{parser.http_method}" 
			puts "parser #{parser.request_url}" 

			write_response
			close			
		end

		private

		def write_response
			status, headers, body = app.call

			socket.write "HTTP/1.1 #{status} #{HTTP_STATUS_CODES[status]}\r\n"
			socket.write headers.map { |k,v| "#{k}:#{v}\r\n" }.join
			socket.write "\r\n"
			socket.write "#{body.join}\n"
		end

		def close
			socket.close
		end

	end

end<commit_msg>call body close - Rack specification<commit_after>require 'http/parser'
require 'tamarin/statuses'

module Tamarin
	
	class Connection

		attr_accessor :socket, :parser, :app
		
		def initialize(socket, app)
			@socket = socket
			@parser = Http::Parser.new(self)
			@app = app
		end

		def process
			until socket.closed? || socket.eof?
				data = socket.readpartial(1024)
				parser << data
			end
		end

		def on_message_complete
			puts "parser #{parser.headers}" 
			puts "parser #{parser.http_method}" 
			puts "parser #{parser.request_url}" 

			write_response
			close			
		end

		private

		def write_response
			status, headers, body = app.call

			socket.write "HTTP/1.1 #{status} #{HTTP_STATUS_CODES[status]}\r\n"
			socket.write headers.map { |k,v| "#{k}:#{v}\r\n" }.join
			socket.write "\r\n"
			socket.write "#{body.join}\n"
			body.close if body.respond_to? :close
		end

		def close
			socket.close
		end

	end

end
{'fraction_non_alphanumeric': 0.12486126526082131, 'fraction_numerical': 0.006659267480577136, 'mean_word_length': 3.0977272727272727, 'pattern_counts': {'":': 0, '<': 7, '<?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': '7117552', 'n_tokens_mistral': 768, 'n_tokens_neox': 630, 'n_words': 155}