Get the name's current zonefile data.
        With `raw=1` on the query string, return the raw zone file.
        Otherwise, return the (raw) zone file only if it
        is well-formed (and return it in a JSON dict).

        Reply the {'zonefile': zonefile} on success
        Reply the raw zone file as application/octet-stream of raw=1 is set
        Reply {'error': ...} and HTTP 400 on invalid name or subdomain, or invalid zone file
        Reply {'error': ...} and HTTP 404 if the name doesn't exist

        Reply 502 on failure to fetch or parse data

def GET_name_zonefile( self, path_info, name ):
        """
        Get the name's current zonefile data.
        With `raw=1` on the query string, return the raw zone file.
        Otherwise, return the (raw) zone file only if it
        is well-formed (and return it in a JSON dict).

        Reply the {'zonefile': zonefile} on success
        Reply the raw zone file as application/octet-stream of raw=1 is set
        Reply {'error': ...} and HTTP 400 on invalid name or subdomain, or invalid zone file
        Reply {'error': ...} and HTTP 404 if the name doesn't exist

        Reply 502 on failure to fetch or parse data
        """
        if not check_name(name) and not check_subdomain(name):
            return self._reply_json({'error': 'Invalid name or subdomain'}, status_code=400)

        raw = path_info['qs_values'].get('raw', '')
        raw = (raw.lower() in ['1', 'true'])
        
        if not blockstackd_scripts.is_name_valid(name) and not blockstackd_scripts.is_subdomain(name):
            return self._reply_json({'error': 'Invalid name or subdomain'}, status_code=400)

        blockstackd_url = get_blockstackd_url()
        resp = blockstackd_client.get_name_record(name, include_history=False, hostport=blockstackd_url)
        if json_is_error(resp):
            log.error("Failed to load zone file for {}: {}".format(name, resp['error']))
            return self._reply_json({"error": resp['error']}, status_code=resp.get('http_status', 502))

        if 'zonefile' not in resp or resp['zonefile'] is None:
            log.error("No zone file for {}".format(name))
            return self._reply_json({'error': 'No zone file for name'}, status_code=404)

        try:
            zonefile_txt = base64.b64decode(resp['zonefile'])
        except:
            log.error("Zone file data is not serialized properly")
            return self._reply_json({'error': 'Zone file is not serialized properly'}, status_code=400)

        if raw:
            self._send_headers(status_code=200, content_type='application/octet-stream')
            self.wfile.write(zonefile_txt)
            return

        else:
            res = decode_name_zonefile(name, zonefile_txt)
            if res is None:
                log.error("Failed to parse zone file for {}".format(name))
                return self._reply_json({'error': 'Non-standard zone file.  Try passing raw=1 to get the raw zone file.'}) 

            # successfully decodes.  Safe to return as a JSON object.
            return self._reply_json({'zonefile': zonefile_txt})