node-web-mvc
Version:
node spring mvc
103 lines (102 loc) • 2.53 kB
JavaScript
"use strict";
/**
* @module ResponseEntity
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const HttpHeaders_1 = __importDefault(require("../http/HttpHeaders"));
class HttpEntity {
constructor(data, headers) {
this.body = data;
this.headers = (headers || {});
}
/**
* 设置返回内容
* @param data
*/
setBody(data) {
this.body = data;
return this;
}
/**
* 这是头部信息对象
* @param headers
*/
setHeaders(headers) {
this.headers = headers;
return this;
}
/**
* 设置单个头部信息
* @param key
* @param values
*/
setHeader(key, ...values) {
this.headers[key] = values.join(',');
return this;
}
/**
* 设置头部信息 allows
* @param HttpMethod
* @param allowedMethods
*/
setAllow(allowedMethods) {
this.headers[HttpHeaders_1.default.ALLOW] = allowedMethods.join(',');
return this;
}
/**
* 设置返回etag
*/
setETag(etag) {
this.headers[HttpHeaders_1.default.ETAG] = etag;
return this;
}
/**
* 设置Last-Modified头部信息
*/
setLastModified(lastModified) {
this.headers[HttpHeaders_1.default.LAST_MODIFIED] = lastModified.toUTCString();
return this;
}
/**
* 设置Location头部信息
*/
setLocation(location) {
this.headers[HttpHeaders_1.default.LOCATION] = location;
return this;
}
/**
* 配置缓存控制
*/
setCacheControl(cacheControl) {
if (cacheControl) {
this.headers[HttpHeaders_1.default.CACHE_CONTROL] = cacheControl.toString();
}
return this;
}
/**
* 配置 Vary头部信息
* ```js
* .varBy('UserAgent','Cookie')
*
* ```
*/
setVaryBy(requestHeaders) {
this.headers[HttpHeaders_1.default.VARY] = requestHeaders.join(',');
return this;
}
setContentLength(contentLength) {
this.headers[HttpHeaders_1.default.CONTENT_LENGTH] = contentLength;
return this;
}
setContentType(contentType) {
this.headers[HttpHeaders_1.default.CONTENT_TYPE] = contentType.toString();
return this;
}
build() {
this.body = null;
}
}
exports.default = HttpEntity;