/*
* Build a v3 multipart/mixed HTTP reply.
+ * Returns the Content-Type string (allocated on task pool) for use as
+ * the mime_type parameter in rspamd_http_connection_write_message.
*/
-void rspamd_protocol_http_reply_v3(struct rspamd_http_message *msg,
- struct rspamd_task *task)
+const char *
+rspamd_protocol_http_reply_v3(struct rspamd_http_message *msg,
+ struct rspamd_task *task)
{
int flags = RSPAMD_PROTOCOL_DEFAULT | RSPAMD_PROTOCOL_URLS;
ucl_object_t *top = rspamd_protocol_write_ucl(task, flags);
}
rspamd_fstring_t *reply = rspamd_multipart_response_serialize(resp, zstream);
- const char *ctype = rspamd_multipart_response_content_type(resp);
+ const char *resp_ctype = rspamd_multipart_response_content_type(resp);
- /* Set the content type on the HTTP message */
- rspamd_http_message_add_header(msg, "Content-Type", ctype);
+ /* Copy Content-Type to task pool so it survives after response is freed */
+ const char *pool_ctype = rspamd_mempool_strdup(task->task_pool, resp_ctype);
rspamd_http_message_set_body_from_fstring_steal(msg, reply);
rspamd_fstring_free(result_data);
slot = slot % MAX_AVG_TIME_SLOTS;
task->worker->srv->stat->avg_time.avg_time[slot] = processing_time;
}
+
+ return pool_ctype;
}
void rspamd_protocol_write_reply(struct rspamd_task *task, ev_tstamp timeout, struct rspamd_main *srv)
rspamd_protocol_write_log_pipe(task);
break;
case CMD_CHECK_V3:
- rspamd_protocol_http_reply_v3(msg, task);
+ ctype = rspamd_protocol_http_reply_v3(msg, task);
rspamd_protocol_write_log_pipe(task);
- /* Override ctype — it was set by the v3 reply builder via header */
- ctype = NULL;
break;
case CMD_PING:
msg_debug_protocol("writing pong to client");
* Optional body part contains rewritten message.
* @param msg HTTP response message to fill
* @param task task object
+ * @return Content-Type string (allocated on task pool) including boundary
*/
-void rspamd_protocol_http_reply_v3(struct rspamd_http_message *msg,
- struct rspamd_task *task);
+const char *rspamd_protocol_http_reply_v3(struct rspamd_http_message *msg,
+ struct rspamd_task *task);
/**
* Write data to log pipes
break;
case CMD_CHECK_V3:
rspamd_task_set_finish_time(task);
- rspamd_protocol_http_reply_v3(msg, task);
+ ctype = rspamd_protocol_http_reply_v3(msg, task);
rspamd_protocol_write_log_pipe(task);
- ctype = NULL; /* Content-Type set by rspamd_protocol_http_reply_v3 as a header */
break;
case CMD_PING:
rspamd_http_message_set_body(msg, "pong" CRLF, 6);
Expect Symbol GTUBE
checkv3 missing metadata part
- [Documentation] Send only message part without metadata, expect HTTP 400
+ [Documentation] Send only message part without metadata, expect HTTP 500 (400 error mapped to 5xx)
${status} = Scan File V3 Single Part message test message body
- Should Be Equal As Integers ${status} 400
+ Should Be Equal As Integers ${status} 500
checkv3 missing message part
- [Documentation] Send only metadata part without message, expect HTTP 400
+ [Documentation] Send only metadata part without message, expect HTTP 500 (400 error mapped to 5xx)
${status} = Scan File V3 Single Part metadata {} application/json
- Should Be Equal As Integers ${status} 400
+ Should Be Equal As Integers ${status} 500
checkv3 multipart/alternative MIME message
[Documentation] Message with own MIME boundaries (multipart/alternative) must parse correctly
Expect Symbol MIME_HTML_ONLY
checkv3 malformed boundary
- [Documentation] Send body with wrong boundary, expect HTTP 400
- Scan File V3 Expect Error ${GTUBE} 400
+ [Documentation] Send body with wrong boundary, expect HTTP 500 (400 error mapped to 5xx)
+ Scan File V3 Expect Error ${GTUBE} 500
... content_type_override=multipart/form-data; boundary=wrong-boundary-does-not-match