Configuration¶
porter
responses can be configured using a global configuration by setting attributes of porter.config
.
Responses¶
porter.config.return_request_id
(default: True): whether to include a UUID in the response object for the request. This is useful for matching responses to logs generated by theporter
app.
JSON Encoding¶
porter.config.json_encoder
specifies how response data is converted to JSON. Several encoders are available inporter.utils
. The default encoder isporter.utils.AppEncoder
, which ensures that NumPy datatypes are converted to pure Python ones and that Python types beyondstr
,list
,int
, etc. are encoded.
Error Responses¶
There are three settings that affect response data content for error conditions:
porter.config.return_message_on_error
(default: True): whether to include the error message in the error object of the JSON payload returned to the user.porter.config.return_traceback_on_error
(default: False): whether to include the complete exception traceback in the error object of the JSON payload returned to the user. This can be useful for development, but is not recommended for production apps.porter.config.return_user_data_on_error
(default: False): whether to include the user, i.e. request, data in the error object of the JSON payload returned to the user. This can be useful for development, but is not recommended for production apps.
Compression¶
porter supports gzip compression in request data by default. Request data will be decompressed if the header Content-Encoding: gzip
is included in the request. Values other than gzip
are ignored.
porter.config.support_response_gzip
(default: False): whether to compress response data when the request includes the headerAccept-Encoding: gzip
. Responses will not be compressed given other values ofAccept-Encoding
, and error responses are never compressed. If the response is compressed,porter
will set the headerContent-Encoding: gzip
in the response.