parse-proxy-uri
v2.0.15
Published
Parse proxy URIs into host, port, auth, and protocol — supports HTTP, HTTPS, and SOCKS schemes.
Downloads
5,849
Maintainers
Readme
parse-proxy-uri
Lightweight module for parsing a proxy URI.
Install
$ npm install parse-proxy-uri --saveUsage
const parseProxy = require('parse-proxy-uri')
const proxy = parseProxy('http://alice:[email protected]:8080')
proxy.auth // => 'alice:TopSecret'
proxy.host // => 'proxy.example:8080'
proxy.protocol // => 'http:'
proxy.toString() // => 'http://alice:[email protected]:8080'The returned value is a URL subclass, so username and password keep their
WHATWG percent-encoded form and auth gives you the decoded pair.
An invalid input throws a ParseProxyError (a TypeError) with
code: 'INVALID_PROXY'.
Mutation
Every setter re-validates, so a parsed proxy can never become something that
parseProxy would have rejected. A rejected assignment throws and leaves the
proxy untouched.
username and password take raw values and encode them for you:
const parseProxy = require('parse-proxy-uri')
const proxy = parseProxy('http://proxy.example:8080')
proxy.password = 'p@ss/word'
proxy.password // => 'p%40ss%2Fword'
proxy.auth // => ':p@ss/word'href takes a whole proxy URI, held to the same rules as parseProxy itself.
parse-proxy-uri © Kiko Beats, released under the MIT License. Authored and maintained by Kiko Beats with help from contributors.
kikobeats.com · GitHub Kiko Beats · X @Kikobeats
