Skip to content

Commit 4c55a98

Browse files
authored
fix: corrections to handleHttp and handleUnverified (#259)
1 parent 3725c0f commit 4c55a98

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

lib/smart-app.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -402,19 +402,22 @@ class SmartApp {
402402
* @param {*} response
403403
*/
404404
async handleHttpCallback(request, response) {
405-
if (request.body && request.body.lifecycle === 'PING') {
406-
return this._handleCallback(request.body, responders.httpResponder(response, this._log))
405+
const { body, originalUrl } = request
406+
407+
if (body && body.lifecycle === 'PING') {
408+
return this._handleCallback(body, responders.httpResponder(response, this._log))
407409
}
408410

409411
// Work-around to issue with http-signature
410412
// See also: https://github.com/joyent/node-http-signature/issues/87
411-
if (request.originalUrl) {
412-
request.url = request.originalUrl
413+
if (originalUrl) {
414+
const queryPos = originalUrl.indexOf('?')
415+
request.url = queryPos < 0 ? originalUrl : originalUrl.slice(0, queryPos)
413416
}
414417

415418
const isAuthorized = await this._authorizer.isAuthorized(request)
416419
if (isAuthorized) {
417-
return this._handleCallback(request.body, responders.httpResponder(response, this._log))
420+
return this._handleCallback(body, responders.httpResponder(response, this._log))
418421
}
419422

420423
this._log.error('Unauthorized')
@@ -428,8 +431,8 @@ class SmartApp {
428431
* @param {*} request
429432
* @param {*} response
430433
*/
431-
handleHttpCallbackUnverified(request, response) {
432-
this._handleCallback(request.body, responders.httpResponder(response, this._log))
434+
async handleHttpCallbackUnverified(request, response) {
435+
return this._handleCallback(request.body, responders.httpResponder(response, this._log))
433436
}
434437

435438
/**

0 commit comments

Comments
 (0)