http: do not use a loop to find the tx count

As we want the last tx

Ticket: 8156

The generic function AppLayerParserGetTxCnt calls for HTTP1
Transactions.size()

This function has some specific code, as we may have pre-created
a tx that we do not want to count.
This used to get the last tx by iterating over all the transactions
waiting to find the one with max index.
So, instead of using the Transactions.get function, we get the last
tx out of the VecDeque and check its index.
pull/14497/head
Philippe Antoine 7 months ago committed by Victor Julien
parent 5c0f95faec
commit af246ae7ab

@ -33,9 +33,15 @@ impl Transactions {
// that transaction is started), or zero if neither
// request or response transaction exist yet
let tx_to_check = std::cmp::max(self.request, self.response);
match self.get(tx_to_check) {
match self.transactions.back() {
// Transaction is created, check if it is started
Some(tx) => tx.index.wrapping_add(tx.is_started() as usize),
Some(tx) => {
if tx.index == tx_to_check {
tx.index.wrapping_add(tx.is_started() as usize)
} else {
tx_to_check
}
}
// Transaction doesn't exist yet, so the index is the size
None => tx_to_check,
}

Loading…
Cancel
Save