Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Ander Peñalba2015-03-13 13:47:58 -0400
committerJon Ander Peñalba2015-03-13 13:47:58 -0400
commitf131288973836f2ff3baa8c48d414c92f824d76c (patch)
tree05a2bffb22e9e1dab50a03f43b95e23104b81564
parent682f085d60dc27095485a0a7d7e7d888dfc4c03c (diff)
downloadegit-github-f131288973836f2ff3baa8c48d414c92f824d76c.tar.gz
egit-github-f131288973836f2ff3baa8c48d414c92f824d76c.tar.xz
egit-github-f131288973836f2ff3baa8c48d414c92f824d76c.zip
Allow changing the Accept Header and default to the FULL version
Change-Id: I439daac643404e685a2f21dde4d5d37208fce00f Signed-off-by: Jon Ander Peñalba <jonan88@gmail.com>
-rw-r--r--org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubClient.java22
-rw-r--r--org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/GitHubService.java16
2 files changed, 28 insertions, 10 deletions
diff --git a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubClient.java b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubClient.java
index dee4218d..6fdd5274 100644
--- a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubClient.java
+++ b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubClient.java
@@ -31,7 +31,7 @@ import static org.eclipse.egit.github.core.client.IGitHubConstants.HOST_DEFAULT;
import static org.eclipse.egit.github.core.client.IGitHubConstants.HOST_GISTS;
import static org.eclipse.egit.github.core.client.IGitHubConstants.PROTOCOL_HTTPS;
import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_V3_API;
-import static org.eclipse.egit.github.core.service.GitHubService.ACCEPT_DEFAULT;
+import static org.eclipse.egit.github.core.service.GitHubService.ACCEPT_FULL;
import com.google.gson.Gson;
import com.google.gson.JsonParseException;
@@ -146,6 +146,8 @@ public class GitHubClient {
private String userAgent = USER_AGENT;
+ private String headerAccept = ACCEPT_FULL;
+
private int bufferSize = 8192;
private int requestLimit = -1;
@@ -219,6 +221,22 @@ public class GitHubClient {
}
/**
+ * Set the value to set as the accept header on every request created.
+ * Specifying a null or empty header parameter will reset this client to use
+ * the default accept header value.
+ *
+ * @param header
+ * @return this client
+ */
+ public GitHubClient setHeaderAccept(final String header) {
+ if (header != null && header.length() > 0)
+ headerAccept = header;
+ else
+ headerAccept = ACCEPT_FULL;
+ return this;
+ }
+
+ /**
* Configure request with standard headers
*
* @param request
@@ -228,7 +246,7 @@ public class GitHubClient {
if (credentials != null)
request.setRequestProperty(HEADER_AUTHORIZATION, credentials);
request.setRequestProperty(HEADER_USER_AGENT, userAgent);
- request.setRequestProperty(HEADER_ACCEPT, ACCEPT_DEFAULT);
+ request.setRequestProperty(HEADER_ACCEPT, headerAccept);
return request;
}
diff --git a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/GitHubService.java b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/GitHubService.java
index 19412107..ed2bd637 100644
--- a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/GitHubService.java
+++ b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/GitHubService.java
@@ -32,24 +32,24 @@ import org.eclipse.egit.github.core.client.RequestException;
public abstract class GitHubService {
/**
- * Accept header for default response
+ * Accept header for raw response (only body)
*/
- public static final String ACCEPT_DEFAULT = "application/vnd.github.v3+json"; //$NON-NLS-1$
+ public static final String ACCEPT_RAW = "application/vnd.github.v3.raw+json"; //$NON-NLS-1$
/**
- * Accept header for full response
+ * Accept header for HTML response (only bodyHtml)
*/
- public static final String ACCEPT_FULL = "application/vnd.github.v3.full+json"; //$NON-NLS-1$
+ public static final String ACCEPT_HTML = "application/vnd.github.v3.html+json"; //$NON-NLS-1$
/**
- * Accept header for HTML response
+ * Accept header for text response (only bodyText)
*/
- public static final String ACCEPT_HTML = "application/vnd.github.v3.html+json"; //$NON-NLS-1$
+ public static final String ACCEPT_TEXT = "application/vnd.github.v3.text+json"; //$NON-NLS-1$
/**
- * Accept header for text response
+ * Accept header for full response (body, bodyText and bodyHtml)
*/
- public static final String ACCEPT_TEXT = "application/vnd.github.v3.text+json"; //$NON-NLS-1$
+ public static final String ACCEPT_FULL = "application/vnd.github.v3.full+json"; //$NON-NLS-1$
/**
* Client field

Back to the top