#!/bin/bash echo "=== Testing Rate Limiting on /api/contact ===" echo "" # Test data TEST_DATA='{"name":"Test User","email":"test@example.com","message":"This is a test message"}' # Send requests and capture responses for i in {1..7}; do echo "--- Request #$i ---" RESPONSE=$(curl -s -w "\nHTTP_STATUS:%{http_code}\n" \ -X POST \ -H "Content-Type: application/json" \ -H "X-Forwarded-For: 192.168.1.100" \ -d "$TEST_DATA" \ http://localhost:3000/api/contact) # Extract HTTP status HTTP_STATUS=$(echo "$RESPONSE" | grep "HTTP_STATUS" | cut -d: -f2) BODY=$(echo "$RESPONSE" | grep -v "HTTP_STATUS") echo "Status: $HTTP_STATUS" echo "Response: $BODY" # Extract headers with -i flag HEADERS=$(curl -s -i -X POST \ -H "Content-Type: application/json" \ -H "X-Forwarded-For: 192.168.1.100" \ -d "$TEST_DATA" \ http://localhost:3000/api/contact | grep -E "X-RateLimit-Remaining|Retry-After") echo "Headers: $HEADERS" echo "" # Small delay between requests sleep 0.5 done echo "=== Test Complete ==="