diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2024-03-11 18:59:53 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2024-03-11 18:59:53 +0000 |
commit | 9b78be4f03b67d4feca3081b9427ac5ed1d241c9 (patch) | |
tree | ab6bb423640ace63bbfa71de24a167fbfd2d7dc5 /src/rspamd_proxy.c | |
parent | a4de9b2ebb9aa47ebff0c71fb980daf4eb5ca0cc (diff) | |
download | rspamd-9b78be4f03b67d4feca3081b9427ac5ed1d241c9.tar.gz rspamd-9b78be4f03b67d4feca3081b9427ac5ed1d241c9.zip |
[Feature] Support reply in message pack format
Rspamd currently sends reply in JSON format. However, message pack seems to
be a better choice for a compatible client. It is faster and does not need
escaping or even UTF8 validation. This is a surface for further updates.
Diffstat (limited to 'src/rspamd_proxy.c')
-rw-r--r-- | src/rspamd_proxy.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/rspamd_proxy.c b/src/rspamd_proxy.c index 9139866b5..ad6edd333 100644 --- a/src/rspamd_proxy.c +++ b/src/rspamd_proxy.c @@ -1713,7 +1713,15 @@ rspamd_proxy_scan_self_reply(struct rspamd_task *task) struct rspamd_http_message *msg; struct rspamd_proxy_session *session = task->fin_arg, *nsession; ucl_object_t *rep = NULL; + int out_type = UCL_EMIT_JSON_COMPACT; const char *ctype = "application/json"; + const rspamd_ftok_t *accept_hdr = rspamd_task_get_request_header(task, "Accept"); + + if (accept_hdr && rspamd_substring_search(accept_hdr->begin, accept_hdr->len, + "application/msgpack", sizeof("application/msgpack") - 1)) { + ctype = "application/msgpack"; + out_type = UCL_EMIT_MSGPACK; + } msg = rspamd_http_new_message(HTTP_RESPONSE); msg->date = time(NULL); @@ -1726,7 +1734,7 @@ rspamd_proxy_scan_self_reply(struct rspamd_task *task) case CMD_CHECK_SPAMC: case CMD_CHECK_V2: rspamd_task_set_finish_time(task); - rspamd_protocol_http_reply(msg, task, &rep); + rspamd_protocol_http_reply(msg, task, &rep, out_type); rspamd_protocol_write_log_pipe(task); break; case CMD_PING: |