Skip to content

Commit

Permalink
Disabling ipv6 support in resolver, and some clean up
Browse files Browse the repository at this point in the history
Former-commit-id: 6825d47c6a34992f8ab116f20ac94b21f5ba10f2
  • Loading branch information
subnetmarco committed May 27, 2015
1 parent 9655d44 commit 4e64847
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 38 deletions.
2 changes: 1 addition & 1 deletion kong.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ nginx: |
}
http {
resolver {{dns_resolver}};
resolver {{dns_resolver}} ipv6=off;
charset UTF-8;
access_log logs/access.log;
Expand Down
23 changes: 0 additions & 23 deletions kong/dao/cassandra/factory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,12 @@ local KeyAuthCredentials = require "kong.dao.cassandra.keyauth_credentials"

local CassandraFactory = Object:extend()

local LOCALHOST = "localhost"
local LOCALHOST_IP = "127.0.0.1"

-- Converts every occurence of "localhost" to "127.0.0.1"
-- @param host can either be a string or an array of hosts
local function normalize_localhost(host)
if type(host) == "table" then
for i, v in ipairs(host) do
if v == LOCALHOST then
host[i] = LOCALHOST_IP
end
end
elseif host == LOCALHOST then
host = LOCALHOST_IP
end
return host
end

-- Instanciate a Cassandra DAO.
-- @param properties Cassandra properties
function CassandraFactory:new(properties)
self.type = "cassandra"
self._properties = properties

-- Convert localhost to 127.0.0.1
-- This is because nginx doesn't resolve the /etc/hosts file but /etc/resolv.conf
-- And it may cause errors like "host not found" for "localhost"
self._properties.hosts = normalize_localhost(self._properties.hosts)

self.apis = Apis(properties)
self.consumers = Consumers(properties)
self.plugins_configurations = PluginsConfigurations(properties)
Expand Down
13 changes: 4 additions & 9 deletions kong/plugins/httplog/log.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@ local _M = {}
-- @return `payload` http payload
local function generate_post_payload(method, parsed_url, message)
local body = cjson.encode(message);
local payload = string.format([[
%s %s HTTP/1.1
Host: %s
Connection: Keep-Alive
Content-Type: application/json
Content-Length: %s
%s]], method:upper(), parsed_url.path, parsed_url.host, string.len(body), body)
local payload = string.format(
"%s %s HTTP/1.1\r\nHost: %s\r\nConnection: Keep-Alive\r\nContent-Type: application/json\r\nContent-Length: %s\r\n\r\n%s",
method:upper(), parsed_url.path, parsed_url.host, string.len(body), body)
return payload
end

Expand Down Expand Up @@ -77,4 +72,4 @@ function _M.execute(conf)
end
end

return _M
return _M
5 changes: 1 addition & 4 deletions spec/spec_helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,7 @@ function _M.start_http_server(port, ...)
function(port)
local socket = require "socket"
local server = assert(socket.bind("*", port))
local client, err = server:accept()
if not err then
client:settimeout(3)
end
local client = server:accept()

local lines = {}
local line
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/statics_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ nginx: |
}
http {
resolver {{dns_resolver}};
resolver {{dns_resolver}} ipv6=off;
charset UTF-8;
access_log logs/access.log;
Expand Down

0 comments on commit 4e64847

Please sign in to comment.