mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-05 19:46:07 +00:00
Merge pull request #1041 from TattsGroup/accept-headers
Move all HTTP headers into AcceptHeaders helper class
This commit is contained in:
@@ -109,10 +109,9 @@ namespace Octokit
|
||||
/// <returns>A list of licenses available on the site</returns>
|
||||
public async Task<IReadOnlyList<LicenseMetadata>> GetAllLicenses()
|
||||
{
|
||||
const string previewAcceptsHeader = "application/vnd.github.drax-preview+json";
|
||||
var endpoint = new Uri("licenses", UriKind.Relative);
|
||||
|
||||
var response = await _connection.Get<LicenseMetadata[]>(endpoint, null, previewAcceptsHeader)
|
||||
var response = await _connection.Get<LicenseMetadata[]>(endpoint, null, AcceptHeaders.LicensesApiPreview)
|
||||
.ConfigureAwait(false);
|
||||
return new ReadOnlyCollection<LicenseMetadata>(response.Body);
|
||||
}
|
||||
@@ -124,10 +123,9 @@ namespace Octokit
|
||||
/// <returns>A <see cref="License" /> that includes the license key, text, and attributes of the license.</returns>
|
||||
public async Task<License> GetLicense(string key)
|
||||
{
|
||||
const string previewAcceptsHeader = "application/vnd.github.drax-preview+json";
|
||||
var endpoint = new Uri("licenses/" + Uri.EscapeUriString(key), UriKind.Relative);
|
||||
|
||||
var response = await _connection.Get<License>(endpoint, null, previewAcceptsHeader)
|
||||
var response = await _connection.Get<License>(endpoint, null, AcceptHeaders.LicensesApiPreview)
|
||||
.ConfigureAwait(false);
|
||||
return response.Body;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace Octokit
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "repository");
|
||||
|
||||
var endpoint = ApiUrls.Releases(owner, name);
|
||||
return ApiConnection.GetAll<Release>(endpoint, null, "application/vnd.github.v3");
|
||||
return ApiConnection.GetAll<Release>(endpoint, null, AcceptHeaders.StableVersion);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -78,7 +78,7 @@ namespace Octokit
|
||||
Ensure.ArgumentNotNull(data, "data");
|
||||
|
||||
var endpoint = ApiUrls.Releases(owner, name);
|
||||
return ApiConnection.Post<Release>(endpoint, data, "application/vnd.github.v3");
|
||||
return ApiConnection.Post<Release>(endpoint, data, AcceptHeaders.StableVersion);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -140,7 +140,7 @@ namespace Octokit
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
|
||||
var endpoint = ApiUrls.ReleaseAssets(owner, name, id);
|
||||
return ApiConnection.GetAll<ReleaseAsset>(endpoint, null, "application/vnd.github.v3");
|
||||
return ApiConnection.GetAll<ReleaseAsset>(endpoint, null, AcceptHeaders.StableVersion);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -165,7 +165,7 @@ namespace Octokit
|
||||
return ApiConnection.Post<ReleaseAsset>(
|
||||
endpoint,
|
||||
data.RawData,
|
||||
"application/vnd.github.v3",
|
||||
AcceptHeaders.StableVersion,
|
||||
data.ContentType,
|
||||
data.Timeout.GetValueOrDefault());
|
||||
}
|
||||
@@ -173,7 +173,7 @@ namespace Octokit
|
||||
return ApiConnection.Post<ReleaseAsset>(
|
||||
endpoint,
|
||||
data.RawData,
|
||||
"application/vnd.github.v3",
|
||||
AcceptHeaders.StableVersion,
|
||||
data.ContentType);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,14 @@
|
||||
{
|
||||
public static class AcceptHeaders
|
||||
{
|
||||
public const string StableVersion = "application/vnd.github.v3";
|
||||
|
||||
public const string StableVersionHtml = "application/vnd.github.html";
|
||||
|
||||
public const string RedirectsPreviewThenStableVersionJson = "application/vnd.github.quicksilver-preview+json; charset=utf-8, application/vnd.github.v3+json; charset=utf-8";
|
||||
|
||||
public const string LicensesApiPreview = "application/vnd.github.drax-preview+json";
|
||||
|
||||
public const string ProtectedBranchesApiPreview = "application/vnd.github.loki-preview+json";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -519,7 +519,7 @@ namespace Octokit
|
||||
|
||||
async Task<IApiResponse<string>> GetHtml(IRequest request)
|
||||
{
|
||||
request.Headers.Add("Accept", "application/vnd.github.html");
|
||||
request.Headers.Add("Accept", AcceptHeaders.StableVersionHtml);
|
||||
var response = await RunRequest(request, CancellationToken.None);
|
||||
return new ApiResponse<string>(response, response.Body as string);
|
||||
}
|
||||
|
||||
@@ -11,8 +11,6 @@ namespace Octokit.Internal
|
||||
/// </summary>
|
||||
public class JsonHttpPipeline
|
||||
{
|
||||
private const string v3ApiVersion = "application/vnd.github.quicksilver-preview+json; charset=utf-8, application/vnd.github.v3+json; charset=utf-8";
|
||||
|
||||
readonly IJsonSerializer _serializer;
|
||||
|
||||
public JsonHttpPipeline() : this(new SimpleJsonSerializer())
|
||||
@@ -32,7 +30,7 @@ namespace Octokit.Internal
|
||||
|
||||
if (!request.Headers.ContainsKey("Accept"))
|
||||
{
|
||||
request.Headers["Accept"] = v3ApiVersion;
|
||||
request.Headers["Accept"] = AcceptHeaders.RedirectsPreviewThenStableVersionJson;
|
||||
}
|
||||
|
||||
if (request.Method == HttpMethod.Get || request.Body == null) return;
|
||||
|
||||
Reference in New Issue
Block a user