Class UrlPacScriptSource
java.lang.Object
com.github.markusbernhardt.proxy.selector.pac.UrlPacScriptSource
- All Implemented Interfaces:
PacScriptSource
Script source that will load the content of a PAC file from an webserver. The
script content is cached once it was downloaded.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate String
downloadPacContent
(String url) Downloads the script from a webserver.private BufferedReader
Build a BufferedReader around the open HTTP connection.getScriptContentprotected int
getTimeOut
(String overrideProperty, int defaultValue) Gets the timeout value from a property or uses the given default value if the property cannot be parsed.boolean
isScriptValid(package private) String
parseCharsetFromHeader
(String contentType) Response Content-Type could be something like this: application/x-ns-proxy-autoconfig; charset=UTF-8private String
Reads the whole content available into a String.private String
readPacFileContent
(String scriptUrl) Reads a PAC script from a local file.private void
setPacProxySelectorEnabled
(boolean enable) Enables/disables the PAC proxy selector while we download to prevent recursion.private HttpURLConnection
Configure the connection to download from.toString()
-
Field Details
-
DEFAULT_CONNECT_TIMEOUT
private static final int DEFAULT_CONNECT_TIMEOUT- See Also:
-
DEFAULT_READ_TIMEOUT
private static final int DEFAULT_READ_TIMEOUT- See Also:
-
OVERRIDE_CONNECT_TIMEOUT
- See Also:
-
OVERRIDE_READ_TIMEOUT
- See Also:
-
scriptUrl
-
scriptContent
-
expireAtMillis
private long expireAtMillis
-
-
Constructor Details
-
UrlPacScriptSource
Constructor- Parameters:
url
- the URL to download the script from.
-
-
Method Details
-
getScriptContent
getScriptContent- Specified by:
getScriptContent
in interfacePacScriptSource
- Returns:
- a script.
- Throws:
IOException
- on read error.- See Also:
-
readPacFileContent
Reads a PAC script from a local file.- Parameters:
scriptUrl
-- Returns:
- the content of the script file.
- Throws:
IOException
URISyntaxException
-
downloadPacContent
Downloads the script from a webserver.- Parameters:
url
- the URL to the script file.- Returns:
- the script content.
- Throws:
IOException
- on read error.
-
setPacProxySelectorEnabled
private void setPacProxySelectorEnabled(boolean enable) Enables/disables the PAC proxy selector while we download to prevent recursion. See issue: 26 in the change tracker. -
readAllContent
Reads the whole content available into a String.- Parameters:
r
- to read from.- Returns:
- the complete PAC file content.
- Throws:
IOException
-
getReader
private BufferedReader getReader(HttpURLConnection con) throws UnsupportedEncodingException, IOException Build a BufferedReader around the open HTTP connection.- Parameters:
con
- to read from- Returns:
- the BufferedReader.
- Throws:
UnsupportedEncodingException
IOException
-
setupHTTPConnection
Configure the connection to download from.- Parameters:
url
- to get the pac file content from- Returns:
- a HTTPUrlConnecion to this url.
- Throws:
IOException
MalformedURLException
-
getTimeOut
Gets the timeout value from a property or uses the given default value if the property cannot be parsed.- Parameters:
overrideProperty
- the property to define the timeout value in millisecondsdefaultValue
- the default timeout value in milliseconds.- Returns:
- the value to use.
-
parseCharsetFromHeader
Response Content-Type could be something like this: application/x-ns-proxy-autoconfig; charset=UTF-8- Parameters:
contentType
- header field.- Returns:
- the extracted charset if set or the default charset (UTF-8).
-
toString
-
isScriptValid
public boolean isScriptValid()isScriptValid- Specified by:
isScriptValid
in interfacePacScriptSource
- Returns:
- true if everything is fine, else false.
- See Also:
-