Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Sawicki2011-12-16 20:36:39 +0000
committerKevin Sawicki2011-12-16 20:36:39 +0000
commit3e804a3227e1084bc3567ef1e3ff3538b3408705 (patch)
tree3abae317aa93e4dc557c1939f2f25dd74fb15b4b
parent10ec41bff246bb6900e91c1543c661139fe743d3 (diff)
downloadegit-github-3e804a3227e1084bc3567ef1e3ff3538b3408705.tar.gz
egit-github-3e804a3227e1084bc3567ef1e3ff3538b3408705.tar.xz
egit-github-3e804a3227e1084bc3567ef1e3ff3538b3408705.zip
Allow request to specify 'Accept' header value
Also add constants to service class for HTML and full values Change-Id: I9df737e2a882778997dc8cb95b0091dd4dc43212
-rw-r--r--org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubClient.java3
-rw-r--r--org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubRequest.java20
-rw-r--r--org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/GitHubService.java15
3 files changed, 38 insertions, 0 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 e2fe7a47..9f30ff2f 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
@@ -602,6 +602,9 @@ public class GitHubClient {
*/
public GitHubResponse get(GitHubRequest request) throws IOException {
HttpURLConnection httpRequest = createGet(request.generateUri());
+ String accept = request.getResponseContentType();
+ if (accept != null)
+ httpRequest.setRequestProperty(HEADER_ACCEPT, accept);
final int code = httpRequest.getResponseCode();
if (isOk(code))
return new GitHubResponse(httpRequest, getBody(request,
diff --git a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubRequest.java b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubRequest.java
index 9a69cdcb..e4edca46 100644
--- a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubRequest.java
+++ b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubRequest.java
@@ -30,6 +30,8 @@ public class GitHubRequest {
private Type type;
+ private String responseContentType;
+
/**
* Create empty request
*/
@@ -121,6 +123,24 @@ public class GitHubRequest {
return this;
}
+ /**
+ * @return responseContentType
+ */
+ public String getResponseContentType() {
+ return responseContentType;
+ }
+
+ /**
+ * Set the desired response content type
+ *
+ * @param responseContentType
+ * @return this request
+ */
+ public GitHubRequest setResponseContentType(String responseContentType) {
+ this.responseContentType = responseContentType;
+ return this;
+ }
+
public int hashCode() {
final String fullUri = generateUri();
return fullUri != null ? fullUri.hashCode() : super.hashCode();
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 78b13e91..73ac32d3 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,6 +32,21 @@ import org.eclipse.egit.github.core.client.RequestException;
public abstract class GitHubService {
/**
+ * Accept header for full response
+ */
+ protected static final String ACCEPT_FULL = "application/vnd.github.beta.full+json"; //$NON-NLS-1$
+
+ /**
+ * Accept header for HTML response
+ */
+ protected static final String ACCEPT_HTML = "application/vnd.github.beta.html+json"; //$NON-NLS-1$
+
+ /**
+ * Accept header for text response
+ */
+ protected static final String ACCEPT_TEXT = "application/vnd.github.beta.text+json"; //$NON-NLS-1$
+
+ /**
* Client field
*/
protected final GitHubClient client;

Back to the top