def view_full_response(response, headers_only=False): def check_type(response, against): if 'Content-Type' in response.headers and against in response.headers[ 'Content-Type']: return True return False if headers_only: to_print = printable_data(response.raw_headers) to_print = pygments.highlight(to_print, HttpLexer(), TerminalFormatter()) print to_print else: headers = printable_data(response.raw_headers) headers = pygments.highlight(headers, HttpLexer(), TerminalFormatter()) print headers to_print = printable_data(response.raw_data) if 'Content-Type' in response.headers: try: lexer = get_lexer_for_mimetype( response.headers['Content-Type'].split(';')[0]) to_print = pygments.highlight(to_print, lexer, TerminalFormatter()) except ClassNotFound: pass print to_print
def view_full_request(request, headers_only=False): if headers_only: to_print = printable_data(request.raw_headers) else: to_print = printable_data(request.full_request) to_print = pygments.highlight(to_print, HttpLexer(), TerminalFormatter()) print to_print
def setup(app): # enable Pygments http lexer try: import pygments if pygments.__version__ >= '1.5': # use HTTP lexer included in recent versions of Pygments from pygments.lexers import HttpLexer else: # use HTTP lexer from pygments-json if installed from pygson.http_lexer import HTTPLexer as HttpLexer except ImportError: pass # not fatal if we have old (or no) Pygments and no pygments-http else: app.add_lexer('http', HttpLexer())
def show_http_packet(http_packet, filter_headers): buf = '' version = 'HTTP/1.0' if http_packet['httpVersion'] == 'h2': version = 'HTTP/2.0' if 'url' in http_packet: # request url = urlparse(http_packet['url']) uri = url.path if url.query: uri += f'?{url.query}' buf += f'{http_packet["method"]} {uri} {version}\r\n' else: # response if http_packet['status'] == 0: # isn't a real packet return buf += f'{version} {http_packet["status"]} {http_packet["statusText"]}\r\n' for header in http_packet['headers']: if (filter_headers is not None) and (len(filter_headers) > 0) and \ not is_in_insensitive_list(header['name'], filter_headers): continue buf += f'{header["name"]}: {header["value"]}\r\n' buf += '\r\n' content = {} if 'postData' in http_packet: content = http_packet['postData'] if 'content' in http_packet: content = http_packet['content'] print( highlight(buf, HttpLexer(), TerminalTrueColorFormatter(style='autumn'))) if 'text' in content: print(content['text'])
def headers(self, content): return pygments.highlight(content, HttpLexer(), self.formatter)
def print_http_request_log(line, cfg): header, body = line.split("]", 1) h_header = highlight_log(header, TextLexer(), cfg).strip() + "] " h_body = highlight_log(body, HttpLexer(), cfg) click.echo(h_header, nl=False) click.echo(h_body, nl=False)
def highlight(self): request = self.toPlainText() highlighted = highlight(request, HttpLexer(), HtmlFormatter(full=True, style="friendly")) self.setHtml(highlighted)
def pretty_headers(msg): to_ret = msg.headers_section() to_ret = highlight(to_ret, HttpLexer(), TerminalFormatter()) return to_ret