Class: QgsServerResponse

Note

This is an abstract class, with methods which must be implemented by a subclass.

The following methods must be implemented: clear(), data(), header(), headers(), headersSent(), io(), removeHeader(), sendError(), setHeader(), setStatusCode(), statusCode(), truncate()

Class Hierarchy

Inheritance diagram of qgis.server.QgsServerResponse

Subclasses

QgsBufferServerResponse

Defines a buffered server response.

Abstract Methods

clear

Reset all headers and content for this response

data

Gets the data written so far

header

Returns the header value

headers

Returns the header value

headersSent

Returns True if the headers have already been sent

io

Returns the underlying QIODevice

removeHeader

Clear header Undo a previous 'setHeader' call

sendError

Send error This method delegates error handling at the server level.

setHeader

Set Header entry Add Header entry to the response Note that it is usually an error to set Header after data have been sent through the wire

setStatusCode

Set the http status code

statusCode

Returns the http status code

truncate

Truncate data

Methods

finish

Finish the response, ending the transaction.

flush

Flushes the current output buffer to the network

Virtual Methods

In PyQGIS, only methods marked as virtual can be safely overridden in a Python subclass of QgsServerResponse. See the FAQ for more details.

feedback

Returns the socket feedback if any

write

Write string This is a convenient method that will write directly to the underlying I/O device

class qgis.server.QgsServerResponse[source]
class qgis.server.QgsServerResponse(a0: QgsServerResponse)

Bases: object

abstract clear(self)[source]

Reset all headers and content for this response

abstract data(self) QByteArray[source]

Gets the data written so far

This is implementation dependent: some implementations may not give access to the underlying and return an empty array.

Note that each call to ‘flush’ may empty the buffer and in case of streaming process you may get partial content

Return type:

QByteArray

virtual feedback(self) QgsFeedback | None[source]

Returns the socket feedback if any

Added in version 3.36.

Return type:

Optional[QgsFeedback]

finish(self)[source]

Finish the response, ending the transaction. The default implementation does nothing.

flush(self)[source]

Flushes the current output buffer to the network

flush()’ may be called multiple times. For HTTP transactions headers will be written on the first call to ‘flush()’. The default implementation does nothing.

abstract header(self, key: str | None) str[source]

Returns the header value

Parameters:

key (Optional[str])

Return type:

str

abstract headers(self) Dict[str, str]

Returns the header value

Return type:

Dict[str, str]

abstract headersSent(self) bool[source]

Returns True if the headers have already been sent

Return type:

bool

abstract io(self) QIODevice | None[source]

Returns the underlying QIODevice

Return type:

Optional[QIODevice]

abstract removeHeader(self, key: str | None)[source]

Clear header Undo a previous ‘setHeader’ call

Parameters:

key (Optional[str])

abstract sendError(self, code: int, message: str | None)[source]

Send error This method delegates error handling at the server level. This is different from calling setReturnCode() which let you return a specific response body. Calling sendError() will end the transaction and any attempt to write data or set headers will be an error.

Parameters:
  • code (int) – HHTP return code value

  • message (Optional[str]) – An informative error message

abstract setHeader(self, key: str | None, value: str | None)[source]

Set Header entry Add Header entry to the response Note that it is usually an error to set Header after data have been sent through the wire

Parameters:
  • key (Optional[str])

  • value (Optional[str])

abstract setStatusCode(self, code: int)[source]

Set the http status code

Parameters:

code (int) – HTTP status code value

abstract statusCode(self) int[source]

Returns the http status code

Return type:

int

abstract truncate(self)[source]

Truncate data

Clear internal buffer

virtual write(self, data: str | None)[source]

Write string This is a convenient method that will write directly to the underlying I/O device

Parameters:

data (Optional[str])

virtual write(self, byteArray: QByteArray | bytes | bytearray) int[source]

Write chunk of data This is a convenient method that will write directly to the underlying I/O device

Return type:

int

Returns:

the number of bytes that were actually written

Parameters:

byteArray (Union[QByteArray, bytes, bytearray])

virtual write(self, ex: QgsServerException)[source]

Write server exception

Parameters:

ex (QgsServerException)