Browse Source
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 streammaster
17 changed files with 677 additions and 377 deletions
File diff suppressed because one or more lines are too long
@ -0,0 +1,124 @@
|
||||
/*
|
||||
* This file is a part of Winix |
||||
* and is distributed under the 2-Clause BSD licence. |
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org> |
||||
*/ |
||||
|
||||
/*
|
||||
* Copyright (c) 2022, Tomasz Sowa |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are met: |
||||
* |
||||
* 1. Redistributions of source code must retain the above copyright notice, |
||||
* this list of conditions and the following disclaimer. |
||||
* |
||||
* 2. Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
||||
* POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef headerfile_winix_core_acceptparser |
||||
#define headerfile_winix_core_acceptparser |
||||
|
||||
#include "acceptbaseparser.h" |
||||
#include "log.h" |
||||
#include "header.h" |
||||
|
||||
|
||||
namespace Winix |
||||
{ |
||||
|
||||
|
||||
|
||||
class AcceptParser : public AcceptBaseParser |
||||
{ |
||||
public: |
||||
|
||||
static constexpr size_t MAX_CONTAINER_LENGTH = 16; |
||||
|
||||
/*
|
||||
* IMPROVEME add support for something like "text/html;level=1" (skip the level part) |
||||
* |
||||
* https://developer.mozilla.org/en-US/docs/Glossary/Quality_values
|
||||
* Some syntax, like the one of Accept, allow additional specifiers like text/html;level=1. |
||||
* These increase the specificity of the value. Their use is extremely rare. |
||||
* |
||||
* |
||||
*/ |
||||
|
||||
void Parse(const wchar_t * str, std::vector<HeaderValue> & header_values, bool clear_header_values = true) |
||||
{ |
||||
if( clear_header_values ) |
||||
header_values.clear(); |
||||
|
||||
this->header_values = &header_values; |
||||
AcceptBaseParser::Parse(str); |
||||
|
||||
std::sort(header_values.begin(), header_values.end(), [](HeaderValue & h1, HeaderValue & h2) -> bool { |
||||
return h1.weight > h2.weight; |
||||
}); |
||||
|
||||
PutToLog(header_values); |
||||
} |
||||
|
||||
|
||||
void Parse(const std::wstring & str, std::vector<HeaderValue> & header_values, bool clear_header_values = true) |
||||
{ |
||||
Parse(str.c_str(), header_values, clear_header_values); |
||||
} |
||||
|
||||
|
||||
private: |
||||
|
||||
std::vector<HeaderValue> * header_values; |
||||
|
||||
void Param(const std::wstring & param, double q) |
||||
{ |
||||
if( header_values->size() < MAX_CONTAINER_LENGTH && q > 0.0 ) |
||||
{ |
||||
if( q > 1.0 ) |
||||
q = 1.0; |
||||
|
||||
header_values->resize(header_values->size() + 1); |
||||
header_values->back().value = param; |
||||
header_values->back().weight = q; |
||||
} |
||||
} |
||||
|
||||
void PutToLog(std::vector<HeaderValue> & header_values) |
||||
{ |
||||
if( !header_values.empty() ) |
||||
{ |
||||
log << log3 << "AP: " << Header::accept << " header consists of: "; |
||||
HeaderValue::log_values(header_values, log); |
||||
log << logend; |
||||
} |
||||
else |
||||
{ |
||||
log << log3 << "AP: there is no " << Header::accept << " header" << logend; |
||||
} |
||||
} |
||||
|
||||
}; |
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
#endif |