added conditional check to send response headers