Skip to content

Commit

Permalink
In progress changes
Browse files Browse the repository at this point in the history
  • Loading branch information
avoidwork committed Jul 24, 2017
1 parent 60471fc commit c81f15e
Show file tree
Hide file tree
Showing 4 changed files with 1,903 additions and 287 deletions.
33 changes: 20 additions & 13 deletions lib/tenso.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,11 @@ class Tenso {
return this;
}

headers (req, res, status, body, headers, pipe) {
const result = utility.merge(utility.clone(this.config.headers), headers),
options = {},
headers (req, res, status, body, result, pipe) {
const options = {},
isOptions = regex.options.test(req.method);
let size;

if (req.allow !== "" && result.allow === void 0) {
result.allow = req.allow;
}

if (regex.head.test(req.method)) {
result.connection = "close";
}
Expand All @@ -197,7 +192,7 @@ class Tenso {
size = result["content-length"] || 0;
}

if (!pipe && req.headers.range && headers["content-range"] === void 0) {
if (!pipe && req.headers.range && result["content-range"] === void 0) {
retsu.each(req.headers.range.split(",")[0].split("-"), (i, idx) => {
options[idx === 0 ? "start" : "end"] = i ? parseInt(i, 10) : void 0;
});
Expand Down Expand Up @@ -358,10 +353,10 @@ class Tenso {
return this;
}

respond (req, res, arg, status = 200, headers = {}) {
respond (req, res, arg, status = 200, headers) {
const defer = deferred();

if (res._header === null) {
if (!res.headersSent) {
let ref = [headers || {}],
output;

Expand Down Expand Up @@ -407,7 +402,8 @@ class Tenso {

send (req, res, body = "", status = 200, headers = {"content-type": "text/plain"}) {
const defer = deferred(),
pipe = typeof body.on === "function";
pipe = typeof body.on === "function",
rheaders = res.getHeaders();
let indent = this.config.json,
header, lheaders, compression, compressionMethod;

Expand Down Expand Up @@ -440,12 +436,23 @@ class Tenso {

lheaders = this.headers(req, res, status, body, headers, pipe);

if (status !== 416 && req.headers.range && lheaders["content-range"] === void 0) {
retsu.each(Reflect.ownKeys(lheaders), i => {
if (rheaders[i] !== void 0) {
if (lheaders[i] !== rheaders[i] && rheaders[i].indexOf(lheaders[i]) === -1) {
res.removeHeader(i);
delete rheaders[i];
} else {
delete lheaders[i];
}
}
});

if (status !== 416 && req.headers.range && !res.hasHeader("content-range") && lheaders["content-range"] === void 0) {
return this.error(req, res, 416, http.STATUS_CODES[416]);
}

if (body !== null && body !== "") {
compression = this.compression(req.headers["accept-encoding"], lheaders["content-type"]);
compression = this.compression(req.headers["accept-encoding"], lheaders["content-type"] || rheaders["content-type"]);
}

if (compression) {
Expand Down
Loading

0 comments on commit c81f15e

Please sign in to comment.