Update connection.rb

refactored a bit to increase code reuse and reduce complexity,
I'd personally change the 2 liners like write_request as one lines now =)