You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+289-2Lines changed: 289 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ patches and features.
11
11
## Using the issue tracker
12
12
13
13
The [issue tracker](/issues) is the preferred channel for [bug reports](#bug-reports),
14
-
[features requests](#feature-requests) and [submitting pull requests](#pull-requests),
14
+
[features requests](#feature-requests) and [submitting pull requests](#pull-requests),
15
15
but please respect the following restrictions:
16
16
17
17
* Please **do not** use the issue tracker for personal support requests (use
@@ -136,4 +136,291 @@ license your work under the same license as that used by the project.
136
136
137
137
## Creating New Conversion Targets
138
138
139
-
For a info on creating new conversion targets, please review this [guideline](https://github.com/Mashape/httpsnippet/wiki/Creating-Targets)
139
+
A target is a simple module with a constructor that accepts two parameters: `source` and `options`, where `source` is the HAR Object to process, and `options` is an optional object with any target-specific flags *(used for customizing the output)*.
140
+
141
+
###### Example
142
+
143
+
```js
144
+
module.exports = function (source, opts) {
145
+
// optionally process `opts` object for target specific configuration
146
+
//
147
+
// process `source` object
148
+
//
149
+
// return processed output as string
150
+
};
151
+
152
+
module.exports.info = {
153
+
key: 'curl',
154
+
title: 'cURL',
155
+
link: 'http://curl.haxx.se/',
156
+
description: 'curl is a command line tool and library for transferring data with URL syntax',
157
+
extname: '.sh'
158
+
};
159
+
```
160
+
161
+
### Conversion Rules
162
+
163
+
1. Start by reading and understanding the [HAR](http://www.softwareishard.com/blog/har-12-spec/#request) format.
164
+
2. Utilize utility properties created for convenience (`source.headersObj`, `source.uriObj` etc ...) *see below for mode details*
165
+
3. Follow the guidelines below for best practices and consistency.
166
+
167
+
### Guidelines
168
+
169
+
Using the following example of a request object, HTTP Snippet will pre-process data and create some additional properties:
| `source.fullUrl` | the full & final url, including all query string values |
174
+
| `source.uriObj` | the url parsed with `url.parse()`. compatible with `url.format` |
175
+
| `source.queryObj` | a key => value pair, "normalized" version of `source.queryString`, adds additional query string values from the `source.url` |
176
+
| `source.headersObj` | a key => value pair, "normalized" version of `source.headers`, header names are lowercased |
177
+
| `source.allHeaders` | same as `source.headersObj` but with `cookies` header and populated from `source.cookies` array |
178
+
| `source.postData.jsonObj` | the parsed value of `source.postData.text`, only for `source.postData.mimeType` = `application/json` *(or equivalent mimeTypes)* |
179
+
| `source.postData.paramsObj` | a key => value pair, "normalized" version of `source.postData.params`, only for `source.postData.mimeType` = `application/x-www-form-urlencoded` |
// this value will be always overwritten in this scenario
322
+
text: 'baz=abc&foo=bar&foo=baz'
323
+
324
+
// see below
325
+
jsonObj: false
326
+
}
327
+
```
328
+
329
+
###### application/json
330
+
331
+
- Will match when `postData.mimeType` is one of: `application/json`, `text/json`, `text/x-json`, `application/x-json`
332
+
- In case of failure to parse `postData.text` as a JSON object, `postData.mimeType` is set to `text/plain`, `postData.jsonObj` remains as `false`. this is done so that the implementing target, would still attempt to post the raw body as is.
333
+
- This also emphasizes not to rely on `postData.mimeType` for the `Content-Type` header!
334
+
335
+
```js
336
+
postData: {
337
+
// added to pass har-validator
338
+
size: 0,
339
+
340
+
// original value
341
+
mimeType: 'application/json',
342
+
343
+
// ignored
344
+
params: [],
345
+
346
+
// default value
347
+
paramsObj: false
348
+
349
+
// the raw body in plain text
350
+
text: '"{\"foo\": \"bar\"}"'
351
+
352
+
// the parsed value of postData.text
353
+
jsonObj: {
354
+
foo: 'bar'
355
+
}
356
+
}
357
+
```
358
+
359
+
###### multipart/form-data
360
+
361
+
- Will match when `postData.mimeType` is one of: `multipart/mixed` `multipart/related`, `multipart/form-data`, `multipart/alternative`
362
+
- Will force `postData.mimeType` to `multipart/form-data`
363
+
- Will create/overwrite the `Content-Type` header if it does not exist, with the appropriate boundary flag.
364
+
- When no `params[].value` is present, will default to empty content
365
+
366
+
```js
367
+
postData: {
368
+
// added to pass har-validator
369
+
size: 0,
370
+
371
+
// original value
372
+
mimeType: 'multipart/form-data',
373
+
374
+
// parsed into text values
375
+
params: [
376
+
{
377
+
name: 'foo',
378
+
value: 'bar'
379
+
}
380
+
]
381
+
382
+
// ignored
383
+
paramsObj: false
384
+
385
+
// the raw body in plain text
386
+
// generated based on appropriately parsing the `params` into a multi-boundary content string
387
+
// this value will be always overwritten in this scenario
0 commit comments