class ServerResponse extends Object with StObject
This object is created internally by an HTTP server, not by the user. It is
passed as the second parameter to the 'request'
event.
- Annotations
- @JSType() @JSImport("http", "ServerResponse") @native()
- Since
v0.1.17
- Alphabetic
- By Inheritance
- ServerResponse
- StObject
- Object
- Any
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Instance Constructors
- new ServerResponse(req: IncomingMessage)
- new ServerResponse()
- Attributes
- protected
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def assignSocket(socket: Socket): Unit
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
- def detachSocket(socket: Socket): Unit
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def hasOwnProperty(v: String): Boolean
- Definition Classes
- Object
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def isPrototypeOf(v: Object): Boolean
- Definition Classes
- Object
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def propertyIsEnumerable(v: String): Boolean
- Definition Classes
- Object
- var statusCode: Double
When using implicit headers (not calling
response.writeHead()
explicitly), this property controls the status code that will be sent to the client when the headers get flushed.When using implicit headers (not calling
response.writeHead()
explicitly), this property controls the status code that will be sent to the client when the headers get flushed.js response.statusCode = 404;
After response header was sent to the client, this property indicates the status code which was sent out.
- Since
v0.4.0
- var statusMessage: String
When using implicit headers (not calling
response.writeHead()
explicitly), this property controls the status message that will be sent to the client when the headers get flushed.When using implicit headers (not calling
response.writeHead()
explicitly), this property controls the status message that will be sent to the client when the headers get flushed. If this is left asundefined
then the standard message for the status code will be used.js response.statusMessage = 'Not found';
After response header was sent to the client, this property indicates the status message which was sent out.
- Since
v0.11.8
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toLocaleString(): String
- Definition Classes
- Object
- def toString(): String
- Definition Classes
- AnyRef → Any
- def valueOf(): Any
- Definition Classes
- Object
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- def writeContinue(callback: Function0[Unit]): Unit
- def writeContinue(): Unit
Sends a HTTP/1.1 100 Continue message to the client, indicating that the request body should be sent.
Sends a HTTP/1.1 100 Continue message to the client, indicating that the request body should be sent. See the
'checkContinue'
event onServer
.- Since
v0.3.0
- def writeHead(statusCode: Double, statusMessage: Unit, headers: Array[OutgoingHttpHeader]): ServerResponse.this.type
- def writeHead(statusCode: Double, statusMessage: Unit, headers: OutgoingHttpHeaders): ServerResponse.this.type
- def writeHead(statusCode: Double, statusMessage: String, headers: Array[OutgoingHttpHeader]): ServerResponse.this.type
- def writeHead(statusCode: Double, statusMessage: String, headers: OutgoingHttpHeaders): ServerResponse.this.type
- def writeHead(statusCode: Double, statusMessage: String): ServerResponse.this.type
- def writeHead(statusCode: Double, headers: Array[OutgoingHttpHeader]): ServerResponse.this.type
- def writeHead(statusCode: Double, headers: OutgoingHttpHeaders): ServerResponse.this.type
- def writeHead(statusCode: Double): ServerResponse.this.type
Sends a response header to the request.
Sends a response header to the request. The status code is a 3-digit HTTP status code, like
404
. The last argument,headers
, are the response headers. Optionally one can give a human-readablestatusMessage
as the second argument.headers
may be anArray
where the keys and values are in the same list. It is _not_ a list of tuples. So, the even-numbered offsets are key values, and the odd-numbered offsets are the associated values. The array is in the same format asrequest.rawHeaders
.Returns a reference to the
ServerResponse
, so that calls can be chained.js const body = 'hello world'; response .writeHead(200, { 'Content-Length': Buffer.byteLength(body), 'Content-Type': 'text/plain' }) .end(body);
This method must only be called once on a message and it must be called before
response.end()
is called.If
response.write()
orresponse.end()
are called before calling this, the implicit/mutable headers will be calculated and call this function.When headers have been set with
response.setHeader()
, they will be merged with any headers passed toresponse.writeHead()
, with the headers passed toresponse.writeHead()
given precedence.If this method is called and
response.setHeader()
has not been called, it will directly write the supplied header values onto the network channel without caching internally, and theresponse.getHeader()
on the header will not yield the expected result. If progressive population of headers is desired with potential future retrieval and modification, useresponse.setHeader()
instead.js // Returns content-type = text/plain const server = http.createServer((req, res) => { res.setHeader('Content-Type', 'text/html'); res.setHeader('X-Foo', 'bar'); res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('ok'); });
Content-Length
is given in bytes, not characters. UseBuffer.byteLength()
to determine the length of the body in bytes. Node.js does not check whetherContent-Length
and the length of the body which has been transmitted are equal or not.Attempting to set a header field name or value that contains invalid characters will result in a
TypeError
being thrown.- Since
v0.1.30
- def writeProcessing(): Unit
Sends a HTTP/1.1 102 Processing message to the client, indicating that the request body should be sent.
Sends a HTTP/1.1 102 Processing message to the client, indicating that the request body should be sent.
- Since
v10.0.0
Deprecated Value Members
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable]) @Deprecated
- Deprecated