Edited http responses to include setting "Connection" to "close" so that connections are not kept open indefinitely
Moved filehandle closing to after error handling