add some codes from lib:requests