Class: QgsServerResponse

Note

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

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

List of all members, including inherited members

Class Hierarchy

Inheritance diagram of qgis.server.QgsServerResponse

Subclasses

QgsBufferServerResponse

Defines a buffered server response.

Constructor

__init__

Abstract Methods

addHeader

Add a header value for the given key, without replacing any existing value for the same key Add Header entry to the response

clear

Reset all headers and content for this response

data

Gets the data written so far

fullHeader

Returns a (possibly empty) list of all the header values for the given key

fullHeaders

Returns all the header values

header

Returns a single header value for a given key

headers

Returns the header values as a map: only the last value is returned if multiple values are set for the same header

headersSent

Returns True if the headers have already been sent

io

Returns the underlying QIODevice

removeHeader

Clear all header values for the given key Undo a previous 'setHeader' call

sendError

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

setHeader

Set a single header value replacing any existing value(s) for the same key

setStatusCode

Set the http status code

statusCode

Returns the http status code

truncate

Truncate data

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

finish

Finish the response, ending the transaction.

flush

Flushes the current output buffer to the network

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 addHeader(self, key: str | None, value: str | None)[source]

Add a header value for the given key, without replacing any existing value for the same key Add Header entry to the response

Note

that it is usually an error to set Header after data have been sent through the wire

See also

setHeader() for a method that replaces any existing value(s) for the same header key

Added in version 4.2.

Parameters:
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]

virtual finish(self)[source]

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

virtual 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 fullHeader(self, key: str | None) list[str]

Returns a (possibly empty) list of all the header values for the given key

See also

header() to get only the last value for a given header key

Added in version 4.2.

Parameters:

key (Optional[str])

Return type:

list[str]

abstract fullHeaders(self) Any

Returns all the header values

See also

headers() to get only the last value for each header key

Added in version 4.2.

Return type:

Any

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

Returns a single header value for a given key

Note

if multiple values are set for the same key, the last one is returned

Deprecated since version 4.2: Use fullHeader() instead.

Parameters:

key (Optional[str])

Return type:

str

abstract headers(self) dict[str, str]

Returns the header values as a map: only the last value is returned if multiple values are set for the same header

See also

fullHeaders() to get all the values for all the headers

Deprecated since version 4.2: Use fullHeaders() instead.

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 all header values for the given key 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 a single header value replacing any existing value(s) for the same key

Note

that it is usually an error to set Header after data have been sent through the wire

See also

addHeader() for a method that allows setting multiple values for the same header key

See also

removeHeader() to clear header values for a given key

Parameters:
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

write(self, byteArray: Union[QByteArray, bytes, bytearray, memoryview]) -> int Write chunk of data This is a convenient method that will write directly to the underlying I/O device

Returns:

the number of bytes that were actually written

write(self, ex: QgsServerException) Write server exception

Parameters:

data (Optional[str])