strapi/docs/.vuepress/dist/assets/js/19.8d1b00cd.js
2018-10-05 17:24:17 +02:00

1 line
29 KiB
JavaScript

(window.webpackJsonp=window.webpackJsonp||[]).push([[19],{220:function(t,s,a){"use strict";a.r(s);var e=a(0),n=Object(e.a)({},function(){this.$createElement;this._self._c;return this._m(0)},[function(){var t=this,s=t.$createElement,a=t._self._c||s;return a("div",{staticClass:"content"},[a("h1",{attrs:{id:"response"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#response","aria-hidden":"true"}},[t._v("#")]),t._v(" Response")]),t._v(" "),a("p",[t._v("A Strapi "),a("code",[t._v("Response")]),t._v(" object is an abstraction on top of Node's vanilla response object,\nproviding additional functionality that is useful for every day HTTP server\ndevelopment.")]),t._v(" "),a("h2",{attrs:{id:"api"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#api","aria-hidden":"true"}},[t._v("#")]),t._v(" API")]),t._v(" "),a("h3",{attrs:{id:"response-header"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#response-header","aria-hidden":"true"}},[t._v("#")]),t._v(" response.header")]),t._v(" "),a("p",[t._v("Response header object.")]),t._v(" "),a("h3",{attrs:{id:"response-headers"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#response-headers","aria-hidden":"true"}},[t._v("#")]),t._v(" response.headers")]),t._v(" "),a("p",[t._v("Response header object. Alias as "),a("code",[t._v("response.header")]),t._v(".")]),t._v(" "),a("h3",{attrs:{id:"response-socket"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#response-socket","aria-hidden":"true"}},[t._v("#")]),t._v(" response.socket")]),t._v(" "),a("p",[t._v("Request socket.")]),t._v(" "),a("h3",{attrs:{id:"response-status"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#response-status","aria-hidden":"true"}},[t._v("#")]),t._v(" response.status")]),t._v(" "),a("p",[t._v("Get response status. By default, "),a("code",[t._v("response.status")]),t._v(" is not set unlike Node's\n"),a("code",[t._v("res.statusCode")]),t._v(" which defaults to "),a("code",[t._v("200")]),t._v(".")]),t._v(" "),a("h3",{attrs:{id:"response-status-2"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#response-status-2","aria-hidden":"true"}},[t._v("#")]),t._v(" response.status=")]),t._v(" "),a("p",[t._v("Set response status via numeric code:")]),t._v(" "),a("ul",[a("li",[t._v('100 "continue"')]),t._v(" "),a("li",[t._v('101 "switching protocols"')]),t._v(" "),a("li",[t._v('102 "processing"')]),t._v(" "),a("li",[t._v('200 "ok"')]),t._v(" "),a("li",[t._v('201 "created"')]),t._v(" "),a("li",[t._v('202 "accepted"')]),t._v(" "),a("li",[t._v('203 "non-authoritative information"')]),t._v(" "),a("li",[t._v('204 "no content"')]),t._v(" "),a("li",[t._v('205 "reset content"')]),t._v(" "),a("li",[t._v('206 "partial content"')]),t._v(" "),a("li",[t._v('207 "multi-status"')]),t._v(" "),a("li",[t._v('300 "multiple choices"')]),t._v(" "),a("li",[t._v('301 "moved permanently"')]),t._v(" "),a("li",[t._v('302 "moved temporarily"')]),t._v(" "),a("li",[t._v('303 "see other"')]),t._v(" "),a("li",[t._v('304 "not modified"')]),t._v(" "),a("li",[t._v('305 "use proxy"')]),t._v(" "),a("li",[t._v('307 "temporary redirect"')]),t._v(" "),a("li",[t._v('400 "bad request"')]),t._v(" "),a("li",[t._v('401 "unauthorized"')]),t._v(" "),a("li",[t._v('402 "payment required"')]),t._v(" "),a("li",[t._v('403 "forbidden"')]),t._v(" "),a("li",[t._v('404 "not found"')]),t._v(" "),a("li",[t._v('405 "method not allowed"')]),t._v(" "),a("li",[t._v('406 "not acceptable"')]),t._v(" "),a("li",[t._v('407 "proxy authentication required"')]),t._v(" "),a("li",[t._v('408 "request time-out"')]),t._v(" "),a("li",[t._v('409 "conflict"')]),t._v(" "),a("li",[t._v('410 "gone"')]),t._v(" "),a("li",[t._v('411 "length required"')]),t._v(" "),a("li",[t._v('412 "precondition failed"')]),t._v(" "),a("li",[t._v('413 "request entity too large"')]),t._v(" "),a("li",[t._v('414 "request-uri too large"')]),t._v(" "),a("li",[t._v('415 "unsupported media type"')]),t._v(" "),a("li",[t._v('416 "requested range not satisfiable"')]),t._v(" "),a("li",[t._v('417 "expectation failed"')]),t._v(" "),a("li",[t._v('418 "i\'m a teapot"')]),t._v(" "),a("li",[t._v('422 "unprocessable entity"')]),t._v(" "),a("li",[t._v('423 "locked"')]),t._v(" "),a("li",[t._v('424 "failed dependency"')]),t._v(" "),a("li",[t._v('425 "unordered collection"')]),t._v(" "),a("li",[t._v('426 "upgrade required"')]),t._v(" "),a("li",[t._v('428 "precondition required"')]),t._v(" "),a("li",[t._v('429 "too many requests"')]),t._v(" "),a("li",[t._v('431 "request header fields too large"')]),t._v(" "),a("li",[t._v('500 "internal server error"')]),t._v(" "),a("li",[t._v('501 "not implemented"')]),t._v(" "),a("li",[t._v('502 "bad gateway"')]),t._v(" "),a("li",[t._v('503 "service unavailable"')]),t._v(" "),a("li",[t._v('504 "gateway time-out"')]),t._v(" "),a("li",[t._v('505 "http version not supported"')]),t._v(" "),a("li",[t._v('506 "variant also negotiates"')]),t._v(" "),a("li",[t._v('507 "insufficient storage"')]),t._v(" "),a("li",[t._v('509 "bandwidth limit exceeded"')]),t._v(" "),a("li",[t._v('510 "not extended"')]),t._v(" "),a("li",[t._v('511 "network authentication required"')])]),t._v(" "),a("p",[t._v("Don't worry too much about memorizing these strings, if you have a typo an error will be thrown,\ndisplaying this list so you can make a correction.")]),t._v(" "),a("h3",{attrs:{id:"response-message"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#response-message","aria-hidden":"true"}},[t._v("#")]),t._v(" response.message")]),t._v(" "),a("p",[t._v("Get response status message. By default, "),a("code",[t._v("response.message")]),t._v(" is\nassociated with "),a("code",[t._v("response.status")]),t._v(".")]),t._v(" "),a("h3",{attrs:{id:"response-message-2"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#response-message-2","aria-hidden":"true"}},[t._v("#")]),t._v(" response.message=")]),t._v(" "),a("p",[t._v("Set response status message to the given value.")]),t._v(" "),a("h3",{attrs:{id:"response-length"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#response-length","aria-hidden":"true"}},[t._v("#")]),t._v(" response.length=")]),t._v(" "),a("p",[t._v("Set response Content-Length to the given value.")]),t._v(" "),a("h3",{attrs:{id:"response-length-2"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#response-length-2","aria-hidden":"true"}},[t._v("#")]),t._v(" response.length")]),t._v(" "),a("p",[t._v("Return response Content-Length as a number when present, or deduce\nfrom "),a("code",[t._v("this.body")]),t._v(" when possible, or "),a("code",[t._v("undefined")]),t._v(".")]),t._v(" "),a("h3",{attrs:{id:"response-body"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#response-body","aria-hidden":"true"}},[t._v("#")]),t._v(" response.body")]),t._v(" "),a("p",[t._v("Get response body.")]),t._v(" "),a("h3",{attrs:{id:"response-body-2"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#response-body-2","aria-hidden":"true"}},[t._v("#")]),t._v(" response.body=")]),t._v(" "),a("p",[t._v("Set response body to one of the following:")]),t._v(" "),a("ul",[a("li",[a("code",[t._v("string")]),t._v(" written")]),t._v(" "),a("li",[a("code",[t._v("Buffer")]),t._v(" written")]),t._v(" "),a("li",[a("code",[t._v("Stream")]),t._v(" piped")]),t._v(" "),a("li",[a("code",[t._v("Object")]),t._v(" json-stringified")]),t._v(" "),a("li",[a("code",[t._v("null")]),t._v(" no content response")])]),t._v(" "),a("p",[t._v("If "),a("code",[t._v("response.status")]),t._v(" has not been set, Strapi will automatically set the status to "),a("code",[t._v("200")]),t._v(" or "),a("code",[t._v("204")]),t._v(".")]),t._v(" "),a("h4",{attrs:{id:"string"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#string","aria-hidden":"true"}},[t._v("#")]),t._v(" String")]),t._v(" "),a("p",[t._v("The Content-Type is defaulted to text/html or text/plain, both with\na default charset of utf-8. The Content-Length field is also set.")]),t._v(" "),a("h4",{attrs:{id:"buffer"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#buffer","aria-hidden":"true"}},[t._v("#")]),t._v(" Buffer")]),t._v(" "),a("p",[t._v("The Content-Type is defaulted to application/octet-stream, and Content-Length\nis also set.")]),t._v(" "),a("h4",{attrs:{id:"stream"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#stream","aria-hidden":"true"}},[t._v("#")]),t._v(" Stream")]),t._v(" "),a("p",[t._v("The Content-Type is defaulted to application/octet-stream.")]),t._v(" "),a("h4",{attrs:{id:"object"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#object","aria-hidden":"true"}},[t._v("#")]),t._v(" Object")]),t._v(" "),a("p",[t._v("The Content-Type is defaulted to application/json.")]),t._v(" "),a("h3",{attrs:{id:"response-get-field"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#response-get-field","aria-hidden":"true"}},[t._v("#")]),t._v(" response.get(field)")]),t._v(" "),a("p",[t._v("Get a response header field value with case-insensitive "),a("code",[t._v("field")]),t._v(".")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{attrs:{class:"token keyword"}},[t._v("const")]),t._v(" etag "),a("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),a("span",{attrs:{class:"token keyword"}},[t._v("this")]),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token keyword"}},[t._v("get")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{attrs:{class:"token string"}},[t._v("'ETag'")]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),a("h3",{attrs:{id:"response-set-field-value"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#response-set-field-value","aria-hidden":"true"}},[t._v("#")]),t._v(" response.set(field, value)")]),t._v(" "),a("p",[t._v("Set response header "),a("code",[t._v("field")]),t._v(" to "),a("code",[t._v("value")]),t._v(":")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{attrs:{class:"token keyword"}},[t._v("this")]),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token keyword"}},[t._v("set")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{attrs:{class:"token string"}},[t._v("'Cache-Control'")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v("'no-cache'")]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),a("h3",{attrs:{id:"response-append-field-value"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#response-append-field-value","aria-hidden":"true"}},[t._v("#")]),t._v(" response.append(field, value)")]),t._v(" "),a("p",[t._v("Append additional header "),a("code",[t._v("field")]),t._v(" with value "),a("code",[t._v("val")]),t._v(".")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{attrs:{class:"token keyword"}},[t._v("this")]),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("append")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{attrs:{class:"token string"}},[t._v("'Link'")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v("'<http://127.0.0.1/>'")]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),a("h3",{attrs:{id:"response-set-fields"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#response-set-fields","aria-hidden":"true"}},[t._v("#")]),t._v(" response.set(fields)")]),t._v(" "),a("p",[t._v("Set several response header "),a("code",[t._v("fields")]),t._v(" with an object:")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{attrs:{class:"token keyword"}},[t._v("this")]),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token keyword"}},[t._v("set")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v("'Etag'")]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v("'1234'")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v("'Last-Modified'")]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" date\n"),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),a("h3",{attrs:{id:"response-remove-field"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#response-remove-field","aria-hidden":"true"}},[t._v("#")]),t._v(" response.remove(field)")]),t._v(" "),a("p",[t._v("Remove header "),a("code",[t._v("field")]),t._v(".")]),t._v(" "),a("h3",{attrs:{id:"response-type"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#response-type","aria-hidden":"true"}},[t._v("#")]),t._v(" response.type")]),t._v(" "),a("p",[t._v("Get response "),a("code",[t._v("Content-Type")]),t._v(' void of parameters such as "charset".')]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{attrs:{class:"token keyword"}},[t._v("const")]),t._v(" ct "),a("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),a("span",{attrs:{class:"token keyword"}},[t._v("this")]),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),t._v("type"),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),a("span",{attrs:{class:"token comment"}},[t._v('// => "image/png"')]),t._v("\n")])])]),a("h3",{attrs:{id:"response-type-2"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#response-type-2","aria-hidden":"true"}},[t._v("#")]),t._v(" response.type=")]),t._v(" "),a("p",[t._v("Set response "),a("code",[t._v("Content-Type")]),t._v(" via mime string or file extension.")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{attrs:{class:"token keyword"}},[t._v("this")]),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),t._v("type "),a("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v("'text/plain; charset=utf-8'")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),a("span",{attrs:{class:"token keyword"}},[t._v("this")]),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),t._v("type "),a("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v("'image/png'")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),a("span",{attrs:{class:"token keyword"}},[t._v("this")]),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),t._v("type "),a("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v("'.png'")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),a("span",{attrs:{class:"token keyword"}},[t._v("this")]),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),t._v("type "),a("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v("'png'")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),a("p",[t._v("Note: when appropriate a "),a("code",[t._v("charset")]),t._v(" is selected for you, for\nexample "),a("code",[t._v("response.type = 'html'")]),t._v(' will default to "utf-8", however\nwhen explicitly defined in full as '),a("code",[t._v("response.type = 'text/html'")]),t._v("\nno charset is assigned.")]),t._v(" "),a("h3",{attrs:{id:"response-is-types"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#response-is-types","aria-hidden":"true"}},[t._v("#")]),t._v(" response.is(types...)")]),t._v(" "),a("p",[t._v("Very similar to "),a("code",[t._v("this.request.is()")]),t._v(".\nCheck whether the response type is one of the supplied types.\nThis is particularly useful for creating middleware that\nmanipulate responses.")]),t._v(" "),a("p",[t._v("For example, this is a middleware that minifies\nall HTML responses except for streams.")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{attrs:{class:"token keyword"}},[t._v("const")]),t._v(" minify "),a("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),a("span",{attrs:{class:"token function"}},[t._v("require")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{attrs:{class:"token string"}},[t._v("'html-minifier'")]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nstrapi"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),t._v("app"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("use")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),a("span",{attrs:{class:"token operator"}},[t._v("*")]),a("span",{attrs:{class:"token function"}},[t._v("minifyHTML")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("next"),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token keyword"}},[t._v("yield")]),t._v(" next"),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n "),a("span",{attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{attrs:{class:"token operator"}},[t._v("!")]),a("span",{attrs:{class:"token keyword"}},[t._v("this")]),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),t._v("response"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("is")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{attrs:{class:"token string"}},[t._v("'html'")]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token keyword"}},[t._v("return")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n "),a("span",{attrs:{class:"token keyword"}},[t._v("const")]),t._v(" body "),a("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),a("span",{attrs:{class:"token keyword"}},[t._v("this")]),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),t._v("body"),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),a("span",{attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{attrs:{class:"token operator"}},[t._v("!")]),t._v("body "),a("span",{attrs:{class:"token operator"}},[t._v("||")]),t._v(" body"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),t._v("pipe"),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token keyword"}},[t._v("return")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n "),a("span",{attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("Buffer"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("isBuffer")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("body"),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n body "),a("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" body"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("toString")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n "),a("span",{attrs:{class:"token keyword"}},[t._v("this")]),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),t._v("body "),a("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),a("span",{attrs:{class:"token function"}},[t._v("minify")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),t._v("body"),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),a("h3",{attrs:{id:"response-redirect-url-alt"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#response-redirect-url-alt","aria-hidden":"true"}},[t._v("#")]),t._v(" response.redirect(url, [alt])")]),t._v(" "),a("p",[t._v("Perform a [302] redirect to "),a("code",[t._v("url")]),t._v(".")]),t._v(" "),a("p",[t._v('The string "back" is special-cased\nto provide Referrer support, when Referrer\nis not present '),a("code",[t._v("alt")]),t._v(' or "/" is used.')]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{attrs:{class:"token keyword"}},[t._v("this")]),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("redirect")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{attrs:{class:"token string"}},[t._v("'back'")]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),a("span",{attrs:{class:"token keyword"}},[t._v("this")]),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("redirect")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{attrs:{class:"token string"}},[t._v("'back'")]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v("'/index.html'")]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),a("span",{attrs:{class:"token keyword"}},[t._v("this")]),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("redirect")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{attrs:{class:"token string"}},[t._v("'/login'")]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),a("span",{attrs:{class:"token keyword"}},[t._v("this")]),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("redirect")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{attrs:{class:"token string"}},[t._v("'http://google.com'")]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),a("p",[t._v("To alter the default status of "),a("code",[t._v("302")]),t._v(", simply assign the status\nbefore or after this call. To alter the body, assign it after this call:")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{attrs:{class:"token keyword"}},[t._v("this")]),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),t._v("status "),a("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),a("span",{attrs:{class:"token number"}},[t._v("301")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),a("span",{attrs:{class:"token keyword"}},[t._v("this")]),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("redirect")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{attrs:{class:"token string"}},[t._v("'/cart'")]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),a("span",{attrs:{class:"token keyword"}},[t._v("this")]),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),t._v("body "),a("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v("'Redirecting to shopping cart'")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),a("h3",{attrs:{id:"response-attachment-filename"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#response-attachment-filename","aria-hidden":"true"}},[t._v("#")]),t._v(" response.attachment([filename])")]),t._v(" "),a("p",[t._v("Set "),a("code",[t._v("Content-Disposition")]),t._v(' to "attachment" to signal the client\nto prompt for download. Optionally specify the '),a("code",[t._v("filename")]),t._v(" of the\ndownload.")]),t._v(" "),a("h3",{attrs:{id:"response-headersent"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#response-headersent","aria-hidden":"true"}},[t._v("#")]),t._v(" response.headerSent")]),t._v(" "),a("p",[t._v("Check if a response header has already been sent. Useful for seeing\nif the client may be notified on error.")]),t._v(" "),a("h3",{attrs:{id:"response-lastmodified"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#response-lastmodified","aria-hidden":"true"}},[t._v("#")]),t._v(" response.lastModified")]),t._v(" "),a("p",[t._v("Return the "),a("code",[t._v("Last-Modified")]),t._v(" header as a "),a("code",[t._v("Date")]),t._v(", if it exists.")]),t._v(" "),a("h3",{attrs:{id:"response-lastmodified-2"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#response-lastmodified-2","aria-hidden":"true"}},[t._v("#")]),t._v(" response.lastModified=")]),t._v(" "),a("p",[t._v("Set the "),a("code",[t._v("Last-Modified")]),t._v(" header as an appropriate UTC string.\nYou can either set it as a "),a("code",[t._v("Date")]),t._v(" or date string.")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{attrs:{class:"token keyword"}},[t._v("this")]),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),t._v("response"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),t._v("lastModified "),a("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),a("span",{attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),a("span",{attrs:{class:"token class-name"}},[t._v("Date")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),a("h3",{attrs:{id:"response-etag"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#response-etag","aria-hidden":"true"}},[t._v("#")]),t._v(" response.etag=")]),t._v(" "),a("p",[t._v("Set the ETag of a response including the wrapped "),a("code",[t._v('"')]),t._v("s.\nNote that there is no corresponding "),a("code",[t._v("response.etag")]),t._v(" getter.")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{attrs:{class:"token keyword"}},[t._v("this")]),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),t._v("response"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),t._v("etag "),a("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" crypto"),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("createHash")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{attrs:{class:"token string"}},[t._v("'md5'")]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("update")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{attrs:{class:"token keyword"}},[t._v("this")]),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),t._v("body"),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),a("span",{attrs:{class:"token function"}},[t._v("digest")]),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{attrs:{class:"token string"}},[t._v("'hex'")]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),a("h3",{attrs:{id:"response-vary-field"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#response-vary-field","aria-hidden":"true"}},[t._v("#")]),t._v(" response.vary(field)")]),t._v(" "),a("p",[t._v("Vary on "),a("code",[t._v("field")]),t._v(".")])])}],!1,null,null,null);n.options.__file="response.md";s.default=n.exports}}]);