changed the way how the request's answer is created,
now winix can return json, xml, csv from out_main_stream or from frames and json from models removed from Request: bool send_bin_stream bool return_json bool return_info_only pt::Space info bool page_generated bool out_main_stream_use_html_filter bool out_streams_use_html_filter added to Request: enum AnswerSource enum AnswerContainer AnswerSource answer_source AnswerContainer answer_container bool use_ezc_engine std::wstring frame bool send_all_frames bool use_html_filter added to Config: // the name of the url parameter for returning all frames, e.g. https://domain.tld/mydir/myfunction/allframes // default: allframes std::wstring request_all_frames_parameter; // the name of the root element when serializing request answer to xml // default: winix std::wstring xml_root; algorithm (the whole algorithm is described in core/request.h): at the beginning of a request winix sets answer_source to models answer_container to text use_ezc_engine to true next answer_container and use_ezc_engine can be changed in the following way: 1. winix will look for 'Accept' http header and depending on the header winix will set: (not implemented yet) Accept | answer_container | use_ezc_engine ------------------------------------|----------------- application/json | json | false application/xml | xml | false text/csv | csv | false 2. next answer_container is set depending on 'container' url parameter container | answer_container --------------------------------------------------------- not present | don't change the value text | text json | json xml | xml csv | csv use_ezc_engine is set depending on 'answer' url parameter: answer | use_ezc_engine --------------------------------- not present | don't change the value html | true data | false if 'answer' is html then we take into account two more parameters: frame: frame_name (empty default) - if set then winix returns this specific frame allframes: (if present then winix returns all frames)
This commit is contained in:
@@ -249,6 +249,181 @@ public:
|
||||
*
|
||||
*/
|
||||
|
||||
// the algorithm how a request's answer is created
|
||||
// ------------------------------------------------------------------------------------------
|
||||
//
|
||||
// at the beginning of a request winix sets
|
||||
// answer_source to models
|
||||
// answer_container to text
|
||||
// use_ezc_engine to true
|
||||
//
|
||||
// next answer_container and use_ezc_engine can be changed in the following way:
|
||||
//
|
||||
// 1. winix will look for 'Accept' http header and depending on the header winix will set:
|
||||
//
|
||||
// Accept | answer_container | use_ezc_engine
|
||||
// ------------------------------------|-----------------
|
||||
// application/json | json | false
|
||||
// application/xml | xml | false
|
||||
// text/csv | csv | false
|
||||
//
|
||||
//
|
||||
//
|
||||
// 2. next answer_container is set depending on 'container' url parameter
|
||||
// container | answer_container
|
||||
// ---------------------------------------------------------
|
||||
// not present | don't change the value
|
||||
// text | text
|
||||
// json | json
|
||||
// xml | xml
|
||||
// csv | csv
|
||||
//
|
||||
// use_ezc_engine is set depending on 'answer' url parameter:
|
||||
// answer | use_ezc_engine
|
||||
// ---------------------------------
|
||||
// not present | don't change the value
|
||||
// html | true
|
||||
// data | false
|
||||
//
|
||||
// if 'answer' is html then we take into account two more parameters:
|
||||
// frame: frame_name (empty default) - if set then winix returns this specific frame
|
||||
// allframes: (if present then winix returns all frames)
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// the whole algorithm how the answer is created is shown below:
|
||||
//
|
||||
//
|
||||
// answer_source: bin_stream
|
||||
// |--------------->-------------- send out_bin_stream
|
||||
// |
|
||||
// |
|
||||
// |
|
||||
// |
|
||||
// | answer_source: models and use_ezc_engine: true
|
||||
// |------------------------>------------------------
|
||||
// | |
|
||||
// | use ezc engine
|
||||
// | for converting models
|
||||
// | to out_main_stream and frame_streams
|
||||
// | |
|
||||
// | change answer_source to
|
||||
// | frame_stream (if there is 'allframes' parameter or 'frame' parameter is not empty)
|
||||
// | or to main_stream otherwise
|
||||
// | |
|
||||
// |-------------------------<-----------------------
|
||||
// |
|
||||
// |
|
||||
// |
|
||||
// |
|
||||
// |
|
||||
// | answer_source: main_stream
|
||||
// |----------------------->-------------------------
|
||||
// | |
|
||||
// | depending on answer_container
|
||||
// | |
|
||||
// | --------------------------------------------------------------------
|
||||
// | | | | |
|
||||
// | text json xml csv
|
||||
// | | | | |
|
||||
// | send send send send
|
||||
// | out_main_stream out_main_stream out_main_stream out_main_stream
|
||||
// | as json text in one cell in first csv cell
|
||||
// | (without making e.g.
|
||||
// | an object) <winix>
|
||||
// | e.g. "text" text
|
||||
// | </winix>
|
||||
// |
|
||||
// |
|
||||
// |
|
||||
// | answer_source: frame_streams
|
||||
// |-------->-------
|
||||
// | |
|
||||
// | |
|
||||
// | depending on
|
||||
// | 'frame' string variable and 'allframes'
|
||||
// | |
|
||||
// | |
|
||||
// | | is 'frame' string empty or there is 'allframes' parameter
|
||||
// | |----------------------->---------------------
|
||||
// | | |
|
||||
// | | depending on answer_container
|
||||
// | | |
|
||||
// | | --------------------------------------------------------------------
|
||||
// | | | | | |
|
||||
// | | text json xml csv
|
||||
// | | | | | |
|
||||
// | | send text serialize serialize serialize
|
||||
// | | from all frames all frames all frames all frames
|
||||
// | | one by one to json to xml to csv
|
||||
// | |
|
||||
// | |
|
||||
// | |
|
||||
// | |
|
||||
// | | is 'frame' string not empty and there is no 'allframes' parameter
|
||||
// | |----------------------->---------------------
|
||||
// | |
|
||||
// | depending on answer_container
|
||||
// | |
|
||||
// | --------------------------------------------------------------------
|
||||
// | | | | |
|
||||
// | text json xml csv
|
||||
// | | | | |
|
||||
// | send text serialize serialize serialize
|
||||
// | from one frame one frame one frame one frame
|
||||
// | to json to xml to csv
|
||||
// |
|
||||
// |
|
||||
// |
|
||||
// |
|
||||
// |
|
||||
// |
|
||||
// | answer_source: models
|
||||
// |------------------------>------------------------
|
||||
// |
|
||||
// depending on answer_container
|
||||
// |
|
||||
// --------------------------------------------------------------------
|
||||
// | | | |
|
||||
// text json xml csv
|
||||
// | | | |
|
||||
// serialize serialize models serialize models serialize models
|
||||
// models to to json to xml to csv
|
||||
// csv
|
||||
// but return
|
||||
// as text/plain
|
||||
|
||||
|
||||
// change maybe answer_bin_stream -> source_bin_stream?
|
||||
enum AnswerSource
|
||||
{
|
||||
answer_bin_stream,
|
||||
answer_models,
|
||||
answer_main_stream,
|
||||
answer_frame_streams,
|
||||
};
|
||||
|
||||
|
||||
// change maybe answer_text -> container_text?
|
||||
enum AnswerContainer
|
||||
{
|
||||
answer_text,
|
||||
answer_json,
|
||||
answer_xml,
|
||||
answer_csv,
|
||||
};
|
||||
|
||||
AnswerSource answer_source;
|
||||
AnswerContainer answer_container;
|
||||
|
||||
bool use_ezc_engine;
|
||||
|
||||
std::wstring frame;
|
||||
bool send_all_frames;
|
||||
|
||||
|
||||
// request status
|
||||
// !! CHANGE ME it'll be better to use ordinary http result codes
|
||||
@@ -280,90 +455,24 @@ public:
|
||||
// a value can be either a cookie value or the whole cookie string (with domain, date etc)
|
||||
pt::Space out_cookies;
|
||||
|
||||
// winix can return either a text answer or a binary answer
|
||||
// if send_bin_stream is true then the binary answer is sent (out_bin_stream)
|
||||
// or if send_bin_stream is false then the text answer is sent
|
||||
// default: false
|
||||
//
|
||||
//
|
||||
// winix answer send to the client's browser
|
||||
// |
|
||||
// |
|
||||
// depending on send_bin_stream
|
||||
// (if false) ------------------------------------------------- (if true)
|
||||
// | |
|
||||
// text answer binary answer
|
||||
// | |
|
||||
// depending on return_json sending out_bin_stream
|
||||
// (if false) ------------------------------------ (if true)
|
||||
// | |
|
||||
// normal request ajax request
|
||||
// | |
|
||||
// sending out_main_stream |
|
||||
// |
|
||||
// |
|
||||
// depending on return_info_only
|
||||
// (if false) ------------------------------------------------------------- (if true)
|
||||
// | |
|
||||
// generating JSON object from: generating JSON object only from info
|
||||
// out_streams and info, e.g.: e.g.:
|
||||
// { { info object serialized here }
|
||||
// "out": { out_streams serialized here e.g.:
|
||||
// "stream_name_1": "some html content",
|
||||
// "stream_name_2": "some other html content"
|
||||
// },
|
||||
// "info": { info object serialized here }
|
||||
// }
|
||||
//
|
||||
//
|
||||
bool send_bin_stream;
|
||||
|
||||
// binary page sent to the client if send_bin_stream is true
|
||||
// binary page sent to the client if answer_source is answer_bin_stream
|
||||
BinaryPage out_bin_stream;
|
||||
|
||||
// when returning the text answer we can either return the whole html page (normal requests)
|
||||
// or a JSON object (for requests generated from AJAX)
|
||||
// if return_json is false then we return the whole html page (which is in out_main_stream)
|
||||
// if return_json is true we are creating an JSON object from out_streams
|
||||
// and from info space (see above picture)
|
||||
// (or just only from info if return_info_only is true)
|
||||
// default: false
|
||||
// return_json is set to true by App at the beginning of a request
|
||||
// if reqtype:json parameter is present (in the url)
|
||||
// note: return_json is only valid if send_bin_stream is false
|
||||
bool return_json;
|
||||
|
||||
// main text output stream where the html otput is generated from ezc templates
|
||||
// here the whole html page (with doctype, head, body) is generated
|
||||
HtmlTextStream out_main_stream;
|
||||
|
||||
// text output streams used in ajax requests (send in JSON format to the client)
|
||||
// text output streams used in ajax requests
|
||||
// in ezc templates you can use [ezc frame "stream_name"] or just [frame "stream_name"] keyword
|
||||
// to switch between streams
|
||||
Ezc::OutStreams<HtmlTextStream, true> out_streams;
|
||||
|
||||
// if true the JSON object is generated only from info (out_streams are not used)
|
||||
// default: false
|
||||
bool return_info_only;
|
||||
|
||||
// additional info added when sending the JSON answer
|
||||
pt::Space info;
|
||||
|
||||
// models to return or to render through ezc library
|
||||
Ezc::Models models;
|
||||
|
||||
|
||||
// if set to true then the standard template system will not be used
|
||||
// default: false
|
||||
bool page_generated;
|
||||
|
||||
// whether or not the main html stream should be filtered by our html filter
|
||||
bool out_main_stream_use_html_filter;
|
||||
|
||||
// whether or not the ajax streams should be filtered by our html filter
|
||||
// this filter is only aplied to streams in "out" space, "info" space is not touched
|
||||
bool out_streams_use_html_filter;
|
||||
|
||||
// filter html content with HTMLFilter, default the same as config.html_filter
|
||||
bool use_html_filter;
|
||||
|
||||
// if this variable is true then winix always return 200 OK header
|
||||
// when the status would be 404 (not found) or 403 (permission denied)
|
||||
@@ -375,7 +484,6 @@ public:
|
||||
bool gen_skip_new_line;
|
||||
bool gen_use_special_chars;
|
||||
|
||||
|
||||
// index template name
|
||||
std::wstring html_template;
|
||||
|
||||
@@ -384,6 +492,7 @@ public:
|
||||
additional variables used for common uses
|
||||
*/
|
||||
|
||||
// DEPRECATED will be removed
|
||||
// usually items in the current directory (depends on the function)
|
||||
std::vector<Item> item_tab;
|
||||
|
||||
@@ -407,7 +516,9 @@ public:
|
||||
void RequestEnds();
|
||||
void Clear();
|
||||
|
||||
|
||||
bool PrepareAnswerType();
|
||||
bool CheckContainerParameter();
|
||||
bool CheckAnswerParameter();
|
||||
|
||||
bool IsParam(const wchar_t * param_name);
|
||||
bool IsParam(const std::wstring & param_name);
|
||||
|
||||
Reference in New Issue
Block a user