Skip to content

Commit c22658e

Browse files
author
Felipe Zimmerle
committed
Adds `msc_update_status_code' method to the libmodsec api
1 parent fff5a57 commit c22658e

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

headers/modsecurity/transaction.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ class Transaction : public TransactionAnchoredVariables {
309309
int appendResponseBody(const unsigned char *body, size_t size);
310310

311311
int processLogging();
312+
int updateStatusCode(int status);
312313

313314
bool intervention(ModSecurityIntervention *it);
314315

@@ -622,6 +623,9 @@ int msc_intervention(Transaction *transaction, ModSecurityIntervention *it);
622623
/** @ingroup ModSecurity_C_API */
623624
int msc_process_logging(Transaction *transaction);
624625

626+
/** @ingroup ModSecurity_C_API */
627+
int msc_update_status_code(Transaction *transaction, int status);
628+
625629
#ifdef __cplusplus
626630
}
627631
} // namespace modsecurity

src/transaction.cc

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,6 +1694,29 @@ int Transaction::getRuleEngineState() {
16941694
}
16951695

16961696

1697+
/**
1698+
* @name updateStatusCode
1699+
* @brief Updates response status code.
1700+
*
1701+
* Called after processResponseHeaders to inform a new response code.
1702+
* Not mandatory.
1703+
*
1704+
*
1705+
* @param status The returned http code.
1706+
*
1707+
* @returns If the operation was successful or not.
1708+
* @retval true Operation was successful.
1709+
* @retval false Operation failed.
1710+
*
1711+
*/
1712+
int Transaction::updateStatusCode(int code) {
1713+
this->m_httpCodeReturned = code;
1714+
m_variableResponseStatus.set(std::to_string(code), m_variableOffset);
1715+
1716+
return true;
1717+
}
1718+
1719+
16971720
/**
16981721
* @name msc_new_transaction
16991722
* @brief Create a new transaction for a given configuration and ModSecurity core.
@@ -2126,5 +2149,25 @@ extern "C" int msc_process_logging(Transaction *transaction) {
21262149
return transaction->processLogging();
21272150
}
21282151

2152+
2153+
/**
2154+
* @name msc_update_status_code
2155+
* @brief Updates response status code.
2156+
*
2157+
* Called after msc_process_response_headers to inform a new response code.
2158+
* Not mandatory.
2159+
*
2160+
* @param transaction ModSecurity transaction.
2161+
*
2162+
* @returns If the operation was successful or not.
2163+
* @retval 1 Operation was successful.
2164+
* @retval 0 Operation failed.
2165+
*
2166+
*/
2167+
extern "C" int msc_update_status_code(Transaction *transaction, int status) {
2168+
return transaction->updateStatusCode(status);
2169+
}
2170+
2171+
21292172
} // namespace modsecurity
21302173

0 commit comments

Comments
 (0)