--- parser3/src/include/pa_sapi.h 2016/12/24 22:53:30 1.32 +++ parser3/src/include/pa_sapi.h 2020/10/14 00:07:42 1.35 @@ -1,20 +1,20 @@ /** @file Parser: web server api interface object decl. - Copyright (c) 2001-2015 Art. Lebedev Studio (http://www.artlebedev.com) + Copyright (c) 2001-2017 Art. Lebedev Studio (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ #ifndef PA_SAPI_H #define PA_SAPI_H -#define IDENT_PA_SAPI_H "$Id: pa_sapi.h,v 1.32 2016/12/24 22:53:30 moko Exp $" +#define IDENT_PA_SAPI_H "$Id: pa_sapi.h,v 1.35 2020/10/14 00:07:42 moko Exp $" // includes - -#include "pa_types.h" +#include "pa_common.h" #include "pa_array.h" +#include "pa_exception.h" // forwards class SAPI_Info; @@ -25,8 +25,6 @@ struct SAPI { static void log(SAPI_Info& info, const char* fmt, ...); /// log error message & exit static void die(const char* fmt, ...); - /// log error message & abort[write core] - static void abort(const char* fmt, ...); /// read POST request bytes static size_t read_post(SAPI_Info& info, char *buf, size_t max_bytes); /// add response header attribute [but do not send it to client] @@ -36,6 +34,14 @@ struct SAPI { /// output body bytes static size_t send_body(SAPI_Info& info, const void *buf, size_t size); + static void send_error(SAPI_Info& info, const char *exception_cstr, const char *status = "500"){ + // capitalized headers passed for preventing malloc during capitalization + add_header_attribute(info, HTTP_STATUS_CAPITALIZED, status); + add_header_attribute(info, HTTP_CONTENT_TYPE_CAPITALIZED, "text/plain"); + send_header(info); + send_body(info, exception_cstr, strlen(exception_cstr)); + } + class Env { public: /// entire environment