def adc_response(msg, isjson, code=200, json_encoded=False):
    if json_encoded:
        body = msg
    else:
        template = 'response.json' if isjson else 'response.html'
        body = render_template(template, msg=msg)
    resp = make_response(body)
    if code == 200:
        resp.status = 'OK'
    elif code == 400:
        resp.status = 'Bad Request'
    elif code == 401:
        resp.status = 'Unauthorized'
    resp.status_code = code
    resp.headers['Content-Type'] = 'application/json' if isjson else 'text/html; charset=utf-8'
    return resp