UNPKG

node-beanstalk

Version:

The most comprehensive beanstalk client for nodejs

31 lines 1.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseResponseHeaders = void 0; var types_1 = require("../types"); var const_1 = require("../const"); var ResponseError_1 = require("../error/ResponseError"); function parseResponseHeaders(buff) { var firstCrlf = buff.indexOf(const_1.CRLF_BUFF); if (firstCrlf === -1) return null; var _a = buff.slice(0, firstCrlf).toString().split(' '), status = _a[0], restHeaders = _a.slice(1); var hasData = status in types_1.BeanstalkDataResponseStatus; var dataLength = 0; var headers = restHeaders; if (hasData) { var lengthHeader = headers.pop(); dataLength = parseInt(lengthHeader, 10); if (Number.isNaN(dataLength)) { throw new ResponseError_1.ResponseError(ResponseError_1.ResponseErrorCode.ErrInvalidBodyLength, "Received invalid data length for ".concat(status, " response, expected number, got ").concat(lengthHeader)); } } return { headersLineLen: firstCrlf + const_1.CRLF_BUFF.length, status: status, headers: headers, hasData: hasData, dataLength: dataLength && dataLength + const_1.CRLF_BUFF.length, }; } exports.parseResponseHeaders = parseResponseHeaders; //# sourceMappingURL=parseResponseHeaders.js.map