Skip to content

Commit

Permalink
Add sequence number to request data struct and update UI (#83)
Browse files Browse the repository at this point in the history
* Add sequence number to request data struct and update UI

* Update brew bundle command to prevent upgrades in check_macos script
  • Loading branch information
royshil authored Mar 14, 2024
1 parent fe6f3f4 commit bccbc36
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .github/scripts/utils.zsh/check_macos
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ if (( ! ${+commands[brew]} )) {
return 2
}

brew bundle --file ${SCRIPT_HOME}/.Brewfile
brew bundle --no-upgrade --file ${SCRIPT_HOME}/.Brewfile
rehash
log_group
10 changes: 9 additions & 1 deletion src/request-data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ struct request_data_handler_response request_data_handler(url_source_request_dat
{
struct request_data_handler_response response;

request_data->sequence_number++;

if (request_data->url_or_file == "file") {
// This is a file request
// Read the file
Expand Down Expand Up @@ -334,10 +336,14 @@ struct request_data_handler_response request_data_handler(url_source_request_dat
// Replace the {input} placeholder with the source text
inja::Environment env;
// Add an inja callback for time formatting
env.add_callback("strftime", 1, [](inja::Arguments &args) {
env.add_callback("strftime", 2, [](inja::Arguments &args) {
std::string format = args.at(0)->get<std::string>();
std::time_t t = std::time(nullptr);
std::tm *tm = std::localtime(&t);
if (args.at(1)->get<bool>()) {
// if the second argument is true, use UTC time
tm = std::gmtime(&t);
}
char buffer[256];
std::strftime(buffer, sizeof(buffer), format.c_str(), tm);
return std::string(buffer);
Expand All @@ -351,6 +357,8 @@ struct request_data_handler_response request_data_handler(url_source_request_dat
return input;
});

json["seq"] = request_data->sequence_number;

// Replace the {input} placeholder in the querystring as well
std::string url = request_data->url;
try {
Expand Down
2 changes: 2 additions & 0 deletions src/request-data.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ struct url_source_request_data {
std::string aggregate_to_empty_buffer;
// agg buffer begin timestamp
uint64_t agg_buffer_begin_ts;
uint64_t sequence_number;
std::string last_obs_text_source_value;
std::string obs_input_source_resize_option;
// SSL options
Expand Down Expand Up @@ -134,6 +135,7 @@ struct url_source_request_data {
aggregate_to_target = URL_SOURCE_AGG_TARGET_NONE;
aggregate_to_empty_buffer = std::string("");
agg_buffer_begin_ts = 0;
sequence_number = 0;
last_obs_text_source_value = std::string("");
obs_input_source_resize_option = std::string("100%");
ssl_verify_peer = false;
Expand Down
101 changes: 52 additions & 49 deletions src/ui/requestbuilder.ui
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,51 @@
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QWidget" name="widget_10" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_9">
<property name="spacing">
<number>6</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QComboBox" name="methodComboBox">
<item>
<property name="text">
<string>GET</string>
</property>
</item>
<item>
<property name="text">
<string>POST</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_failonhttperrorcodes">
<property name="toolTip">
<string>Fail on e.g. 400 HTTP codes or continue and get the response body?</string>
</property>
<property name="text">
<string>Fail on HTTP error code?</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
Expand Down Expand Up @@ -442,8 +487,11 @@
</item>
<item row="9" column="0">
<widget class="QLabel" name="label_16">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Available functions: (for URL field above as well)&lt;/p&gt;&lt;p&gt;- {{input}} : The dynamic input&lt;/p&gt;&lt;p&gt;- {{strftime(&amp;lt;format&amp;gt;, &amp;lt;utc? true/false&amp;gt;)}} : Add a formatted time&lt;/p&gt;&lt;p&gt;- {{urlencode(var)}} : URL Encoded input&lt;/p&gt;&lt;p&gt;- {{imageb64}} : Base64 encoded image input&lt;/p&gt;&lt;p&gt;- {{seq}} : Sequential counter for requests&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Body</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Body&lt;/p&gt;&lt;p&gt;ℹ️&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
Expand All @@ -463,21 +511,21 @@
</property>
</widget>
</item>
<item row="11" column="0">
<item row="10" column="0">
<widget class="QCheckBox" name="sslOptionsCheckbox">
<property name="text">
<string>SSL Options</string>
</property>
</widget>
</item>
<item row="12" column="0">
<item row="11" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="12" column="1">
<item row="11" column="1">
<widget class="QGroupBox" name="sslOptionsGroup">
<property name="title">
<string/>
Expand Down Expand Up @@ -603,51 +651,6 @@
</layout>
</widget>
</item>
<item row="4" column="1">
<widget class="QWidget" name="widget_10" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_9">
<property name="spacing">
<number>6</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QComboBox" name="methodComboBox">
<item>
<property name="text">
<string>GET</string>
</property>
</item>
<item>
<property name="text">
<string>POST</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_failonhttperrorcodes">
<property name="toolTip">
<string>Fail on e.g. 400 HTTP codes or continue and get the response body?</string>
</property>
<property name="text">
<string>Fail on HTTP error code?</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down

0 comments on commit bccbc36

Please sign in to comment.