processHttpEvent method
Execute rules for HTTP events with fresh appContext
Implementation
Future<void> processHttpEvent(ObslyEventBase event) async {
if (!_isAvailable || !_isExecutionEnabled) return;
final url = 'Unknown URL';
final method = 'Unknown Method';
try {
final httpContext = _extractHttpContext(event);
if (httpContext != null) {
final contextUrl = httpContext['url'] ?? url;
final contextMethod = httpContext['method'] ?? method;
// Log HTTP rule processing
ObslyLogger.verbose('π HTTP Request: $contextMethod $contextUrl');
ObslyLogger.verbose('π― Starting HTTP rule evaluation: $contextUrl ($contextMethod)');
// Build fresh appContext for this evaluation
final currentAppContext = _buildCurrentAppContext();
// Log context access for debugging
ObslyLogger.verbose('ποΈ HTTP Rule context access: app_context');
// Merge HTTP context with app context
final fullContext = {
...currentAppContext,
'request': {
'url': contextUrl,
'verb': contextMethod,
'statusCode': httpContext['statusCode'] ?? 200,
'timeout': httpContext['timeout'] ?? false,
'duration': httpContext['duration'] ?? 0,
'requestBody': httpContext['requestBody'],
'responseBody': httpContext['responseBody'],
},
};
// Log the merged context
ObslyLogger.verbose('ποΈ HTTP Rule merged context prepared');
// Use unified execution method
final results = await RulesManager.instance.executeRulesForEvent(
eventType: 'http',
context: fullContext,
);
// Log results with new system
final allTags = results
.expand((r) => RulesResultFormatter.formatForUI(r.rawResult, includeTimestamp: false)['tags']
as List<Map<String, dynamic>>)
.toList();
final allVariables = results
.expand((r) => RulesResultFormatter.formatForUI(r.rawResult, includeTimestamp: false)['variables']
as List<Map<String, dynamic>>)
.toList();
final resultStatus = results.isNotEmpty ? 'β
SUCCESS' : 'β NO RESULTS';
ObslyLogger.verbose(
'π HTTP Rules result: $resultStatus | Rules: ${results.length} | Tags: ${allTags.length} | Variables: ${allVariables.length}');
ObslyLogger.log(
'π HTTP Rules executed for: $contextUrl ($contextMethod) - Status: ${httpContext['statusCode']}');
}
} catch (e, stackTrace) {
ObslyLogger.errorWithContext(
'RulesIntegration',
'processHttpEvent',
e.toString(),
stackTrace,
context: {'url': url, 'method': method},
);
}
}