US gas prices near $4 a gallon, testing consumer resilience