change the way how winix answer is created
Now we can return ezc content and models serialized in the same json structure, Xml and Csv are not implemented yet. Ezc frames are returned in 'ezc_frames' field. Main ezc stream is returned in 'main_stream' field. Frame url parameter can take more than one frame (names separated by commas). Honor Accept http header (AcceptParser). Samples: -------- http://domain.tld/dir/controller returns html answer from the main ezc stream http://domain.tld/dir/controller/container:raw returns html answer from the main ezc stream (the same as above) http://domain.tld/dir/controller/frame:abc returns "abc" frame as html http://domain.tld/dir/controller/container:json returns all serialized models to json and no ezc streams http://domain.tld/dir/controller/container:xml returns all serialized models to xml and no ezc streams (not implemented yet) http://domain.tld/dir/controller/container:json/frame:abc,xyz returns all serialized models to json and two frames in 'ezc_frames' object http://domain.tld/dir/controller/container:json/all_frames returns all serialized models to json and all frames in 'ezc_frames' object http://domain.tld/dir/controller/container:json/main_stream returns all serialized models and the main ezc stream in 'main_stream' field http://domain.tld/dir/controller/container:json/main_stream/all_frames returns all serialized models to json, all frames and the main stream
This commit is contained in:
@@ -190,6 +190,7 @@ public:
|
||||
std::wstring env_http_host;
|
||||
std::wstring env_http_user_agent;
|
||||
std::wstring env_http_accept_encoding;
|
||||
std::wstring env_http_accept;
|
||||
std::wstring env_fcgi_role;
|
||||
std::wstring env_content_type;
|
||||
std::wstring env_https;
|
||||
@@ -249,180 +250,87 @@ 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
|
||||
// the algorithm how a request's container is selected is shown below:
|
||||
// (the whole answer's algorightm is implemented in PrepareAnswerType() method)
|
||||
// ------------------------------------------------------------------------------------------
|
||||
//
|
||||
// next answer_container and use_ezc_engine can be changed in the following way:
|
||||
// at the beginning we set container_type to "raw" meaning simple text or html, then
|
||||
// we check the "Accept" http header, if it is set then we set container_type accordingly:
|
||||
//
|
||||
// 1. winix will look for 'Accept' http header and depending on the header winix will set:
|
||||
// Accept | container_type
|
||||
// -----------------------------------------------
|
||||
// text/html | container_raw
|
||||
// application/xhtml+xml | container_raw
|
||||
// application/json | container_json
|
||||
// application/xml | container_xml
|
||||
// text/csv | container_csv
|
||||
//
|
||||
// Accept | answer_container | use_ezc_engine
|
||||
// ------------------------------------|-----------------
|
||||
// application/json | json | false
|
||||
// application/xml | xml | false
|
||||
// text/csv | csv | false
|
||||
// next we check "container" url parameter, if it is set then we set container_type accordingly
|
||||
// ("container" url parameter has higher precedence than "Accept" http header):
|
||||
//
|
||||
// container | container_type
|
||||
// -----------------------------------------------
|
||||
// raw | container_raw
|
||||
// json | container_json
|
||||
// xml | container_xml
|
||||
// csv | container_csv
|
||||
//
|
||||
//
|
||||
// Samples:
|
||||
//
|
||||
// 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
|
||||
// http://domain.tld/dir/controller
|
||||
// returns html answer from the main ezc stream
|
||||
//
|
||||
// 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
|
||||
// http://domain.tld/dir/controller/container:raw
|
||||
// returns html answer from the main ezc stream (the same as above)
|
||||
//
|
||||
// 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)
|
||||
// http://domain.tld/dir/controller/frame:abc
|
||||
// returns "abc" frame as html
|
||||
//
|
||||
// http://domain.tld/dir/controller/container:json
|
||||
// returns all serialized models to json and no ezc streams
|
||||
//
|
||||
// http://domain.tld/dir/controller/container:xml
|
||||
// returns all serialized models to xml and no ezc streams
|
||||
//
|
||||
// http://domain.tld/dir/controller/container:json/frame:abc,xyz
|
||||
// returns all serialized models to json and two frames in 'ezc_frames' object
|
||||
//
|
||||
// http://domain.tld/dir/controller/container:json/all_frames
|
||||
// returns all serialized models to json and all frames in 'ezc_frames' object
|
||||
//
|
||||
// http://domain.tld/dir/controller/container:json/main_stream
|
||||
// returns all serialized models and the main ezc stream in 'main_stream' field
|
||||
//
|
||||
// the whole algorithm how the answer is created is shown below:
|
||||
// http://domain.tld/dir/controller/container:json/main_stream/all_frames
|
||||
// returns all serialized models to json, all frames and the main stream
|
||||
//
|
||||
//
|
||||
// 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,
|
||||
};
|
||||
bool send_bin_stream;
|
||||
bool send_main_stream;
|
||||
bool send_all_frames;
|
||||
std::vector<std::wstring> send_frames;
|
||||
|
||||
bool use_ezc_engine;
|
||||
bool serialize_models;
|
||||
|
||||
|
||||
// change maybe answer_text -> container_text?
|
||||
enum AnswerContainer
|
||||
enum ContainerType
|
||||
{
|
||||
answer_text,
|
||||
answer_json,
|
||||
answer_xml,
|
||||
answer_csv,
|
||||
container_raw,
|
||||
container_json,
|
||||
container_xml,
|
||||
container_csv,
|
||||
};
|
||||
|
||||
AnswerSource answer_source;
|
||||
AnswerContainer answer_container;
|
||||
ContainerType container_type;
|
||||
|
||||
bool use_ezc_engine;
|
||||
|
||||
std::wstring frame;
|
||||
bool send_all_frames;
|
||||
// at the beginning those with higher priority
|
||||
std::vector<HeaderValue> accept_mime_types;
|
||||
|
||||
|
||||
// request status
|
||||
@@ -516,9 +424,7 @@ public:
|
||||
void RequestEnds();
|
||||
void Clear();
|
||||
|
||||
bool PrepareAnswerType();
|
||||
bool CheckContainerParameter();
|
||||
bool CheckAnswerParameter();
|
||||
void PrepareAnswerType();
|
||||
|
||||
bool IsParam(const wchar_t * param_name);
|
||||
bool IsParam(const std::wstring & param_name);
|
||||
@@ -550,7 +456,8 @@ public:
|
||||
template<typename NameType, typename ValueType>
|
||||
void AddCookie(const NameType & name, const ValueType & value, pt::Date & expires);
|
||||
|
||||
|
||||
bool has_frame(const wchar_t * frame);
|
||||
bool has_frame(const std::wstring & frame);
|
||||
|
||||
|
||||
private:
|
||||
@@ -562,6 +469,9 @@ private:
|
||||
|
||||
void ClearOutputStreams();
|
||||
|
||||
void CheckAcceptHeader();
|
||||
void CheckContainerParameter();
|
||||
void PrepareFrameNames();
|
||||
|
||||
void current_dir(morm::Wrapper & wrapper);
|
||||
void last_item_wrapper(morm::Wrapper & wrapper);
|
||||
|
||||
Reference in New Issue
Block a user