diff --git a/Octokit.Reactive/Clients/IObservableRepositoryContentsClient.cs b/Octokit.Reactive/Clients/IObservableRepositoryContentsClient.cs
index 4b56ed1b..a5221a6b 100644
--- a/Octokit.Reactive/Clients/IObservableRepositoryContentsClient.cs
+++ b/Octokit.Reactive/Clients/IObservableRepositoryContentsClient.cs
@@ -34,8 +34,18 @@ namespace Octokit.Reactive
/// The owner of the repository
/// The name of the repository
///
+ [Obsolete("Use GetArchive to download the archive instead")]
IObservable GetArchiveLink(string owner, string name);
+ ///
+ /// Get an archive of a given repository's contents
+ ///
+ /// https://developer.github.com/v3/repos/contents/#get-archive-link
+ /// The owner of the repository
+ /// The name of the repository
+ /// A promise, containing the binary contents of the archive
+ IObservable GetArchive(string owner, string name);
+
///
/// This method will return a 302 to a URL to download a tarball or zipball archive for a repository.
/// Please make sure your HTTP framework is configured to follow redirects or you will need to use the
@@ -47,8 +57,19 @@ namespace Octokit.Reactive
/// The name of the repository
/// The format of the archive. Can be either tarball or zipball
///
+ [Obsolete("Use GetArchive to download the archive instead")]
IObservable GetArchiveLink(string owner, string name, ArchiveFormat archiveFormat);
+ ///
+ /// Get an archive of a given repository's contents, in a specific format
+ ///
+ /// https://developer.github.com/v3/repos/contents/#get-archive-link
+ /// The owner of the repository
+ /// The name of the repository
+ /// The format of the archive. Can be either tarball or zipball
+ /// A promise, containing the binary contents of the archive
+ IObservable GetArchive(string owner, string name, ArchiveFormat archiveFormat);
+
///
/// This method will return a 302 to a URL to download a tarball or zipball archive for a repository.
/// Please make sure your HTTP framework is configured to follow redirects or you will need to use the
@@ -61,8 +82,20 @@ namespace Octokit.Reactive
/// The format of the archive. Can be either tarball or zipball
/// A valid Git reference.
///
+ [Obsolete("Use GetArchive to download the archive instead")]
IObservable GetArchiveLink(string owner, string name, ArchiveFormat archiveFormat, string reference);
+ ///
+ /// Get an archive of a given repository's contents, using a specific format and reference
+ ///
+ /// https://developer.github.com/v3/repos/contents/#get-archive-link
+ /// The owner of the repository
+ /// The name of the repository
+ /// The format of the archive. Can be either tarball or zipball
+ /// A valid Git reference.
+ /// A promise, containing the binary contents of the archive
+ IObservable GetArchive(string owner, string name, ArchiveFormat archiveFormat, string reference);
+
///
/// Returns the contents of a file or directory in a repository.
///
diff --git a/Octokit.Reactive/Clients/ObservableRepositoryContentsClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryContentsClient.cs
index ca2889e4..a4a5e4b2 100644
--- a/Octokit.Reactive/Clients/ObservableRepositoryContentsClient.cs
+++ b/Octokit.Reactive/Clients/ObservableRepositoryContentsClient.cs
@@ -59,11 +59,24 @@ namespace Octokit.Reactive
/// The owner of the repository
/// The name of the repository
///
+ [Obsolete("Use GetArchive to download the archive instead")]
public IObservable GetArchiveLink(string owner, string name)
{
return GetArchiveLink(owner, name, ArchiveFormat.Tarball, string.Empty);
}
+ ///
+ /// Get an archive of a given repository's contents
+ ///
+ /// https://developer.github.com/v3/repos/contents/#get-archive-link
+ /// The owner of the repository
+ /// The name of the repository
+ /// A promise, containing the binary contents of the archive
+ public IObservable GetArchive(string owner, string name)
+ {
+ return _client.Repository.Content.GetArchive(owner, name).ToObservable();
+ }
+
///
/// This method will return a 302 to a URL to download a tarball or zipball archive for a repository.
/// Please make sure your HTTP framework is configured to follow redirects or you will need to use the
@@ -75,11 +88,25 @@ namespace Octokit.Reactive
/// The name of the repository
/// The format of the archive. Can be either tarball or zipball
///
+ [Obsolete("Use GetArchive to download the archive instead")]
public IObservable GetArchiveLink(string owner, string name, ArchiveFormat archiveFormat)
{
return GetArchiveLink(owner, name, archiveFormat, String.Empty);
}
+ ///
+ /// Get an archive of a given repository's contents, in a specific format
+ ///
+ /// https://developer.github.com/v3/repos/contents/#get-archive-link
+ /// The owner of the repository
+ /// The name of the repository
+ /// The format of the archive. Can be either tarball or zipball
+ /// A promise, containing the binary contents of the archive
+ public IObservable GetArchive(string owner, string name, ArchiveFormat archiveFormat)
+ {
+ return _client.Repository.Content.GetArchive(owner, name, archiveFormat).ToObservable();
+ }
+
///
/// This method will return a 302 to a URL to download a tarball or zipball archive for a repository.
/// Please make sure your HTTP framework is configured to follow redirects or you will need to use the
@@ -92,6 +119,7 @@ namespace Octokit.Reactive
/// The format of the archive. Can be either tarball or zipball
/// A valid Git reference.
///
+ [Obsolete("Use GetArchive to download the archive instead")]
public IObservable GetArchiveLink(string owner, string name, ArchiveFormat archiveFormat, string reference)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
@@ -100,6 +128,20 @@ namespace Octokit.Reactive
return _client.Repository.Content.GetArchiveLink(owner, name, archiveFormat, reference).ToObservable();
}
+ ///
+ /// Get an archive of a given repository's contents, using a specific format and reference
+ ///
+ /// https://developer.github.com/v3/repos/contents/#get-archive-link
+ /// The owner of the repository
+ /// The name of the repository
+ /// The format of the archive. Can be either tarball or zipball
+ /// A valid Git reference.
+ /// A promise, containing the binary contents of the archive
+ public IObservable GetArchive(string owner, string name, ArchiveFormat archiveFormat, string reference)
+ {
+ return _client.Repository.Content.GetArchive(owner, name, archiveFormat, reference).ToObservable();
+ }
+
///
/// Returns the contents of a file or directory in a repository.
///
diff --git a/Octokit.Tests.Integration/Clients/RepositoryContentsClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryContentsClientTests.cs
index 707c4c47..d2d0bf9d 100644
--- a/Octokit.Tests.Integration/Clients/RepositoryContentsClientTests.cs
+++ b/Octokit.Tests.Integration/Clients/RepositoryContentsClientTests.cs
@@ -115,43 +115,43 @@ namespace Octokit.Tests.Integration.Clients
}
}
- [IntegrationTest]
- public async Task GetsArchiveLinkAsTarball()
+ [IntegrationTest(Skip = "this will probably take too long")]
+ public async Task GetsArchiveAsTarball()
{
var github = Helper.GetAuthenticatedClient();
- var archiveLink = await github
+ var archive = await github
.Repository
.Content
- .GetArchiveLink("octokit", "octokit.net");
+ .GetArchive("octokit", "octokit.net");
- Assert.Equal("https://codeload.github.com/octokit/octokit.net/legacy.tar.gz/master", archiveLink);
+ Assert.NotEmpty(archive);
}
[IntegrationTest]
- public async Task GetsArchiveLinkAsZipball()
+ public async Task GetsArchiveAsZipball()
{
var github = Helper.GetAuthenticatedClient();
- var archiveLink = await github
+ var archive = await github
.Repository
.Content
- .GetArchiveLink("octokit", "octokit.net", ArchiveFormat.Zipball, "");
+ .GetArchive("octokit", "octokit.net", ArchiveFormat.Zipball, "");
- Assert.Equal("https://codeload.github.com/octokit/octokit.net/legacy.zip/master", archiveLink);
+ Assert.NotEmpty(archive);
}
[IntegrationTest]
- public async Task GetsArchiveLinkForReleaseBranchAsTarball()
+ public async Task GetsArchiveForReleaseBranchAsTarball()
{
var github = Helper.GetAuthenticatedClient();
- var archiveLink = await github
+ var archive = await github
.Repository
.Content
- .GetArchiveLink("alfhenrik", "ScriptCs.OctoKit", ArchiveFormat.Tarball, "dev");
+ .GetArchive("alfhenrik", "ScriptCs.OctoKit", ArchiveFormat.Tarball, "dev");
- Assert.Equal("https://codeload.github.com/alfhenrik/ScriptCs.OctoKit/legacy.tar.gz/dev", archiveLink);
+ Assert.NotEmpty(archive);
}
}
}
\ No newline at end of file
diff --git a/Octokit.Tests/Http/RedirectHandlerTests.cs b/Octokit.Tests/Http/RedirectHandlerTests.cs
index beb55b87..5ba2face 100644
--- a/Octokit.Tests/Http/RedirectHandlerTests.cs
+++ b/Octokit.Tests/Http/RedirectHandlerTests.cs
@@ -102,18 +102,6 @@ namespace Octokit.Tests.Http
Assert.Null(response.RequestMessage.Headers.Authorization);
}
-
- [Fact]
- public async Task DisabledRedirectShouldPassThrough()
- {
- var invoker = CreateInvoker(new HttpResponseMessage(HttpStatusCode.Found));
- var httpRequestMessage = CreateRequest(HttpMethod.Get);
- httpRequestMessage.Properties[RedirectHandler.AllowAutoRedirectKey] = false;
- var response = await invoker.SendAsync(httpRequestMessage, new CancellationToken());
-
- Assert.Equal(response.StatusCode, HttpStatusCode.Redirect);
- Assert.Same(response.RequestMessage, httpRequestMessage);
- }
[Theory]
[InlineData(HttpStatusCode.MovedPermanently)] // 301
@@ -179,7 +167,6 @@ namespace Octokit.Tests.Http
{
var httpRequestMessage = new HttpRequestMessage();
httpRequestMessage.RequestUri = new Uri("http://example.org/foo");
- httpRequestMessage.Properties[RedirectHandler.AllowAutoRedirectKey] = true;
httpRequestMessage.Method = method;
return httpRequestMessage;
}
diff --git a/Octokit/Clients/IRepositoryContentsClient.cs b/Octokit/Clients/IRepositoryContentsClient.cs
index 45a217b0..e02cd689 100644
--- a/Octokit/Clients/IRepositoryContentsClient.cs
+++ b/Octokit/Clients/IRepositoryContentsClient.cs
@@ -1,3 +1,4 @@
+using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Octokit.Internal;
@@ -57,8 +58,18 @@ namespace Octokit
/// The owner of the repository
/// The name of the repository
///
+ [Obsolete("Use GetArchive to download the archive instead")]
Task GetArchiveLink(string owner, string name);
+ ///
+ /// Get an archive of a given repository's contents
+ ///
+ /// https://developer.github.com/v3/repos/contents/#get-archive-link
+ /// The owner of the repository
+ /// The name of the repository
+ /// The binary contents of the archive
+ Task GetArchive(string owner, string name);
+
///
/// This method will return a 302 to a URL to download a tarball or zipball archive for a repository.
/// Please make sure your HTTP framework is configured to follow redirects or you will need to use the
@@ -70,8 +81,19 @@ namespace Octokit
/// The name of the repository
/// The format of the archive. Can be either tarball or zipball
///
+ [Obsolete("Use GetArchive to download the archive instead")]
Task GetArchiveLink(string owner, string name, ArchiveFormat archiveFormat);
+ ///
+ /// Get an archive of a given repository's contents, in a specific format
+ ///
+ /// https://developer.github.com/v3/repos/contents/#get-archive-link
+ /// The owner of the repository
+ /// The name of the repository
+ /// The format of the archive. Can be either tarball or zipball
+ /// The binary contents of the archive
+ Task GetArchive(string owner, string name, ArchiveFormat archiveFormat);
+
///
/// This method will return a 302 to a URL to download a tarball or zipball archive for a repository.
/// Please make sure your HTTP framework is configured to follow redirects or you will need to use the
@@ -84,8 +106,20 @@ namespace Octokit
/// The format of the archive. Can be either tarball or zipball
/// A valid Git reference.
///
+ [Obsolete("Use GetArchive to download the archive instead")]
Task GetArchiveLink(string owner, string name, ArchiveFormat archiveFormat, string reference);
+ ///
+ /// Get an archive of a given repository's contents, using a specific format and reference
+ ///
+ /// https://developer.github.com/v3/repos/contents/#get-archive-link
+ /// The owner of the repository
+ /// The name of the repository
+ /// The format of the archive. Can be either tarball or zipball
+ /// A valid Git reference.
+ /// The binary contents of the archive
+ Task GetArchive(string owner, string name, ArchiveFormat archiveFormat, string reference);
+
///
/// Creates a commit that creates a new file in a repository.
///
diff --git a/Octokit/Clients/RepositoryContentsClient.cs b/Octokit/Clients/RepositoryContentsClient.cs
index 7b867f01..5f866caf 100644
--- a/Octokit/Clients/RepositoryContentsClient.cs
+++ b/Octokit/Clients/RepositoryContentsClient.cs
@@ -89,6 +89,18 @@ namespace Octokit
return GetArchiveLink(owner, name, ArchiveFormat.Tarball, string.Empty);
}
+ ///
+ /// Get an archive of a given repository's contents
+ ///
+ /// https://developer.github.com/v3/repos/contents/#get-archive-link
+ /// The owner of the repository
+ /// The name of the repository
+ /// The binary contents of the archive
+ public Task GetArchive(string owner, string name)
+ {
+ return GetArchive(owner, name, ArchiveFormat.Tarball, string.Empty);
+ }
+
///
/// This method will return a 302 to a URL to download a tarball or zipball archive for a repository.
/// Please make sure your HTTP framework is configured to follow redirects or you will need to use the
@@ -105,6 +117,19 @@ namespace Octokit
return GetArchiveLink(owner, name, archiveFormat, string.Empty);
}
+ ///
+ /// Get an archive of a given repository's contents, in a specific format
+ ///
+ /// https://developer.github.com/v3/repos/contents/#get-archive-link
+ /// The owner of the repository
+ /// The name of the repository
+ /// The format of the archive. Can be either tarball or zipball
+ /// The binary contents of the archive
+ public Task GetArchive(string owner, string name, ArchiveFormat archiveFormat)
+ {
+ return GetArchive(owner, name, archiveFormat, string.Empty);
+ }
+
///
/// This method will return a 302 to a URL to download a tarball or zipball archive for a repository.
/// Please make sure your HTTP framework is configured to follow redirects or you will need to use the
@@ -125,6 +150,27 @@ namespace Octokit
return ApiConnection.GetRedirect(ApiUrls.RepositoryArchiveLink(owner, name, archiveFormat, reference));
}
+ ///
+ /// Get an archive of a given repository's contents, using a specific format and reference
+ ///
+ /// https://developer.github.com/v3/repos/contents/#get-archive-link
+ /// The owner of the repository
+ /// The name of the repository
+ /// The format of the archive. Can be either tarball or zipball
+ /// A valid Git reference.
+ /// The binary contents of the archive
+ public async Task GetArchive(string owner, string name, ArchiveFormat archiveFormat, string reference)
+ {
+ Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
+ Ensure.ArgumentNotNullOrEmptyString(name, "name");
+
+ var endpoint = ApiUrls.RepositoryArchiveLink(owner, name, archiveFormat, reference);
+
+ var response = await Connection.Get(endpoint, new Dictionary(), null);
+
+ return response.Body;
+ }
+
///
/// Creates a commit that creates a new file in a repository.
///
diff --git a/Octokit/Http/Connection.cs b/Octokit/Http/Connection.cs
index c8597dad..0488d71d 100644
--- a/Octokit/Http/Connection.cs
+++ b/Octokit/Http/Connection.cs
@@ -153,12 +153,12 @@ namespace Octokit
/// Specifies accepted response media types.
/// To follow redirect links automatically or not
/// representing the received HTTP response
-
+ [Obsolete("allowAutoRedirect is no longer respected and will be deprecated in a future release")]
public Task> Get(Uri uri, IDictionary parameters, string accepts, bool allowAutoRedirect)
{
Ensure.ArgumentNotNull(uri, "uri");
- return SendData(uri.ApplyParameters(parameters), HttpMethod.Get, null, accepts, null, CancellationToken.None, allowAutoRedirect: allowAutoRedirect);
+ return SendData(uri.ApplyParameters(parameters), HttpMethod.Get, null, accepts, null, CancellationToken.None);
}
public Task> Get(Uri uri, IDictionary parameters, string accepts, CancellationToken cancellationToken)
@@ -321,8 +321,7 @@ namespace Octokit
string contentType,
CancellationToken cancellationToken,
string twoFactorAuthenticationCode = null,
- Uri baseAddress = null,
- bool allowAutoRedirect = true)
+ Uri baseAddress = null)
{
Ensure.ArgumentNotNull(uri, "uri");
@@ -331,7 +330,6 @@ namespace Octokit
Method = method,
BaseAddress = baseAddress ?? BaseAddress,
Endpoint = uri,
- AllowAutoRedirect = allowAutoRedirect,
};
return SendDataInternal(body, accepts, contentType, cancellationToken, twoFactorAuthenticationCode, request);
diff --git a/Octokit/Http/HttpClientAdapter.cs b/Octokit/Http/HttpClientAdapter.cs
index 7c45be56..ac364b3a 100644
--- a/Octokit/Http/HttpClientAdapter.cs
+++ b/Octokit/Http/HttpClientAdapter.cs
@@ -77,7 +77,9 @@ namespace Octokit.Internal
contentType = GetContentMediaType(responseMessage.Content);
// We added support for downloading images and zip-files. Let's constrain this appropriately.
- if (contentType != null && (contentType.StartsWith("image/") || contentType.Equals("application/zip", StringComparison.OrdinalIgnoreCase)))
+ if (contentType != null && (contentType.StartsWith("image/")
+ || contentType.Equals("application/zip", StringComparison.OrdinalIgnoreCase)
+ || contentType.Equals("application/x-gzip", StringComparison.OrdinalIgnoreCase)))
{
responseBody = await responseMessage.Content.ReadAsByteArrayAsync().ConfigureAwait(false);
}
@@ -104,7 +106,6 @@ namespace Octokit.Internal
var fullUri = new Uri(request.BaseAddress, request.Endpoint);
requestMessage = new HttpRequestMessage(request.Method, fullUri);
- requestMessage.Properties["AllowAutoRedirect"] = request.AllowAutoRedirect;
foreach (var header in request.Headers)
{
requestMessage.Headers.Add(header.Key, header.Value);
@@ -166,7 +167,6 @@ namespace Octokit.Internal
internal class RedirectHandler : DelegatingHandler
{
- public const string AllowAutoRedirectKey = "AllowAutoRedirect";
public const string RedirectCountKey = "RedirectCount";
public bool Enabled { get; set; }
@@ -177,10 +177,6 @@ namespace Octokit.Internal
// Can't redirect without somewhere to redirect too. Throw?
if (response.Headers.Location == null) return response;
- // Don't redirect if redirection has been disabled for this request
- var allowAutoRedirect = (bool)request.Properties[AllowAutoRedirectKey];
- if (!allowAutoRedirect) return response; // Throw?
-
// Don't redirect if we exceed max number of redirects
var redirectCount = 0;
if (request.Properties.Keys.Contains(RedirectCountKey))
diff --git a/Octokit/Http/IRequest.cs b/Octokit/Http/IRequest.cs
index f52b2e52..31fbc578 100644
--- a/Octokit/Http/IRequest.cs
+++ b/Octokit/Http/IRequest.cs
@@ -14,6 +14,7 @@ namespace Octokit.Internal
Uri Endpoint { get; }
TimeSpan Timeout { get; }
string ContentType { get; }
+ [Obsolete("This value is no longer respected due to the necessary redirect work")]
bool AllowAutoRedirect { get; }
}
}
diff --git a/Octokit/Http/Request.cs b/Octokit/Http/Request.cs
index cd6dad4d..f9300fd4 100644
--- a/Octokit/Http/Request.cs
+++ b/Octokit/Http/Request.cs
@@ -11,7 +11,6 @@ namespace Octokit.Internal
{
Headers = new Dictionary();
Parameters = new Dictionary();
- AllowAutoRedirect = true;
Timeout = TimeSpan.FromSeconds(100);
}
@@ -23,6 +22,8 @@ namespace Octokit.Internal
public Uri Endpoint { get; set; }
public TimeSpan Timeout { get; set; }
public string ContentType { get; set; }
+
+ [Obsolete("This value is no longer respected due to the necessary redirect work")]
public bool AllowAutoRedirect { get; set; }
}
}