Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/GitHub.Api/Application/ApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public async Task<bool> ContinueLoginAsync(LoginResult loginResult, Func<LoginRe
// it'll throw if it's private or an enterprise instance requiring authentication
catch (ApiException apiex)
{
if (!HostAddress.IsGitHubDotComUri(OriginalUrl.ToRepositoryUri()))
if (!HostAddress.IsGitHubDotCom(OriginalUrl.ToRepositoryUri()))
isEnterprise = apiex.IsGitHubApiException();
}
catch {}
Expand Down
2 changes: 1 addition & 1 deletion src/GitHub.Api/Authentication/LoginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ bool EnterpriseWorkaround(UriString hostAddress, Exception e)
// the failure, using basic authentication (with username and password) instead of trying
// to get an authorization token.
var apiException = e as ApiException;
return !HostAddress.IsGitHubDotComUri(hostAddress.ToUri()) &&
return !HostAddress.IsGitHubDotCom(hostAddress) &&
(e is NotFoundException ||
e is ForbiddenException ||
apiException?.StatusCode == (HttpStatusCode)422);
Expand Down
16 changes: 13 additions & 3 deletions src/GitHub.Api/Primitives/HostAddress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class HostAddress
/// <returns></returns>
public static HostAddress Create(Uri hostUri)
{
return IsGitHubDotComUri(hostUri)
return IsGitHubDotCom(hostUri)
? GitHubDotComHostAddress
: new HostAddress(hostUri);
}
Expand Down Expand Up @@ -68,16 +68,26 @@ public HostAddress()
// since that's the same cache key for all the other github.com operations.
public string CredentialCacheKeyHost { get; private set; }

public static bool IsGitHubDotComUri(Uri hostUri)
public static bool IsGitHubDotCom(Uri hostUri)
{
return hostUri.IsSameHost(GitHubDotComHostAddress.WebUri)
|| hostUri.IsSameHost(GitHubDotComHostAddress.ApiUri)
|| hostUri.IsSameHost(gistUri);
}

public static bool IsGitHubDotCom(string url)
{
if (String.IsNullOrEmpty(url))
return false;
Uri uri = null;
if (!Uri.TryCreate(url, UriKind.Absolute, out uri))
return false;
return IsGitHubDotCom(uri);
}

public bool IsGitHubDotCom()
{
return IsGitHubDotComUri(ApiUri);
return IsGitHubDotCom(ApiUri);
}

public string Title
Expand Down