All Projects → apiaryio → Curl Trace Parser

apiaryio / Curl Trace Parser

Licence: mit
Parser for output from Curl --trace option

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Curl Trace Parser

Phplrt
PHP Language Recognition Tool
Stars: ✭ 127 (-30.6%)
Mutual labels:  parser, trace
Java Binary Block Parser
most comfortable and dynamic way to process bit data in Java and Android
Stars: ✭ 180 (-1.64%)
Mutual labels:  parser
Feedjira
A feed parsing library
Stars: ✭ 2,017 (+1002.19%)
Mutual labels:  parser
Cron Parser
Java Parser For Cron Expressions
Stars: ✭ 176 (-3.83%)
Mutual labels:  parser
Elf Parser
Lightweight elf binary parser with no external dependencies - Sections, Symbols, Relocations, Segments
Stars: ✭ 172 (-6.01%)
Mutual labels:  parser
Cloudsim Plus
☕️🏗⛅️🎓 A modern, full-featured, easier-to-use, highly extensible, faster and more accurate Java 8+ Framework for Cloud Computing Simulation
Stars: ✭ 178 (-2.73%)
Mutual labels:  trace
Graphql S2s
Add GraphQL Schema support for type inheritance, generic typing, metadata decoration. Transpile the enriched GraphQL string schema into the standard string schema understood by graphql.js and the Apollo server client.
Stars: ✭ 171 (-6.56%)
Mutual labels:  parser
Rebel Framework
Advanced and easy to use penetration testing framework 💣🔎
Stars: ✭ 183 (+0%)
Mutual labels:  trace
Ts Sql
A SQL database implemented purely in TypeScript type annotations.
Stars: ✭ 2,324 (+1169.95%)
Mutual labels:  parser
Participle
A parser library for Go
Stars: ✭ 2,302 (+1157.92%)
Mutual labels:  parser
Monkey Rust
An interpreter for the Monkey programming language written in Rust
Stars: ✭ 174 (-4.92%)
Mutual labels:  parser
Neversink Filter
This is a lootfilter for the game "Path of Exile". It hides low value items, uses a markup-scheme and sounds to highlight expensive gear and is based on economy data mining.
Stars: ✭ 2,164 (+1082.51%)
Mutual labels:  parser
Php Whois
PHP WHOIS provides parsed and raw whois lookup of domains and ASN routes. PHP 5.4+ and 7+ compatible
Stars: ✭ 179 (-2.19%)
Mutual labels:  curl
Zebra curl
A high performance cURL PHP library for running of multiple requests at once, asynchronously
Stars: ✭ 172 (-6.01%)
Mutual labels:  curl
Pornhub Api
Unofficial API for PornHub.com in Python
Stars: ✭ 181 (-1.09%)
Mutual labels:  parser
J2team Community
Join our group to see more
Stars: ✭ 172 (-6.01%)
Mutual labels:  curl
Weaver
Trace Go program execution with uprobes and eBPF
Stars: ✭ 174 (-4.92%)
Mutual labels:  trace
Ethereum Graph Debugger
Ethereum solidity graph plain debugger. To have the whole picture when debugging.
Stars: ✭ 177 (-3.28%)
Mutual labels:  trace
Atldotnet
Fully managed, portable and easy-to-use C# library to read and edit audio data and metadata (tags) from various audio formats, playlists and CUE sheets
Stars: ✭ 180 (-1.64%)
Mutual labels:  parser
Snapdragon
snapdragon is an extremely pluggable, powerful and easy-to-use parser-renderer factory.
Stars: ✭ 180 (-1.64%)
Mutual labels:  parser

The curl --trace parser

NPM Version Build Status Dependency Status devDependency Status Greenkeeper badge

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

$ npm install -g curl-trace-parser

Record your first trace file

$ 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 <
  • Request and Response is delimited by CR+LF
  • Both Request and Response are terminated by an extra trailing LF

Note: This is little bit tricky because HTTP RFC does not have declared delimiter for Request and Response, for obvious reasons.

$ cat tracefile | curl-trace-parser --raw
> 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 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

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

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].