public void setRequestUrl ( String urlStr ) { // This looks a little confusing: We're trying to fixup an incoming // request URL that starts with: // "http(s):/www.archive.org" // so it becomes: // "http(s)://www.archive.org" // (note the missing second "/" in the first) // // if that is not the case, then see if the incoming scheme // is known, adding an implied "http://" scheme if there doesn't appear // to be a scheme.. // TODO: make the default "http://" configurable. if ( ! urlStr . startsWith ( UrlOperations . HTTP_SCHEME ) && ! urlStr . startsWith ( UrlOperations . HTTPS_SCHEME ) && ! urlStr . startsWith ( UrlOperations . FTP_SCHEME ) && ! urlStr . startsWith ( UrlOperations . FTPS_SCHEME ) ) { if ( urlStr . startsWith ( "http:/" ) ) { urlStr = UrlOperations . HTTP_SCHEME + urlStr . substring ( 6 ) ; } else if ( urlStr . startsWith ( "https:/" ) ) { urlStr = UrlOperations . HTTPS_SCHEME + urlStr . substring ( 7 ) ; } else if ( urlStr . startsWith ( "ftp:/" ) ) { urlStr = UrlOperations . FTP_SCHEME + urlStr . substring ( 5 ) ; } else if ( urlStr . startsWith ( "ftps:/" ) ) { urlStr = UrlOperations . FTPS_SCHEME + urlStr . substring ( 6 ) ; } else { if ( UrlOperations . urlToScheme ( urlStr ) == null ) { urlStr = UrlOperations . HTTP_SCHEME + urlStr ; } } } try { String decodedUrlStr = URLDecoder . decode ( urlStr , "UTF-8" ) ; String idnEncodedHost = UsableURIFactory . getInstance ( decodedUrlStr , "UTF-8" ) . getHost ( ) ; if ( idnEncodedHost != null ) { // If url is absolute, replace host with IDN-encoded host. String unicodeEncodedHost = URLEncoder . encode ( IDNA . toUnicode ( idnEncodedHost ) , "UTF-8" ) ; urlStr = urlStr . replace ( unicodeEncodedHost , idnEncodedHost ) ; } } catch ( UnsupportedEncodingException ex ) { // Should never happen as UTF-8 is required to be present throw new RuntimeException ( ex ) ; } catch ( URIException ex ) { throw new RuntimeException ( ex ) ; } put ( REQUEST_URL , urlStr ) ; }
Set the request URL .