mirror of
https://github.com/jlengrand/github-api.git
synced 2026-04-08 08:21:23 +00:00
- When we receive events from a webhook, it is non-trivial to determine which GitHub instance the event came from or for that matter even if the event actually came from GitHub or GitHub Enterprise. - In order to ensure that the logic for parsing events does not get replicated in clients, we need to be able to call GitHub.parseEventPayload(Reader,Class) without knowing which GitHub the event originates from and without the resulting objects triggering API calls back to a GitHub - Thus we add GitHub.offline() to provide an off-line connection - Thus we modify some of the object classes to return best-effort objects when off-line - Add support for more of the event types into GHEventPayload - Add tests of the event payload and accessing critical fields when using GitHub.offline()
42 lines
1.1 KiB
Java
42 lines
1.1 KiB
Java
package org.kohsuke.github;
|
|
|
|
import org.kohsuke.github.extras.ImpatientHttpConnector;
|
|
|
|
import java.io.IOException;
|
|
import java.net.HttpURLConnection;
|
|
import java.net.URL;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
/**
|
|
* Pluggability for customizing HTTP request behaviors or using altogether different library.
|
|
*
|
|
* <p>
|
|
* For example, you can implement this to st custom timeouts.
|
|
*
|
|
* @author Kohsuke Kawaguchi
|
|
*/
|
|
public interface HttpConnector {
|
|
/**
|
|
* Opens a connection to the given URL.
|
|
*/
|
|
HttpURLConnection connect(URL url) throws IOException;
|
|
|
|
/**
|
|
* Default implementation that uses {@link URL#openConnection()}.
|
|
*/
|
|
HttpConnector DEFAULT = new ImpatientHttpConnector(new HttpConnector() {
|
|
public HttpURLConnection connect(URL url) throws IOException {
|
|
return (HttpURLConnection) url.openConnection();
|
|
}
|
|
});
|
|
|
|
/**
|
|
* Stub implementation that is always off-line.
|
|
*/
|
|
HttpConnector OFFLINE = new HttpConnector() {
|
|
public HttpURLConnection connect(URL url) throws IOException {
|
|
throw new IOException("Offline");
|
|
}
|
|
};
|
|
}
|