From f131288973836f2ff3baa8c48d414c92f824d76c Mon Sep 17 00:00:00 2001 From: Jon Ander Peñalba Date: Fri, 13 Mar 2015 18:47:58 +0100 Subject: Allow changing the Accept Header and default to the FULL version Change-Id: I439daac643404e685a2f21dde4d5d37208fce00f Signed-off-by: Jon Ander Peñalba --- .../egit/github/core/client/GitHubClient.java | 22 ++++++++++++++++++++-- .../egit/github/core/service/GitHubService.java | 16 ++++++++-------- 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; @@ -218,6 +220,22 @@ public class GitHubClient { return this; } + /** + * 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 * @@ -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 -- cgit v1.2.3