2
0
mirror of https://github.com/xcat2/confluent.git synced 2025-08-29 22:38:22 +00:00

Add some beginnings of html form response for api explorer

This commit is contained in:
Jarrod Johnson
2013-11-02 18:37:26 -04:00
parent 04d2cd4ba3
commit f3fc2ace76
2 changed files with 26 additions and 13 deletions

View File

@@ -108,11 +108,11 @@ def _pick_mimetype(env):
if the '.json' scheme doesn't cut it.
"""
if env['PATH_INFO'].endswith('.json'):
return 'application/json'
return 'application/json; charset=utf-8'
elif env['PATH_INFO'].endswith('.html'):
return 'text/html'
elif 'application/json' in env['HTTP_ACCEPT']:
return 'application/json'
return 'application/json; charset=utf-8'
else:
return 'text/html'
@@ -149,7 +149,7 @@ def resourcehandler(env, start_response):
return
if authorized['code'] != 200:
raise Exception("Unrecognized code from auth engine")
headers = [('Content-Type', 'application/json; charset=utf-8')]
headers = [('Content-Type', mimetype) ]
headers.extend(("Set-Cookie", m.OutputString())
for m in authorized['cookie'].values())
cfgmgr = authorized['cfgmgr']
@@ -200,15 +200,22 @@ def resourcehandler(env, start_response):
yield "404 - Request path not recognized"
return
start_response('200 OK', headers)
yield '['
docomma = False
for rsp in hdlr:
if docomma:
yield ','
else:
docomma = True
yield rsp.json()
yield ']'
if mimetype == 'text/html':
yield '<html><body><form>'
for rsp in hdlr:
yield rsp.html()
yield '<br>'
yield '</form></body></html>'
else:
yield '['
docomma = False
for rsp in hdlr:
if docomma:
yield ','
else:
docomma = True
yield rsp.json()
yield ']'
def serve():

View File

@@ -19,7 +19,13 @@ class ConfluentMessage(object):
def html(self):
#this is used to facilitate the api explorer feature
pass
snippet = ""
for key in self.kvpairs.iterkeys():
snippet += key + ":"
snippet += '<input type="text" name="%s" value="%s">' % (
key, self.kvpairs[key])
return snippet
class PowerState(ConfluentMessage):