Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makes response header references case insensitive #149

Merged
merged 1 commit into from
Oct 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 26 additions & 15 deletions lib/recurly/Http.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,14 @@ function makeRequest (options, requestBody) {

const submitRequest = () => {
const httpRequest = https.request(options, (httpResponse) => {
// downcase response headers
const responseHeaders = {}
for (const header in httpResponse.headers) {
responseHeaders[header.toLowerCase()] = httpResponse.headers[header]
}

var responseStream
const encoding = httpResponse.headers['content-encoding']
const encoding = responseHeaders['content-encoding']

if (encoding === 'gzip') {
responseStream = zlib.createGunzip(ZLIB_OPTIONS)
Expand All @@ -42,7 +48,7 @@ function makeRequest (options, requestBody) {
} else {
responseStream = httpResponse
}
responseStream.setEncoding(responseEncoding(httpResponse.headers['content-type']))
responseStream.setEncoding(responseEncoding(responseHeaders['content-type']))

const chunks = []
responseStream.on('data', chunk => chunks.push(chunk))
Expand Down Expand Up @@ -107,30 +113,35 @@ class Response {
if (body && body.length > 0) {
resp.body = body
}
// downcase response headers
const responseHeaders = {}
for (const header in response.headers) {
responseHeaders[header.toLowerCase()] = response.headers[header]
}
resp.status = response.statusCode
resp.requestId = response.headers['x-request-id']
resp.rateLimit = parseInt(response.headers['x-ratelimit-limit'], 10)
resp.rateLimitRemaining = parseInt(response.headers['x-ratelimit-remaining'], 10)
resp.rateLimitReset = new Date(parseInt(response.headers['x-ratelimit-reset'], 10) * 1000)
if (response.headers['content-type']) {
resp.contentType = response.headers['content-type'].split(';')[0]
resp.requestId = responseHeaders['x-request-id']
resp.rateLimit = parseInt(responseHeaders['x-ratelimit-limit'], 10)
resp.rateLimitRemaining = parseInt(responseHeaders['x-ratelimit-remaining'], 10)
resp.rateLimitReset = new Date(parseInt(responseHeaders['x-ratelimit-reset'], 10) * 1000)
if (responseHeaders['content-type']) {
resp.contentType = responseHeaders['content-type'].split(';')[0]
}
resp.recordCount = null
resp.apiDeprecated = false
resp.apiSunsetDate = null
const deprecated = response.headers['Recurly-Deprecated'] || ''
const deprecated = responseHeaders['recurly-deprecated'] || ''
if (deprecated.toUpperCase() === 'TRUE') {
resp.apiDeprecated = true
resp.apiSunsetDate = response.headers['Recurly-Sunset-Date']
resp.apiSunsetDate = responseHeaders['recurly-sunset-date']
}

if (response.headers['recurly-total-records']) {
resp.recordCount = parseInt(response.headers['recurly-total-records'], 10)
if (responseHeaders['recurly-total-records']) {
resp.recordCount = parseInt(responseHeaders['recurly-total-records'], 10)
}
resp.date = response.headers['date']
resp.date = responseHeaders['date']
resp.proxyMetadata = {
'server': response.headers['server'],
'cf-ray': response.headers['cf-ray']
'server': responseHeaders['server'],
'cf-ray': responseHeaders['cf-ray']
}

return resp
Expand Down