<commit_before>local TCP = require('tcp')
local Request = require('request')
local Response = require('response')
local HTTP_Parser = require('http_parser')
local HTTP = {}


function HTTP.create_server(host, port, on_connection)
  local server = TCP.new()
  server:bind(host, port)
  server:listen(function (err)
    if err then
      return server:emit("error", err)
    end

    -- Accept the client and build request and response objects
    local client = TCP.new()
    server:accept(client)
    client:read_start()
    local request = Request.new(client)
    local response = Response.new(client)

    -- Convert TCP stream to HTTP stream
    local current_field
    local parser
    local headers
    parser = HTTP_Parser.new("request", {
      on_message_begin = function ()
        headers = {}
        request.headers = headers
      end,
      on_url = function (url)
        request.url = url
      end,
      on_header_field = function (field)
        current_field = field
      end,
      on_header_value = function (value)
        headers[current_field:lower()] = value
      end,
      on_headers_complete = function (info)

        request.method = info.method
        request.upgrade = info.upgrade

        request.version_major = info.version_major
        request.version_minor = info.version_minor

        -- Handle 100-continue requests
        if request.headers.expect and info.version_major == 1 and info.version_minor == 1 and request.headers.expect:lower() == "100-continue" then
          if server.handlers and server.handlers.check_continue then<commit_msg>Give upgrade requests access to the raw client if they want it<commit_after>local TCP = require('tcp')
local Request = require('request')
local Response = require('response')
local HTTP_Parser = require('http_parser')
local HTTP = {}


function HTTP.create_server(host, port, on_connection)
  local server = TCP.new()
  server:bind(host, port)
  server:listen(function (err)
    if err then
      return server:emit("error", err)
    end

    -- Accept the client and build request and response objects
    local client = TCP.new()
    server:accept(client)
    client:read_start()
    local request = Request.new(client)
    local response = Response.new(client)

    -- Convert TCP stream to HTTP stream
    local current_field
    local parser
    local headers
    parser = HTTP_Parser.new("request", {
      on_message_begin = function ()
        headers = {}
        request.headers = headers
      end,
      on_url = function (url)
        request.url = url
      end,
      on_header_field = function (field)
        current_field = field
      end,
      on_header_value = function (value)
        headers[current_field:lower()] = value
      end,
      on_headers_complete = function (info)

        request.method = info.method
        request.upgrade = info.upgrade

        request.version_major = info.version_major
        request.version_minor = info.version_minor

        -- Give upgrade requests access to the raw client if they want it
        if info.upgrade then
          request.client = client
        end

        -- Handle 100-continue requests
        if request.headers.expect and info.version_major == 1 and info.version_minor == 1 and request.headers.expect:lower() == "100-continue" then
          if server.handlers and server.handlers.check_continue then
{'fraction_non_alphanumeric': 0.08848771825984018, 'fraction_numerical': 0.004735128736312519, 'mean_word_length': 2.793490460157127, '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': '7605939', 'n_tokens_mistral': 937, 'n_tokens_neox': 899, 'n_words': 270}