@@ -33,8 +33,8 @@ var _getStorageId = function(client) {
3333 // browsers (if this is undesirable)
3434 // navigator.userAgent
3535 return 'forge.http.' +
36- client . url . scheme + '.' +
37- client . url . host + '.' +
36+ client . url . protocol . slice ( 0 , - 1 ) + '.' +
37+ client . url . hostname + '.' +
3838 client . url . port ;
3939} ;
4040
@@ -121,7 +121,7 @@ var _doRequest = function(client, socket) {
121121 // connect
122122 socket . options . request . connectTime = + new Date ( ) ;
123123 socket . connect ( {
124- host : client . url . host ,
124+ host : client . url . hostname ,
125125 port : client . url . port ,
126126 policyPort : client . policyPort ,
127127 policyUrl : client . policyUrl
@@ -310,7 +310,7 @@ var _initSocket = function(client, socket, tlsOptions) {
310310 // prime socket by connecting and caching TLS session, will do
311311 // next request from there
312312 socket . connect ( {
313- host : client . url . host ,
313+ host : client . url . hostname ,
314314 port : client . url . port ,
315315 policyPort : client . policyPort ,
316316 policyUrl : client . policyUrl
@@ -405,7 +405,7 @@ var _readCookies = function(client, response) {
405405 *
406406 * @param options:
407407 * url: the url to connect to (scheme://host:port).
408- * socketPool: the flash socket pool to use.
408+ * socketPool: the flash socket pool to use.
409409 * policyPort: the flash policy port to use (if other than the
410410 * socket pool default), use 0 for flash default.
411411 * policyUrl: the flash policy file URL to use (if provided will
@@ -441,8 +441,10 @@ http.createClient = function(options) {
441441 // get scheme, host, and port from url
442442 options . url = ( options . url ||
443443 window . location . protocol + '//' + window . location . host ) ;
444- var url = http . parseUrl ( options . url ) ;
445- if ( ! url ) {
444+ var url ;
445+ try {
446+ url = new URL ( options . url ) ;
447+ } catch ( e ) {
446448 var error = new Error ( 'Invalid url.' ) ;
447449 error . details = { url : options . url } ;
448450 throw error ;
@@ -469,7 +471,7 @@ http.createClient = function(options) {
469471 // idle sockets
470472 idle : [ ] ,
471473 // whether or not the connections are secure
472- secure : ( url . scheme === 'https' ) ,
474+ secure : ( url . protocol === 'https: ' ) ,
473475 // cookie jar (key'd off of name and then path, there is only 1 domain
474476 // and one setting for secure per client so name+path is unique)
475477 cookies : { } ,
@@ -497,7 +499,7 @@ http.createClient = function(options) {
497499 if ( depth === 0 && verified === true ) {
498500 // compare common name to url host
499501 var cn = certs [ depth ] . subject . getField ( 'CN' ) ;
500- if ( cn === null || client . url . host !== cn . value ) {
502+ if ( cn === null || client . url . hostname !== cn . value ) {
501503 verified = {
502504 message : 'Certificate common name does not match url host.'
503505 } ;
@@ -512,7 +514,7 @@ http.createClient = function(options) {
512514 tlsOptions = {
513515 caStore : caStore ,
514516 cipherSuites : options . cipherSuites || null ,
515- virtualHost : options . virtualHost || url . host ,
517+ virtualHost : options . virtualHost || url . hostname ,
516518 verify : options . verify || _defaultCertificateVerify ,
517519 getCertificate : options . getCertificate || null ,
518520 getPrivateKey : options . getPrivateKey || null ,
@@ -552,7 +554,7 @@ http.createClient = function(options) {
552554 client . send = function ( options ) {
553555 // add host header if not set
554556 if ( options . request . getField ( 'Host' ) === null ) {
555- options . request . setField ( 'Host' , client . url . fullHost ) ;
557+ options . request . setField ( 'Host' , client . url . origin ) ;
556558 }
557559
558560 // set default dummy handlers
@@ -1307,15 +1309,6 @@ http.createResponse = function() {
13071309 return response ;
13081310} ;
13091311
1310- /**
1311- * Parses the scheme, host, and port from an http(s) url.
1312- *
1313- * @param str the url string.
1314- *
1315- * @return the parsed url object or null if the url is invalid.
1316- */
1317- http . parseUrl = forge . util . parseUrl ;
1318-
13191312/**
13201313 * Returns true if the given url is within the given cookie's domain.
13211314 *
@@ -1336,11 +1329,11 @@ http.withinCookieDomain = function(url, cookie) {
13361329 // ensure domain starts with a '.'
13371330 // parse URL as necessary
13381331 if ( typeof url === 'string' ) {
1339- url = http . parseUrl ( url ) ;
1332+ url = new URL ( url ) ;
13401333 }
13411334
1342- // add '.' to front of URL host to match against domain
1343- var host = '.' + url . host ;
1335+ // add '.' to front of URL hostname to match against domain
1336+ var host = '.' + url . hostname ;
13441337
13451338 // if the host ends with domain then it falls within it
13461339 var idx = host . lastIndexOf ( domain ) ;
0 commit comments