Line data Source code
1 : /*
2 : ___________________________________________
3 : | _ ___ _ |
4 : | | | |__ \ | | |
5 : | | |__ ) |__ _ __ _ ___ _ __ | |_ |
6 : | | '_ \ / // _` |/ _` |/ _ \ '_ \| __| | HTTP/2 AGENT FOR MOCK TESTING
7 : | | | | |/ /| (_| | (_| | __/ | | | |_ | Version 0.0.z
8 : | |_| |_|____\__,_|\__, |\___|_| |_|\__| | https://github.com/testillano/h2agent
9 : | __/ | |
10 : | |___/ |
11 : |___________________________________________|
12 :
13 : Licensed under the MIT License <http://opensource.org/licenses/MIT>.
14 : SPDX-License-Identifier: MIT
15 : Copyright (c) 2021 Eduardo Ramos
16 :
17 : Permission is hereby granted, free of charge, to any person obtaining a copy
18 : of this software and associated documentation files (the "Software"), to deal
19 : in the Software without restriction, including without limitation the rights
20 : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
21 : copies of the Software, and to permit persons to whom the Software is
22 : furnished to do so, subject to the following conditions:
23 :
24 : The above copyright notice and this permission notice shall be included in all
25 : copies or substantial portions of the Software.
26 :
27 : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28 : IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29 : FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30 : AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31 : LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32 : OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 : SOFTWARE.
34 : */
35 :
36 : #include <string>
37 :
38 : #include <ert/tracing/Logger.hpp>
39 :
40 : #include <MockServerData.hpp>
41 :
42 :
43 : namespace h2agent
44 : {
45 : namespace model
46 : {
47 :
48 242 : void MockServerData::loadEvent(const DataKey &dataKey, const std::string &previousState, const std::string &state, const std::chrono::microseconds &receptionTimestampUs, unsigned int responseStatusCode, const nghttp2::asio_http2::header_map &requestHeaders, const nghttp2::asio_http2::header_map &responseHeaders, DataPart &requestBodyDataPart, const std::string &responseBody, std::uint64_t serverSequence, unsigned int responseDelayMs, bool historyEnabled, const std::string &virtualOriginComingFromMethod, const std::string &virtualOriginComingFromUri) {
49 :
50 242 : bool maiden{};
51 242 : auto events = std::static_pointer_cast<MockServerEventsHistory>(getEvents(dataKey, maiden));
52 :
53 242 : events->loadEvent(previousState, state, receptionTimestampUs, responseStatusCode, requestHeaders, responseHeaders, requestBodyDataPart, responseBody, serverSequence, responseDelayMs, historyEnabled, virtualOriginComingFromMethod, virtualOriginComingFromUri);
54 :
55 242 : if (maiden) add(dataKey.getKey(), events); // push the key in the map:
56 242 : }
57 :
58 0 : bool MockServerData::removeEventByRecvSeq(const DataKey &dataKey, std::uint64_t recvSeq) {
59 :
60 0 : bool exists{};
61 0 : auto events = std::static_pointer_cast<MockServerEventsHistory>(get(dataKey.getKey(), exists));
62 0 : if (!exists) return false;
63 :
64 0 : bool deleted = events->removeEventByRecvSeq(recvSeq);
65 :
66 : // Cleanup empty map entry:
67 0 : if (deleted && events->size() == 0) {
68 0 : bool aux{};
69 0 : remove(dataKey.getKey(), aux);
70 : }
71 :
72 0 : return deleted;
73 0 : }
74 :
75 0 : std::shared_ptr<MockEvent> MockServerData::getEventByRecvSeq(const DataKey &dataKey, std::uint64_t recvSeq) {
76 :
77 0 : bool exists{};
78 0 : auto events = std::static_pointer_cast<MockServerEventsHistory>(get(dataKey.getKey(), exists));
79 0 : if (!exists) return nullptr;
80 :
81 0 : return events->getEventByRecvSeq(recvSeq);
82 0 : }
83 :
84 : }
85 : }
86 :
|