Created
December 6, 2022 19:35
-
-
Save ywkaras/1813bf47779e018515df31bea6523510 to your computer and use it in GitHub Desktop.
Example of input to global plugin generation tool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[settings] | |
plugin_name = my_plugin | |
[global] | |
#include <string> | |
using std::string; | |
string fixed_value; | |
+http_read_request_hdr_hook | |
[init] | |
// Value for X-Fixed header should be first and only parameter. | |
if (n_arg > 2) | |
Emergency("X-Fixed value should be only parameter"); | |
else if (n_arg != 1) | |
Emergency(" X-Fixed value parameter missing"); | |
fixed = arg[1]; | |
Dbg("X-Fixed headder value is %s", fixed); | |
[per_txn] | |
// Value of X-RPS-In header field in request. | |
string rps_in; | |
[http_read_request_hdr_hook] | |
TxnClientReq req(txn); | |
MimeField rps_in_mf(req, "X-RPS-In"); | |
if (rps_in_mf.valid()) { | |
rps_in = rps_in_mf.valuesGet(); | |
+ http_send_response_hdr_hook | |
} | |
[http_send_response_hdr_hook] | |
TxnClientResp resp(txn); | |
MimeField rps_out_mf = MimeField::create(resp, "X-RPS-Out); | |
if (!rps_out_mf.valid()) { | |
Warning("Unexecped X-RPS-Out header field in response from server"); | |
// Overwrite the header field value set by the server. | |
rps_out_mf = MimeField(resp, "X-RPS-Out"); | |
} | |
if (rsp_in == "rock") | |
rsp_out_mf.setValues("paper"); | |
else if (rsp_in == "paper") | |
rsp_out_mf.setValues("scissors"); | |
else if (rsp_in == "scissors") | |
rsp_out_mf.setValues("rock"); | |
else | |
rsp_out_mf.setValues("error"); | |
MimeField fixed_mf = MimeField::create(resp, "X-Fixed); | |
if (!fixed_mf.valid()) { | |
Warning("Unexecped X-Fixed header field in response from server"); | |
// Overwrite the header field value set by the server. | |
fixed_mf = MimeField(resp, "X-Fixed"); | |
} | |
fixed_mf.setValues(fixed_value); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment