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 : #pragma once
37 :
38 :
39 : #include <MockEvent.hpp>
40 :
41 :
42 : namespace h2agent
43 : {
44 : namespace model
45 : {
46 :
47 :
48 : class MockServerEvent : public MockEvent
49 : {
50 : nlohmann::json request_body_{};
51 : DataPart response_body_data_part_{};
52 : std::uint64_t recv_seq_{};
53 : unsigned int response_delay_ms_{};
54 : std::string virtual_origin_coming_from_method_{};
55 : std::string virtual_origin_coming_from_uri_{};
56 : std::uint64_t sending_timestamp_us_{};
57 :
58 : public:
59 :
60 278 : MockServerEvent() {;}
61 :
62 : // setters:
63 :
64 : /**
65 : * Loads request information
66 : *
67 : * @param previousState Previous request state
68 : * @param state Request state
69 : * @param receptionTimestampUs Microseconds reception timestamp
70 : * @param responseStatusCode Response status code
71 : * @param requestHeaders Request headers
72 : * @param responseHeaders Response headers
73 : *
74 : * @param requestBodyDataPart Request body
75 : * @param responseBody Response body
76 : * @param recvSeq Receive sequence (1..N)
77 : * @param responseDelayMs Response delay in milliseconds
78 : *
79 : * @param virtualOriginComingFromMethod Marks event as virtual one, adding a field with the origin method which caused it. Non-virtual by default (empty parameter).
80 : * @param virtualOriginComingFromUri Marks event as virtual one, adding a field with the origin uri which caused it. Non-virtual by default (empty parameter).
81 : */
82 : void load(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 recvSeq, unsigned int responseDelayMs, const std::string &virtualOriginComingFromMethod = "", const std::string &virtualOriginComingFromUri = "");
83 :
84 : // getters
85 :
86 : /** Receive sequence
87 : *
88 : * @return Receive sequence (1..N)
89 : */
90 0 : std::uint64_t getRecvSeq() const {
91 0 : return recv_seq_;
92 : }
93 :
94 : /** Request body
95 : *
96 : * @return Request body
97 : */
98 1 : const nlohmann::json &getRequestBody() const {
99 1 : return request_body_;
100 : }
101 :
102 : /**
103 : * Sets the sending timestamp (response out)
104 : *
105 : * @param sendingTimestampUs Microseconds sending timestamp
106 : */
107 2 : void setSendingTimestampUs(const std::chrono::microseconds &sendingTimestampUs) {
108 2 : sending_timestamp_us_ = sendingTimestampUs.count();
109 2 : json_["sendingTimestampUs"] = sending_timestamp_us_;
110 2 : }
111 :
112 : /** Sending timestamp (response out)
113 : *
114 : * @return Sending timestamp in microseconds (0 if not yet sent)
115 : */
116 8 : std::uint64_t getSendingTimestampUs() const {
117 8 : return sending_timestamp_us_;
118 : }
119 : };
120 :
121 : }
122 : }
123 :
|