def get(self): item = self.get_argument('item', None) ruleid = self.get_argument('ruleid', None) origin = self.get_argument('origin', None) host = self.get_argument('host', None) doc = True if self.get_argument('doc', False) else False coll = 'documentation' if doc else 'log_logentry' body = None fmt = None reqheaders = {} respheaders = {} entry = None if item: collection = self.settings['db'].proxyservice[coll] entry = yield motor.Op(collection.find_one, {'_id': self.get_id(item)}) if entry: reqheaders = entry['request'][ 'headers'] if 'request' in entry and 'headers' in entry[ 'request'] and entry['request'][ 'headers'] else reqheaders respheaders = entry['response'][ 'headers'] if 'response' in entry and 'headers' in entry[ 'response'] else respheaders status = entry['response']['status'] if 'fileid' in entry['response']: body, ctype = yield self.get_gridfs_body( entry['response']['fileid'], respheaders) fmt = util.get_format(ctype) elif 'body' in entry['response']: body = entry['response']['body'] entry = entry['request'] entry['status'] = status elif ruleid: collection = self.settings['db'].proxyservice['log_rules'] entry = yield motor.Op(collection.find_one, {'_id': self.get_id(ruleid)}) body = entry['body'] reqheaders = entry['reqheaders'] if 'reqheaders' in entry and entry[ 'reqheaders'] else reqheaders respheaders = entry[ 'respheaders'] if 'respheaders' in entry else respheaders fmt = util.get_format( util.get_content_type( self.nice_headers(respheaders))) if respheaders else None self.render("ruleadd.html", tryagain=False, item=item, origin=origin, host=host, entry=entry, body=body, fmt=fmt, reqheaders=reqheaders, respheaders=respheaders)
def post(self): host = util.cleanarg(self.get_argument('host'), False) scheme = util.cleanarg(self.get_argument('scheme'), False) path = util.cleanarg(self.get_argument('path'), False) query = util.cleanarg(self.get_argument('query'), False) status = util.cleanarg(self.get_argument('status'), False) method = util.cleanarg(self.get_argument('method'), False) respbody = util.cleanarg(self.get_argument('respbody'), False) reqbody = util.cleanarg(self.get_argument('reqbody'), False) reqheaders = self.get_submitted_headers('reqheader') respheaders = self.get_submitted_headers('respheader') collection = self.settings['db'].proxyservice['documentation'] reqfmt = util.get_format(util.get_content_type(self.nice_headers(reqheaders))) if reqheaders else None respfmt = util.get_format(util.get_content_type(self.nice_headers(respheaders))) if respheaders else None if not host and not path and not query and not status: self.render("documentationadd.html", tryagain=True, host=host, path=path, query=query, status=status, method=method, respbody=respbody, reqbody=reqbody, reqheaders=reqheaders, respheaders=respheaders, reqfmt=reqfmt, respfmt=respfmt, scheme=scheme) return # default stuff if not scheme: scheme = 'http' if not status: status = 200 if not method: method = 'GET' item = { 'request': { 'scheme': scheme, 'host': host, 'path': path, 'query': query, 'method': method, 'body': reqbody, 'headers': reqheaders, }, 'response': { 'body': respbody, 'headers': respheaders, 'status': int(status), } } yield collection.insert(item) self.redirect('/documentation/host/' + host)
def get(self, ident): collection = self.settings['db'].proxyservice['log_rules'] entry = yield motor.Op(collection.find_one, {'_id': self.get_id(ident)}) if not entry: raise tornado.web.HTTPError(404) item = self.get_argument('item', None) origin = entry[ 'origin'] or None if 'origin' in entry else self.get_argument( 'origin', None) host = self.get_argument('host', None) reqheaders = entry[ 'reqheaders'] if entry and 'reqheaders' in entry else {} respheaders = entry[ 'respheaders'] if entry and 'respheaders' in entry else {} fmt = util.get_format( util.get_content_type( self.nice_headers(respheaders))) if respheaders else None self.render("ruleedit.html", entry=entry, item=item, origin=origin, host=host, tryagain=False, body=None, fmt=fmt, reqheaders=reqheaders, respheaders=respheaders)
def post(self): item = self.get_argument('item', None) origin = util.cleanarg(self.get_argument('origin', False), False) host = self.get_argument('host', None) rhost = util.cleanarg(self.get_argument('rhost'), False) path = util.cleanarg(self.get_argument('path'), False) query = util.cleanarg(self.get_argument('query'), False) status = util.cleanarg(self.get_argument('status'), False) method = util.cleanarg(self.get_argument('method'), False) response = util.cleanarg(self.get_argument('response'), False) delay = int(util.cleanarg(self.get_argument('delay', 0), 0)) body = util.cleanarg(self.get_argument('body'), False) reqheaders = self.get_submitted_headers('reqheader') respheaders = self.get_submitted_headers('respheader') dynamic = True if response is False and body is False and not respheaders else False fmt = util.get_format(util.get_content_type(self.nice_headers(respheaders))) if respheaders else None if not rhost and not path and not query and not status: response = False self.render("ruleadd.html", tryagain=True, item=item, origin=origin, host=host, entry=None, body=body, fmt=fmt, reqheaders=reqheaders, respheaders=respheaders) return # filter headers, set field to false if nothing has been added reqheaders = reqheaders if reqheaders else False collection = self.settings['db'].proxyservice['log_rules'] yield motor.Op(collection.insert, { 'active': True, 'dynamic': dynamic, 'host': rhost, 'path': path, 'query': query, 'method': method, 'status': status, 'origin': origin, 'delay': delay, 'response': response, 'reqheaders': reqheaders, 'respheaders': respheaders, 'body': body }) params = {} if origin: params['origin'] = origin # this is required otherwise we will filter out this rule after the redirect if host and host == rhost: params['host'] = host if item: params['item'] = item self.redirect('/rules?' + urllib.urlencode(params))
def get(self, ident): collection = self.settings['db'].proxyservice['documentation'] entry = yield motor.Op(collection.find_one, {'_id': self.get_id(ident)}) if not entry: raise tornado.web.HTTPError(404) reqheaders = entry['request'][ 'headers'] if 'request' in entry and 'headers' in entry[ 'request'] else {} respheaders = entry['response'][ 'headers'] if 'response' in entry and 'headers' in entry[ 'response'] else {} if 'fileid' in entry['response']: resbody, ctype = yield self.get_gridfs_body( entry['response']['fileid'], respheaders) entry['response']['body'] = resbody if 'fileid' in entry['request']: reqbody, ctype = yield self.get_gridfs_body( entry['request']['fileid'], reqheaders) entry['request']['body'] = reqbody reqfmt = util.get_format( util.get_content_type( self.nice_headers(reqheaders))) if reqheaders else None respfmt = util.get_format( util.get_content_type( self.nice_headers(respheaders))) if respheaders else None scheme = entry['request']['scheme'] if 'scheme' in entry[ 'request'] else 'http' self.render("documentationedit.html", entry=entry, tryagain=False, reqheaders=reqheaders, respheaders=respheaders, respfmt=respfmt, reqfmt=reqfmt, scheme=scheme)
def get(self, ident): collection = self.settings['db'].proxyservice['log_rules'] entry = yield motor.Op(collection.find_one, {'_id': self.get_id(ident)}) if not entry: raise tornado.web.HTTPError(404) item = self.get_argument('item', None) origin = entry['origin'] or None if 'origin' in entry else self.get_argument('origin', None) host = self.get_argument('host', None) reqheaders = entry['reqheaders'] if entry and 'reqheaders' in entry else {} respheaders = entry['respheaders'] if entry and 'respheaders' in entry else {} fmt = util.get_format(util.get_content_type(self.nice_headers(respheaders))) if respheaders else None self.render("ruleedit.html", entry=entry, item=item, origin=origin, host=host, tryagain=False, body=None, fmt=fmt, reqheaders=reqheaders, respheaders=respheaders)
def get(self, ident): collection = self.settings['db'].proxyservice['documentation'] entry = yield motor.Op(collection.find_one, {'_id': self.get_id(ident)}) if not entry: raise tornado.web.HTTPError(404) reqheaders = entry['request']['headers'] if 'request' in entry and 'headers' in entry['request'] else {} respheaders = entry['response']['headers'] if 'response' in entry and 'headers' in entry['response'] else {} if 'fileid' in entry['response']: resbody, ctype = yield self.get_gridfs_body(entry['response']['fileid'], respheaders) entry['response']['body'] = resbody if 'fileid' in entry['request']: reqbody, ctype = yield self.get_gridfs_body(entry['request']['fileid'], reqheaders) entry['request']['body'] = reqbody reqfmt = util.get_format(util.get_content_type(self.nice_headers(reqheaders))) if reqheaders else None respfmt = util.get_format(util.get_content_type(self.nice_headers(respheaders))) if respheaders else None scheme = entry['request']['scheme'] if 'scheme' in entry['request'] else 'http' self.render("documentationedit.html", entry=entry, tryagain=False, reqheaders=reqheaders, respheaders=respheaders, respfmt=respfmt, reqfmt=reqfmt, scheme=scheme)
def get(self): item = self.get_argument('item', None) ruleid = self.get_argument('ruleid', None) origin = self.get_argument('origin', None) host = self.get_argument('host', None) doc = True if self.get_argument('doc', False) else False coll = 'documentation' if doc else 'log_logentry' body = None fmt = None reqheaders = {} respheaders = {} entry = None if item: collection = self.settings['db'].proxyservice[coll] entry = yield motor.Op(collection.find_one, {'_id': self.get_id(item)}) if entry: reqheaders = entry['request']['headers'] if 'request' in entry and 'headers' in entry['request'] and entry['request']['headers'] else reqheaders respheaders = entry['response']['headers'] if 'response' in entry and 'headers' in entry['response'] else respheaders status = entry['response']['status'] if 'fileid' in entry['response']: body, ctype = yield self.get_gridfs_body(entry['response']['fileid'], respheaders) fmt = util.get_format(ctype) elif 'body' in entry['response']: body = entry['response']['body'] entry = entry['request'] entry['status'] = status elif ruleid: collection = self.settings['db'].proxyservice['log_rules'] entry = yield motor.Op(collection.find_one, {'_id': self.get_id(ruleid)}) body = entry['body'] reqheaders = entry['reqheaders'] if 'reqheaders' in entry and entry['reqheaders'] else reqheaders respheaders = entry['respheaders'] if 'respheaders' in entry else respheaders fmt = util.get_format(util.get_content_type(self.nice_headers(respheaders))) if respheaders else None self.render("ruleadd.html", tryagain=False, item=item, origin=origin, host=host, entry=entry, body=body, fmt=fmt, reqheaders=reqheaders, respheaders=respheaders)
def get(self, ident): origin = self.get_argument('origin', None) host = self.get_argument('host', None) collection = self.settings['db'].proxyservice['documentation'] try: oid = objectid.ObjectId(ident) except objectid.InvalidId as e: print e self.send_error(500) return #raise tornado.web.HTTPError(400) entry = yield motor.Op(collection.find_one, {'_id': oid}) if not entry: raise tornado.web.HTTPError(404) requestquery = util.nice_body(entry['request']['query'], 'application/x-www-form-urlencoded') requestheaders = self.nice_headers(entry['request']['headers']) responseheaders = self.nice_headers(entry['response']['headers']) respctype = util.get_content_type(self.nice_headers(responseheaders)) reqctype = util.get_content_type(self.nice_headers(requestheaders)) requestbody = None responsebody = None reqbody = None resbody = None if 'fileid' in entry['response']: resbody, ctype = yield self.get_gridfs_body( entry['response']['fileid'], responseheaders) responsebody = self.get_formatted_body(resbody, ctype) elif 'body' in entry['response']: if not respctype: respctype = util.get_body_content_type( entry['response']['body']) resbody = entry['response']['body'] responsebody = self.get_formatted_body(resbody, respctype) if 'fileid' in entry['request']: reqbody, ctype = yield self.get_gridfs_body( entry['request']['fileid'], requestheaders) requestbody = self.get_formatted_body(reqbody, ctype) elif 'body' in entry['request']: reqbody = entry['request']['body'] if not reqctype: reqctype = util.get_body_content_type(reqbody) requestbody = self.get_formatted_body(reqbody, reqctype) for key, value in requestheaders.iteritems(): if key == 'Cookie': requestheaders[key] = util.nice_body( value, 'application/x-www-form-urlencoded') cmd = yield self.get_curl_cmd(entry, reqbody) cmd = highlight(cmd, BashLexer(), HtmlFormatter(cssclass='codehilite curl')) fmt = util.get_format(respctype) if respctype else None self.render("one.html", item=entry, body=resbody, fmt=fmt, cmd=cmd, requestheaders=requestheaders, responseheaders=responseheaders, requestbody=requestbody, responsebody=responsebody, requestquery=requestquery, finished=True, socketuuid=None, origin=origin, host=host, relativedelta=relativedelta, from_doc=True)
def get(self, ident): origin = self.get_argument('origin', None) host = self.get_argument('host', None) collection = self.settings['db'].proxyservice['documentation'] try: oid = objectid.ObjectId(ident) except objectid.InvalidId as e: print e self.send_error(500) return #raise tornado.web.HTTPError(400) entry = yield motor.Op(collection.find_one, {'_id': oid}) if not entry: raise tornado.web.HTTPError(404) requestquery = util.nice_body(entry['request']['query'], 'application/x-www-form-urlencoded') requestheaders = self.nice_headers(entry['request']['headers']) responseheaders = self.nice_headers(entry['response']['headers']) respctype = util.get_content_type(self.nice_headers(responseheaders)) reqctype = util.get_content_type(self.nice_headers(requestheaders)) requestbody = None responsebody = None reqbody = None resbody = None if 'fileid' in entry['response']: resbody, ctype = yield self.get_gridfs_body(entry['response']['fileid'], responseheaders) responsebody = self.get_formatted_body(resbody, ctype) elif 'body' in entry['response']: if not respctype: respctype = util.get_body_content_type(entry['response']['body']) resbody = entry['response']['body'] responsebody = self.get_formatted_body(resbody, respctype) if 'fileid' in entry['request']: reqbody, ctype = yield self.get_gridfs_body(entry['request']['fileid'], requestheaders) requestbody = self.get_formatted_body(reqbody, ctype) elif 'body' in entry['request']: reqbody = entry['request']['body'] if not reqctype: reqctype = util.get_body_content_type(reqbody) requestbody = self.get_formatted_body(reqbody, reqctype) for key, value in requestheaders.iteritems(): if key == 'Cookie': requestheaders[key] = util.nice_body(value, 'application/x-www-form-urlencoded') cmd = yield self.get_curl_cmd(entry, reqbody) cmd = highlight(cmd, BashLexer(), HtmlFormatter(cssclass='codehilite curl')) fmt = util.get_format(respctype) if respctype else None self.render("one.html", item=entry, body=resbody, fmt=fmt, cmd=cmd, requestheaders=requestheaders, responseheaders=responseheaders, requestbody=requestbody, responsebody=responsebody, requestquery=requestquery, finished=True, socketuuid=None, origin=origin, host=host, relativedelta=relativedelta, from_doc=True)
def post(self): host = util.cleanarg(self.get_argument('host'), False) scheme = util.cleanarg(self.get_argument('scheme'), False) path = util.cleanarg(self.get_argument('path'), False) query = util.cleanarg(self.get_argument('query'), False) status = util.cleanarg(self.get_argument('status'), False) method = util.cleanarg(self.get_argument('method'), False) respbody = util.cleanarg(self.get_argument('respbody'), False) reqbody = util.cleanarg(self.get_argument('reqbody'), False) reqheaders = self.get_submitted_headers('reqheader') respheaders = self.get_submitted_headers('respheader') collection = self.settings['db'].proxyservice['documentation'] reqfmt = util.get_format( util.get_content_type( self.nice_headers(reqheaders))) if reqheaders else None respfmt = util.get_format( util.get_content_type( self.nice_headers(respheaders))) if respheaders else None if not host and not path and not query and not status: self.render("documentationadd.html", tryagain=True, host=host, path=path, query=query, status=status, method=method, respbody=respbody, reqbody=reqbody, reqheaders=reqheaders, respheaders=respheaders, reqfmt=reqfmt, respfmt=respfmt, scheme=scheme) return # default stuff if not scheme: scheme = 'http' if not status: status = 200 if not method: method = 'GET' item = { 'request': { 'scheme': scheme, 'host': host, 'path': path, 'query': query, 'method': method, 'body': reqbody, 'headers': reqheaders, }, 'response': { 'body': respbody, 'headers': respheaders, 'status': int(status), } } yield collection.insert(item) self.redirect('/documentation/host/' + host)
def post(self): item = self.get_argument('item', None) origin = util.cleanarg(self.get_argument('origin', False), False) host = self.get_argument('host', None) rhost = util.cleanarg(self.get_argument('rhost'), False) path = util.cleanarg(self.get_argument('path'), False) query = util.cleanarg(self.get_argument('query'), False) status = util.cleanarg(self.get_argument('status'), False) method = util.cleanarg(self.get_argument('method'), False) response = util.cleanarg(self.get_argument('response'), False) delay = int(util.cleanarg(self.get_argument('delay', 0), 0)) body = util.cleanarg(self.get_argument('body'), False) reqheaders = self.get_submitted_headers('reqheader') respheaders = self.get_submitted_headers('respheader') dynamic = True if response is False and body is False and not respheaders else False fmt = util.get_format( util.get_content_type( self.nice_headers(respheaders))) if respheaders else None if not rhost and not path and not query and not status: response = False self.render("ruleadd.html", tryagain=True, item=item, origin=origin, host=host, entry=None, body=body, fmt=fmt, reqheaders=reqheaders, respheaders=respheaders) return # filter headers, set field to false if nothing has been added reqheaders = reqheaders if reqheaders else False collection = self.settings['db'].proxyservice['log_rules'] yield motor.Op( collection.insert, { 'active': True, 'dynamic': dynamic, 'host': rhost, 'path': path, 'query': query, 'method': method, 'status': status, 'origin': origin, 'delay': delay, 'response': response, 'reqheaders': reqheaders, 'respheaders': respheaders, 'body': body }) params = {} if origin: params['origin'] = origin # this is required otherwise we will filter out this rule after the redirect if host and host == rhost: params['host'] = host if item: params['item'] = item self.redirect('/rules?' + urllib.urlencode(params))
def get(self, ident): origin = self.get_argument('origin', None) host = self.get_argument('host', None) collection = self.settings['db'].proxyservice['log_logentry'] reqbody = None try: oid = objectid.ObjectId(ident) except objectid.InvalidId as e: print e self.send_error(500) return entry = yield motor.Op(collection.find_one, {'_id': oid}) if not entry: raise tornado.web.HTTPError(404) requestquery = util.nice_body(entry['request']['query'], 'application/x-www-form-urlencoded') requestheaders = self.nice_headers(entry['request']['headers']) responseheaders = self.nice_headers(entry['response']['headers']) requestbody = None responsebody = None resbody = None socketuuid = util.get_uuid(entry) # consider the response finished finished = True if 'fileid' in entry['response']: respfileid = entry['response']['fileid'] filepath = util.getfilepath(respfileid) finished = util.is_finished(filepath) if finished: resbody, ctype = yield self.get_gridfs_body( respfileid, responseheaders) responsebody = self.get_formatted_body(resbody, ctype) else: response_mime_type = util.get_content_type( requests.structures.CaseInsensitiveDict(responseheaders)) responsebody = self.get_partial_content_body( filepath, response_mime_type) if 'fileid' in entry['request']: reqbody, ctype = yield self.get_gridfs_body( entry['request']['fileid'], requestheaders) requestbody = self.get_formatted_body(reqbody, ctype) # format the cookie header for key, value in requestheaders.iteritems(): if key == 'Cookie': requestheaders[key] = util.nice_body( value, 'application/x-www-form-urlencoded', 'nopadding break-all nobg') pass # get pre-formatted messages for this host if needed messages = [] if not finished: messages = yield self.get_messages(entry) cmd = yield self.get_curl_cmd(entry, reqbody) cmd = highlight(cmd, BashLexer(), HtmlFormatter(cssclass='codehilite curl')) fmt = util.get_format( util.get_content_type(self.nice_headers( responseheaders))) if responseheaders else None self.render("one.html", item=entry, cmd=cmd, body=resbody, fmt=fmt, messages=messages, requestheaders=requestheaders, responseheaders=responseheaders, requestbody=requestbody, responsebody=responsebody, requestquery=requestquery, finished=finished, socketuuid=socketuuid, origin=origin, host=host, relativedelta=relativedelta, from_doc=False)
def get(self, host): path = self.get_argument('path', None) method = self.get_argument('method', None) collection = self.settings['db'].proxyservice['documentation'] cursor = collection.find({'request.host': host}).sort([('request.path', 1), ('response.status', 1)]) res = cursor.to_list(100) endpoints = yield res # Get a list of requests per endpoints tree = util.tree() for item in endpoints: if item['request']['path']: parts = filter(None, item['request']['path'].split('/')) else: parts = [''] o = tree for part in parts: o = o['children'][part] o['methods'][item['request']['method']][item['response']['status']] = item['_id'] req = {'request.host': host, 'request.method': method} if path and path != '/': req['request.path'] = path else: req['request.path'] = {'$in': [False, '/']} entries = yield collection.find(req).sort([('response.status', 1)]).to_list(100) for k, entry in enumerate(entries): entries[k]['request']['headers'] = self.nice_headers(entry['request']['headers']) entries[k]['response']['headers'] = self.nice_headers(entry['response']['headers']) if entry['request']['query']: entries[k]['request']['query'] = urlparse.parse_qsl(entry['request']['query'], keep_blank_values=True) reqbody = None if 'body' in entries[k]['request'] and entries[k]['request']['body']: reqbody = entries[k]['request']['body'] entries[k]['request']['content-type'] = util.get_content_type(entry['request']['headers']) elif 'request' in entry and 'fileid' in entry['request']: reqbody, entries[k]['request']['content-type'] = yield self.get_gridfs_body(entry['request']['fileid'], entry['request']['headers']) if 'content-type' in entries[k]['request'] and reqbody: if entries[k]['request']['content-type'] == 'application/x-www-form-urlencoded': entries[k]['request']['body'] = urlparse.parse_qsl(reqbody, keep_blank_values=True) else: entries[k]['request']['body'] = self.get_formatted_body(reqbody, entries[k]['request']['content-type'], 'break-all') if 'response' in entry: if 'fileid' in entry['response']: entries[k]['response']['body'], entries[k]['response']['content-type'] = yield self.get_gridfs_body(entry['response']['fileid'], entry['response']['headers']) elif 'body' in entry['response']: entry['response']['content-type'] = util.get_content_type(entry['response']['headers']) if util.get_format(entry['response']['content-type']) == 'json': entries[k]['response']['schema'] = skinfer.generate_schema(json.loads(entry['response']['body'])) #genson.Schema().add_object(json.loads(resbody)).to_dict() print entries[k]['response']['content-type'] entries[k]['response']['body'] = self.get_formatted_body(entries[k]['response']['body'], entries[k]['response']['content-type'], 'break-all') collection = self.settings['db'].proxyservice['docsettings'] row = yield collection.find_one({'host': host}) self.render("documentationhost.html", host=host, entries=entries, tree=tree, render_tree=self.render_tree, render_document=self.render_document, currentpath=path, method=method, row=row, ObjectId=ObjectId)
def post(self, ident): host = util.cleanarg(self.get_argument('host'), False) scheme = util.cleanarg(self.get_argument('scheme'), False) path = util.cleanarg(self.get_argument('path'), False) query = util.cleanarg(self.get_argument('query'), False) status = util.cleanarg(self.get_argument('status'), False) method = util.cleanarg(self.get_argument('method'), False) respbody = util.cleanarg(self.get_argument('respbody'), False) reqbody = util.cleanarg(self.get_argument('reqbody'), False) reqheaders = self.get_submitted_headers('reqheader') respheaders = self.get_submitted_headers('respheader') collection = self.settings['db'].proxyservice['documentation'] entry = yield motor.Op(collection.find_one, {'_id': self.get_id(ident)}) reqfmt = util.get_format(util.get_content_type(self.nice_headers(reqheaders))) if reqheaders else None respfmt = util.get_format(util.get_content_type(self.nice_headers(respheaders))) if respheaders else None if not host and not path and not query and not status: self.render("documentationedit.html", entry=entry, tryagain=True, reqheaders=reqheaders, respheaders=respheaders, respfmt=respfmt, reqfmt=reqfmt, scheme=scheme) return # default stuff if not scheme: scheme = 'http' if not status: status = 200 if not method: method = 'GET' item = { 'request': { 'scheme': scheme, 'host': host, 'path': path, 'query': query, 'method': method, 'body': reqbody, 'headers': reqheaders, }, 'response': { 'body': respbody, 'headers': respheaders, 'status': int(status), } } up = { 'request.host': host, 'request.scheme': scheme, 'request.path': path, 'request.query': query, 'request.method': method, 'request.body': reqbody, 'request.headers': reqheaders, 'response.body': respbody, 'response.headers': respheaders, 'response.status': int(status), } yield collection.update({'_id': self.get_id(ident)}, {'$set': up}) item['_id'] = ident self.render("documentationedit.html", entry=item, tryagain=False, reqheaders=reqheaders, respheaders=respheaders, respfmt=respfmt, reqfmt=reqfmt, scheme=scheme)
def post(self, ident): host = util.cleanarg(self.get_argument('host'), False) scheme = util.cleanarg(self.get_argument('scheme'), False) path = util.cleanarg(self.get_argument('path'), False) query = util.cleanarg(self.get_argument('query'), False) status = util.cleanarg(self.get_argument('status'), False) method = util.cleanarg(self.get_argument('method'), False) respbody = util.cleanarg(self.get_argument('respbody'), False) reqbody = util.cleanarg(self.get_argument('reqbody'), False) reqheaders = self.get_submitted_headers('reqheader') respheaders = self.get_submitted_headers('respheader') collection = self.settings['db'].proxyservice['documentation'] entry = yield motor.Op(collection.find_one, {'_id': self.get_id(ident)}) reqfmt = util.get_format( util.get_content_type( self.nice_headers(reqheaders))) if reqheaders else None respfmt = util.get_format( util.get_content_type( self.nice_headers(respheaders))) if respheaders else None if not host and not path and not query and not status: self.render("documentationedit.html", entry=entry, tryagain=True, reqheaders=reqheaders, respheaders=respheaders, respfmt=respfmt, reqfmt=reqfmt, scheme=scheme) return # default stuff if not scheme: scheme = 'http' if not status: status = 200 if not method: method = 'GET' item = { 'request': { 'scheme': scheme, 'host': host, 'path': path, 'query': query, 'method': method, 'body': reqbody, 'headers': reqheaders, }, 'response': { 'body': respbody, 'headers': respheaders, 'status': int(status), } } up = { 'request.host': host, 'request.scheme': scheme, 'request.path': path, 'request.query': query, 'request.method': method, 'request.body': reqbody, 'request.headers': reqheaders, 'response.body': respbody, 'response.headers': respheaders, 'response.status': int(status), } yield collection.update({'_id': self.get_id(ident)}, {'$set': up}) item['_id'] = ident self.render("documentationedit.html", entry=item, tryagain=False, reqheaders=reqheaders, respheaders=respheaders, respfmt=respfmt, reqfmt=reqfmt, scheme=scheme)