add 509 StatusCode checking and fixed the unclosed inputstream bug