예제 #1
0
 def get(self, request, request_id):
     silk_request = Request.objects.get(pk=request_id)
     query_params = None
     if silk_request.query_params:
         query_params = json.loads(silk_request.query_params)
     body = silk_request.raw_body
     try:
         body = json.loads(body)  # Incase encoded as JSON
     except (ValueError, TypeError):
         pass
     context = {
         'silk_request': silk_request,
         'curl': curl_cmd(url=request.build_absolute_uri(silk_request.path),
                          method=silk_request.method,
                          query_params=query_params,
                          body=body,
                          content_type=silk_request.content_type),
         'query_params': json.dumps(query_params, sort_keys=True, indent=4) if query_params else None,
         'client': gen(path=silk_request.path,
                       method=silk_request.method,
                       query_params=query_params,
                       data=body,
                       content_type=silk_request.content_type),
         'request': request
     }
     return render_to_response('silk/request.html', context)
예제 #2
0
 def get(self, request, request_id):
     silk_request = Request.objects.get(pk=request_id)
     query_params = None
     if silk_request.query_params:
         query_params = json.loads(silk_request.query_params)
     body = silk_request.raw_body
     try:
         body = json.loads(body)  # Incase encoded as JSON
     except (ValueError, TypeError):
         pass
     context = {
         'silk_request':
         silk_request,
         'curl':
         curl_cmd(url=request.build_absolute_uri(silk_request.path),
                  method=silk_request.method,
                  query_params=query_params,
                  body=body,
                  content_type=silk_request.content_type),
         'query_params':
         json.dumps(query_params, sort_keys=True, indent=4)
         if query_params else None,
         'client':
         gen(path=silk_request.path,
             method=silk_request.method,
             query_params=query_params,
             data=body,
             content_type=silk_request.content_type),
         'request':
         request
     }
     return render(request, 'silk/request.html', context)
예제 #3
0
 def _execute(self, path, method, query_params=None, body=None, content_type=None):
     cmd = curl_cmd('127.0.0.1:%d' % PORT + path, method=method, query_params=query_params, body=body,
                    content_type=content_type)
     print(cmd)
     p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
     stdout, _ = p.communicate()
     if hasattr(stdout, 'decode'):  #py3
         raw_response = stdout.decode("utf-8")
     else:  #py2
         raw_response = stdout
     return json.loads(raw_response)