1 #ifndef HTTP_REPLY__HPP
2 #define HTTP_REPLY__HPP
84 const char * cd_uid) :
131 m_Req->res.content_length = content_length;
134 "Reply has already started");
151 return m_Req->bytes_sent;
155 void Send(
const char * payload,
size_t payload_len,
156 bool is_persist,
bool is_last)
158 if (payload_len == 0) {
167 body.base = (
char*)payload;
168 body.len = payload_len;
170 body = h2o_strdup(&
m_Req->pool, payload, payload_len);
172 x_DoSend(&body, payload_len > 0 ? 1 : 0, is_last);
176 void Send(std::vector<h2o_iovec_t> & payload,
bool is_last)
178 size_t payload_size = payload.size();
179 if (payload_size > 0 || is_last) {
180 if (payload_size > 0)
181 x_DoSend(&payload.front(), payload_size, is_last);
183 x_DoSend(
nullptr, payload_size, is_last);
192 void SendOk(
const char * payload,
size_t payload_len,
bool is_persist)
193 {
Send(payload, payload_len, is_persist,
true); }
195 void Send202(
const char * payload,
size_t payload_len)
197 h2o_iovec_t body = h2o_strdup(&
m_Req->pool, payload, payload_len);
230 "Request has not been postponed");
234 }
catch (
const std::exception & e) {
237 Error(
"unexpected failure");
246 "Request has not been postponed");
277 "There are no assigned pending requests");
284 return h2o_strdup(&
m_Req->pool,
285 reinterpret_cast<const char*
>(
data),
size);
288 "Request pool is not available");
301 Send(
nullptr, 0,
true,
true);
309 {
return static_pointer_cast<CCassDataCallbackReceiver>(
m_DataReady); }
327 virtual void OnData()
override;
343 PSG_ERROR(
"A responce generator is created more than once "
349 h2o_mem_alloc_shared(&
m_Req->pool,
368 PSG_TRACE(
"CHttpReply::Stop: need cancel");
389 static void s_StopCB(h2o_generator_t * _generator, h2o_req_t * req)
397 static void s_ProceedCB(h2o_generator_t * _generator, h2o_req_t * req)
423 m_Req->res.status = status;
424 m_Req->res.reason = reason;
434 "Request has already been finished");
440 int status=200,
const char * reason=
k_ReasonOK)
446 "is_last: " << is_last <<
", state: " <<
m_State);
456 is_last ? H2O_SEND_STATE_FINAL : H2O_SEND_STATE_IN_PROGRESS);
475 start_timestamp = psg_clock_t::now();
477 start_timestamp =
m_PendingReqs.front()->GetStartTimestamp();
494 const char * payload);
503 "Reply has already started");
507 h2o_add_header(&
m_Req->pool,
509 H2O_TOKEN_CONTENT_TYPE,
NULL,
510 H2O_STRLIT(
"application/json"));
513 h2o_add_header(&
m_Req->pool,
515 H2O_TOKEN_CONTENT_TYPE,
NULL,
516 H2O_STRLIT(
"text/html"));
519 h2o_add_header(&
m_Req->pool,
521 H2O_TOKEN_CONTENT_TYPE,
NULL,
522 H2O_STRLIT(
"application/octet-stream"));
525 h2o_add_header(&
m_Req->pool,
527 H2O_TOKEN_CONTENT_TYPE,
NULL,
528 H2O_STRLIT(
"text/plain"));
531 h2o_add_header(&
m_Req->pool,
533 H2O_TOKEN_CONTENT_TYPE,
NULL,
534 H2O_STRLIT(
"image/x-icon"));
537 h2o_add_header(&
m_Req->pool,
539 H2O_TOKEN_CONTENT_TYPE,
NULL,
540 H2O_STRLIT(
"application/x-ncbi-psg"));
552 static int cd_uid_size = strlen(
m_CdUid);
553 h2o_add_header_by_str(&
m_Req->pool, &
m_Req->res.headers,
554 H2O_STRLIT(
"X-CD-UID"), 0,
NULL,
void x_HandleConnectionState(int status, const char *reason)
CHttpReply(CHttpReply &&)=delete
void x_SetContentType(void)
void SetContentLength(uint64_t content_length)
CHttpConnection * GetHttpConnection(void)
CHttpReply(h2o_req_t *req, CHttpProto *proto, CHttpConnection *http_conn, const char *cd_uid)
void Send202(const char *payload, size_t payload_len)
h2o_iovec_t PrepareChunk(const unsigned char *data, unsigned int size)
CHttpReply & operator=(const CHttpReply &)=delete
void AssignGenerator(void)
void Send401(const char *payload)
bool IsCompleted(void) const
bool IsPostponed(void) const
void SetRequestId(size_t request_id)
void Send409(const char *payload)
CHttpReply(const CHttpReply &)=delete
size_t GetBytesSent(void) const
void CancelPending(bool from_flush=false)
EReplyState GetState(void) const
SRespGenerator * m_RespGenerator
void Send404(const char *payload)
CHttpConnection * m_HttpConn
void x_SendPsg503(const string &msg, EPSGS_PubseqGatewayErrorCode err_code)
static void s_ProceedCB(h2o_generator_t *_generator, h2o_req_t *req)
CHttpReply & operator=(CHttpReply &&)=delete
static void s_GeneratorDisposalCB(void *gen)
void x_DoSend(h2o_iovec_t *vec, size_t count, bool is_last, int status=200, const char *reason=k_ReasonOK)
bool IsOutputReady(void) const
void ResetPendingRequest(void)
bool GetExceedSoftLimitFlag(void) const
bool IsFinished(void) const
void AssignPendingReq(unique_ptr< CPendingOperation > pending_req)
bool CheckResetDataTriggered(void)
void x_SendCanceled(void)
void x_GenericSendError(int status, const char *head, const char *payload)
shared_ptr< CDataTrigger > m_DataReady
void Send400(const char *payload)
bool IsClosed(void) const
void Send502(const char *payload)
shared_ptr< CCassDataCallbackReceiver > GetDataReadyCB(void)
list< shared_ptr< CPendingOperation > > & GetPendingReqs(void)
void SetContentType(EPSGS_ReplyMimeType mime_type)
static void s_StopCB(h2o_generator_t *_generator, h2o_req_t *req)
void Send503(const char *payload)
void Send(std::vector< h2o_iovec_t > &payload, bool is_last)
void Error(const char *what)
void Send500(const char *payload)
list< shared_ptr< CPendingOperation > > m_PendingReqs
EPSGS_ReplyMimeType m_ReplyContentType
void Send(const char *payload, size_t payload_len, bool is_persist, bool is_last)
void NotifyClientConnectionDrop(void)
bool x_ConnectionPrecheck(size_t count, bool is_last)
void SendOk(const char *payload, size_t payload_len, bool is_persist)
void PrepareReplyMessage(const string &msg, CRequestStatus::ECode status, int err_code, EDiagSev severity, bool need_update_last_activity=true)
void PrepareReplyCompletion(CRequestStatus::ECode status, const psg_time_point_t &create_timestamp)
void Flush(EPSGS_ReplyFlush how)
@ eDiag_Error
Error message.
@ e503_ServiceUnavailable
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
static const char * k_Unauthorized
static const char * k_Conflict
static const char * k_BadGateway
static const char * k_ReasonAccepted
static const char * k_NotFound
static const char * k_BadRequest
static const char * k_ReasonOK
static const char * k_ServiceUnavailable
void OnLibh2oFinished(size_t request_id)
static const char * k_InternalServerError
const struct ncbi::grid::netcache::search::fields::SIZE size
#define PSG_ERROR(message)
#define PSG_WARNING(message)
#define PSG_TRACE(message)
EPSGS_PubseqGatewayErrorCode
psg_clock_t::time_point psg_time_point_t
static SLJIT_INLINE sljit_ins msg(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
CDataTrigger(const CDataTrigger &from)=delete
bool CheckResetTriggered(void)
CDataTrigger & operator=(CDataTrigger &&from)=delete
virtual void OnData() override
CDataTrigger(CHttpProto *proto)
CDataTrigger(CDataTrigger &&from)=delete
CDataTrigger & operator=(const CDataTrigger &from)=delete
std::atomic< bool > m_Triggered
h2o_generator_t m_Generator