更多信息以及一个干净的新行后卷曲
~ / . curlrc
-w "\nstatus=%{http_code} %{redirect_url} size=%{size_download} time=%{time_total} content-type=\"%{content_type}\"\n"
(更多选项请点击此处)
redirect_url将为空白,如果请求没有被重定向或您使用-L跟随重定向。
示例输出:
~ ➤ curl https://www.google.com
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="https://www.google.co.uk/?gfe_rd=cr&ei=FW">here</A>.
</BODY></HTML>
status=302 https://www.google.co.uk/?gfe_rd=cr&ei=FW size=262 time=0.044209 content-type="text/html; charset=UTF-8"
~ ➤
编辑,为了使内容更具可读性,你可以在-w行中添加ANSI颜色,这并不容易直接编写,但这个脚本可以生成~/。带有颜色的Curlrc文件。
#!/usr/bin/env python3
from pathlib import Path
import click
chunks = [
('status=', 'blue'),
('%{http_code} ', 'green'),
('%{redirect_url} ', 'green'),
('size=', 'blue'),
('%{size_download} ', 'green'),
('time=', 'blue'),
('%{time_total} ', 'green'),
('content-type=', 'blue'),
('\\"%{content_type}\\"', 'green'),
]
content = '-w "\\n'
for chunk, colour in chunks:
content += click.style(chunk, fg=colour)
content += '\\n"\n'
path = (Path.home() / '.curlrc').resolve()
print('writing:\n{}to: {}'.format(content, path))
path.write_text(content)