-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathurl-parse.js
More file actions
51 lines (44 loc) · 1.68 KB
/
url-parse.js
File metadata and controls
51 lines (44 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Parsing URL example using built-in 'url' module to parse URLs.
// This demonstrates use of the DataPower GatewayScript (ECMA) url parse function.
// Author: Steve Edwards, Escala Ltd.
// Date : 2014-09-30.
// Note : this code is for demonstration purposes only, not production - level.
var serviceVars = require ( 'service-metadata' ); // import the service variables functions
var url = require ( 'url' ); // import the URL parsing functions
var urlStr = serviceVars.URLIn; // get URL of input request
var urlObject = url.parse(urlStr, true, true); // URL details in JSON
session.output.write(urlObject);
/*
Returns the following with 2nd, 3rd parameters = true, true:
{
"protocol": "http:",
"slashes": true,
"auth": null,
"host": "192.168.1.70:80",
"port": "80",
"hostname": "192.168.1.70",
"hash": null,
"search": "?param1=val1¶m2=val2",
"query": {
"param1": "val1",
"param2": "val2"
},
"pathname": "/url-parse",
"path": "/url-parse?param1=val1¶m2=val2",
"href": "http://192.168.1.70:80/url-parse?param1=val1¶m2=val2"
}
From IBM KnowledgeCenter:
url.parse(urlStr, [parseQueryString], [slashesDenoteHost])
urlStr A URL specified as a string.
parseQueryString
- A Boolean value that indicates whether the query string is parsed by the querystring module.
- The string is parsed if true and not otherwise.
The default is false.
slashesDenoteHost
- A Boolean value that indicates whether to interpret a name that follows a double-slash as a host name.
- For example, if true, the string //foo/bar is treated as
{ host: 'foo', pathname: '/bar' }
rather than as
{ pathname: '//foo/bar' }.
The default is false.
*/