百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
C

curl-trace-parser

> 编程语言
开源

用于处理 Curl --trace 选项输出的解析器

198 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

用于处理 Curl --trace 选项输出的解析器

The curl --trace parser

The story

Did you know that you can record raw HTTP communication of Curl command-line tool with the --trace and --trace-ascii option? It's the only way I know to get raw HTTP communication without using the tcpdump or wireshark. For example, this trick is very useful for the proper introspection into HTTP communication of an undocumented RESTful API.

The only glitch is that cURL --trace saves data in its custom format, far from human-friendly, saving chunks as they are being received and splitting them by packets. If you want a human readable form then this parser is what you need. Delivered as a Node.js package.

Usage

$ curl --trace - http://httpbin.org/ip | curl-trace-parser

Sample API

We will be using this sample API created with the Apiary.io mock server to demonstrate tracing an HTTP communication and the use of the cURL trace parser.

Install the cURL trace parser

bash
$ npm install -g curl-trace-parser

Record your first trace file

bash
$ curl --trace tracefile --header "Content-Type: application/json" \
--request POST \
--data-binary "{ \"product\":\"1AB23ORM\", \"quantity\": 2 }" \
"http://curltraceparser.apiary.io/shopping-cart"

Note this cURL example is copied and pasted from Apiary interactive API documentation.

Examples

--raw format

The output is ASCII representation of a raw HTTP message with few modifications:

  • Request line begins with >
  • Response line begins with ` POST /shopping-cart HTTP/1.1

User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8x zlib/1.2.5 Host: curltraceparser.apiary.io Accept: / Content-Type: application/json Content-Length: 39

{ "product":"1AB23ORM", "quantity": 2 }

< HTTP/1.1 201 Created < Content-Type: application/json < Date: Tue, 30 Jul 2013 11:32:30 GMT < X-Apiary-Ratelimit-Limit: 120 < X-Apiary-Ratelimit-Remaining: 119 < Content-Length: 50 < Connection: keep-alive < < { "status": "created", "url": "/shopping-cart/2" }


### `--blueprint` format

The output is HTTP Request and Response in the [API blueprint format](http://apiblueprint.org) which is the superset of markdown.

$ cat tracefile | ./bin/curl-trace-parser --blueprint

POST /shopping-cart

  • Request

    • Headers

        User-Agent:curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8x zlib/1.2.5
        Host:curltraceparser.apiary.io
        Accept:*/*
        Content-Type:application/json
        Content-Length:39
      
    • Body

        { "product":"1AB23ORM", "quantity": 2 }
  • Response 201

    • Headers

        Content-Type:application/json
        Date:Tue, 30 Jul 2013 11:32:30 GMT
        X-Apiary-Ratelimit-Limit:120
        X-Apiary-Ratelimit-Remaining:119
        Content-Length:50
        Connection:keep-alive
      
    • Body

        { "status": "created", "url": "/shopping-cart/2" }

Note: This format does not expect any CR+LF in the message body

### Parse the trace to raw HTTP file using Node.JS

```javascript
var fs = require('fs');
var parser = require('curl-trace-parser');
fs.readFile('./tracefile', 'utf8', function (err,trace) {
  console.log(parser.parse(trace));
})

Output format reverse parser

javascript
var fs = require('fs');
var parser = require('curl-trace-parser');
fs.readFile('./tracefile', 'utf8', function (err,trace) {
  console.log(parser.parseBack(trace));
})

API Reference

parse(traceString) - parse string with trace to object with raw request and response

parseToString(traceString) - parse string with trace to output format

parseBack(outputString) - parse string with output format back to object with raw request an resposne

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScriptcurlhttpparsersjs-team

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言