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
- documented guideline under CONTRIBUTING.md
- added universal multipart management
- added allHeaders property
- updated tests with new information
- update converters with new usage of allHeaders and removing some usage of cookies
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+278Lines changed: 278 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -133,3 +133,281 @@ project:
133
133
134
134
**IMPORTANT**: By submitting a patch, you agree to allow the project owner to
135
135
license your work under the same license as that used by the project.
136
+
137
+
## Creating New Conversion Targets
138
+
139
+
Please start by browsing for [available targets](/src/targets) and inspect each implementation.
140
+
141
+
a target is a simple module with a constructor that accepts two parameters: `source` and `options`,
142
+
where `source` is the HAR Object to process, and `options` is an optional object with any target
143
+
specific flags *(used for customizing the output)*.
144
+
145
+
### Conversion Rules
146
+
147
+
1. start by reading an understanding the [HAR](http://www.softwareishard.com/blog/har-12-spec/#request) format.
148
+
2. utilize utility properties created for convenience (`source.headersObj`, `source.uriObj` etc ...) *see below for mode details*
149
+
3. follow the guidelines below for best practices and consistency.
150
+
151
+
### Guidelines
152
+
153
+
Using the following example of a request object, HTTP Snippet will pre-process data and create some additional properties:
154
+
155
+
|`source.fullUrl`| the full & final url, including all query string values |
156
+
|`source.uriObj`| the url parsed with `url.parse()`. compatible with `url.format`|
157
+
|`source.queryObj`| a key => value pair, "normalized" version of `source.queryString`, adds additional query string values from the `source.url`|
158
+
|`source.headersObj`| a key => value pair, "normalized" version of `source.headers`, header names are lowercased |
159
+
|`source.allHeaders`| same as `source.headersObj` but with `cookies` header and populated from `source.cookies` array |
160
+
|`source.postData.paramsObj`| a key => value pair, "normalized" version of `source.postData.params`, only for `source.postData.mimeType` = `application/x-www-form-urlencoded`|
161
+
|`source.postData.jsonObj`| the parsed value of `source.postData.text`, only for `source.postData.mimeType` = `application/json`*(or equivalent mimeTypes)*|
// this value will be always overwritten in this scenario
304
+
text:'baz=abc&foo=bar&foo=baz'
305
+
306
+
// see below
307
+
jsonObj:false
308
+
}
309
+
```
310
+
311
+
###### application/json
312
+
313
+
*when postData.mimeType is one of: `application/json`, `text/json`, `text/x-json`, `application/x-json`*
314
+
315
+
```js
316
+
postData: {
317
+
// added to pass har-validator
318
+
size:0,
319
+
320
+
// original value
321
+
mimeType:'application/json',
322
+
323
+
// ignored
324
+
params: [],
325
+
326
+
// default value
327
+
paramsObj:false
328
+
329
+
// the raw body in plain text
330
+
text:'"{\"foo\": \"bar\"}"'
331
+
332
+
// the parsed value of postData.text
333
+
jsonObj: {
334
+
foo:'bar'
335
+
}
336
+
}
337
+
```
338
+
339
+
Notes:
340
+
341
+
- In case of failure to parse `postData.text` as a JSON object, `postData.mimeType` is set to `text/plain`. this is done so that the implementing target, would still attempt to post the raw body as is.
342
+
- This also emphasizes not to rely on `postData.mimeType` for the `Content-Type` header!
343
+
344
+
###### multipart/form-data
345
+
346
+
- will create/overwrite the `Content-Type` header if it does not exist, with the appropriate boundary flag.
347
+
- will create/overwrite the `Content-Length` header
348
+
349
+
```js
350
+
postData: {
351
+
// added to pass har-validator
352
+
size:0,
353
+
354
+
// original value
355
+
mimeType:'multipart/form-data',
356
+
357
+
// parsed into text values
358
+
params: [
359
+
{
360
+
name:'foo',
361
+
value:'bar'
362
+
}
363
+
]
364
+
365
+
// ignored
366
+
paramsObj:false
367
+
368
+
// the raw body in plain text
369
+
// generated based on appropriately parsing the `params` into a multi-boundary content string
370
+
// this value will be always overwritten in this scenario
0 commit comments