'use strict'

var getBody = require('raw-body')
var https = require('https')
var path = require('path')
var write = require('./lib/write')

var URL = 'https://svn.apache.org/repos/asf/httpd/httpd/trunk/modules/http/http_protocol.c'

https.get(URL, function onResponse (res) {
  getBody(res, true, function (err, body) {
    if (err) throw err

    var block = /status_lines\[[^\]]*\]\s*=\s*{([^}]+)};/m.exec(body)[1]
    var codes = {}
    var match
    var regexp = /"([0-9]+) ([^"]+)"/g

    while ((match = regexp.exec(block))) {
      codes[match[1]] = match[2]
    }

    write(path.join(__dirname, '../src/apache.json'), codes)
  })
})
