Properly set response headers and status code