<commit_before>local socket = require 'socket'
local Request = require 'lib/request'
local Response = require 'lib/response'
local http = require 'lib/http'

local HTTPServer = {}

function HTTPServer:new(port)
  self.port = port or '9090'
  return self
end

function HTTPServer:start(callback)
  local server = assert(socket.bind("*", self.port))
  local ip, port = server:getsockname()
  print("Server is up on port " .. self.port)

  while 1 do
    local client = server:accept()

    client:settimeout(30)
    self:processRequest(client, callback)
    client:close()
  end
end

function HTTPServer:processRequest(client, callback)
  local request = Request:new(client)
  local response =  Response:new(client)
  local method = request:method()

  if method == 'GET' then
    self:GET(request, response, callback)
  elseif method == 'POST' then
    self:POST(request, response)
  end

  client:send(response.body)
end

function HTTPServer:GET(request, response, callback)
  -- http._get = request:params()
  response:processes(request, response)
  callback(request, response)
end

function HTTPServer:POST(request, response)
  print('POST')
  response:processes(request)
end

httpServer = HTTPServer:new('9090')

httpServer:start(function (req, rep)
  print(req:params()['name'])
end)
<commit_msg>added conditional to guarantee that the callback will be called once<commit_after>local socket = require 'socket'
local Request = require 'lib/request'
local Response = require 'lib/response'
local http = require 'lib/http'

local HTTPServer = {}

function HTTPServer:new(port)
  self.port = port or '9090'
  return self
end

function HTTPServer:start(callback)
  local server = assert(socket.bind("*", self.port))
  local ip, port = server:getsockname()
  print("Server is up on port " .. self.port)
  local was_called = false

  while 1 do
    local client = server:accept()

    client:settimeout(30)

    if not was_called then
      self:processRequest(client, callback)
      was_called = true
    else
      self:processRequest(client)
    end

    client:close()
  end
end

function HTTPServer:processRequest(client, callback)
  local request = Request:new(client)
  local response =  Response:new(client)
  local method = request:method()

  if method == 'GET' then
    self:GET(request, response, callback)
  elseif method == 'POST' then
    self:POST(request, response)
  end

  client:send(response.body)
end

function HTTPServer:GET(request, response, callback)
  response:processes(request, response)

  if callback then
    callback(request, response)
  end
end

function HTTPServer:POST(request, response)
  print('POST')
  response:processes(request)
end

httpServer = HTTPServer:new('9090')

httpServer:start(function (req, rep)
  print(req:params()['name'])
end)

{'fraction_non_alphanumeric': 0.11143062544931703, 'fraction_numerical': 0.007907979870596693, 'mean_word_length': 4.6680244399185336, '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': '7415371', 'n_tokens_mistral': 862, 'n_tokens_neox': 853, 'n_words': 238}