library/src/network/httpd/BP-HTTPdRequestHandlerHelpers.cc
// respond json from static text (this was originally BP_HTTPdRequestHandlerRespondJSONFromStaticText)
respond json from static text (this was originally BP_HTTPdRequestHandlerRespondJSONFromStaticText)
respond json from static text ( this was originally BP_HTTPdRequestHandlerRespondJSONFromStaticText )
BP_ERROR_T BP_HTTPdRequestHandlerRespondJSONFromStaticText(P_BP_HTTPD_REQUEST req, BP_ERROR_T ret_val, char *ret_json)
{
	if(!req)
		return ERR_FAILURE;
	if(!ret_json)
		return ERR_FAILURE;
	if(req->json_output)
	{
		BP_HTTPdAddExtraResponseHeaderToRequest(req, "Content-Type",	"application/json; charset=utf8");
		BP_HTTPdRequestAppendBinaryBuffer
		(
				req,
				ret_json,
				bpstrlen(ret_json)
		);
		BP_HTTPdRequestResponseSendPrepared
		(
			req,
			req->params.connection,
			BP_HTTPD_RESPONSE_CODE_200_OK
		);
		return ret_val;
	}
	else
	{
		BP_HTTPdAddExtraResponseHeaderToRequest(req, "Content-Type",	"application/json; charset=utf8");
		BP_HTTPdRequestAppendBinaryBuffer
		(
				req,
				"general_request_failure",
				bpstrlen("general_request_failure")
		);
		BP_HTTPdRequestResponseSendPrepared
		(
			req,
			req->params.connection,
			BP_HTTPD_RESPONSE_CODE_200_OK
		);
		return ret_val;
	}
	return ERR_SUCCESS;
}
BP_ERROR_T BP_HTTPdRequestHandlerRespondJSONFromStaticText ( P_BP_HTTPD_REQUEST req , BP_ERROR_T ret_val , char * ret_json ) { if ( ! req ) return ERR_FAILURE ; if ( ! ret_json ) return ERR_FAILURE ; if ( req -> json_output ) { BP_HTTPdAddExtraResponseHeaderToRequest ( req , " " , " " ) ; BP_HTTPdRequestAppendBinaryBuffer ( req , ret_json , bpstrlen ( ret_json ) ) ; BP_HTTPdRequestResponseSendPrepared ( req , req -> params . connection , BP_HTTPD_RESPONSE_CODE_200_OK ) ; return ret_val ; } else { BP_HTTPdAddExtraResponseHeaderToRequest ( req , " " , " " ) ; BP_HTTPdRequestAppendBinaryBuffer ( req , " " , bpstrlen ( " " ) ) ; BP_HTTPdRequestResponseSendPrepared ( req , req -> params . connection , BP_HTTPD_RESPONSE_CODE_200_OK ) ; return ret_val ; } return ERR_SUCCESS ; }
respond json from static text (this was originally BP_HTTPdRequestHandlerRespondJSONFromStaticText)
respond json from static text ( this was originally BP_HTTPdRequestHandlerRespondJSONFromStaticText )
// basic null checks // ensure we have json output // set response type to json // append the binary buffer to the output response // send the output response // return the defined return value // set response to json // append binary buffer // send the response to the client // return the defined return value // return indicating success (should technically never get here)