Skip to content

Commit

Permalink
refactor InferBaseUrl from /pathinfo to start after protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Mar 14, 2015
1 parent 34bb81f commit e68da6e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/ServiceStack/Auth/AuthProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,8 @@ protected virtual string GetReferrerUrl(IServiceBase authService, IAuthSession s
if (referrerUrl.IsNullOrEmpty()
|| referrerUrl.IndexOf("/auth", StringComparison.OrdinalIgnoreCase) >= 0)
referrerUrl = this.RedirectUrl
?? HttpHandlerFactory.GetBaseUrl()
?? requestUri.Substring(0, requestUri.IndexOf("/", "https://".Length + 1, StringComparison.Ordinal));
?? authService.Request.GetBaseUrl()
?? requestUri.InferBaseUrl();

return referrerUrl;
}
Expand Down
29 changes: 17 additions & 12 deletions src/ServiceStack/HttpRequestExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -706,22 +706,27 @@ public static string GetAbsoluteUrl(this IRequest httpReq, string url)
return url;
}

public static string InferBaseUrl(this string absoluteUri, string fromPathInfo = null)
{
if (fromPathInfo == null)
fromPathInfo = "/" + (HostContext.Config.HandlerFactoryPath ?? "");

if (string.IsNullOrEmpty(absoluteUri))
return null;

var pos = absoluteUri.IndexOf(fromPathInfo, "https://".Length + 1, StringComparison.Ordinal);
return pos >= 0 ? absoluteUri.Substring(0, pos) : absoluteUri;
}

public static string GetBaseUrl(this IRequest httpReq)
{
var baseUrl = HttpHandlerFactory.GetBaseUrl();
if (baseUrl != null) return baseUrl;
if (baseUrl != null)
return baseUrl.NormalizeScheme();

var pathInfo = httpReq.PathInfo;
if (pathInfo != null)
{
var absoluteUri = httpReq.AbsoluteUri;
var pos = absoluteUri.IndexOf(pathInfo, StringComparison.OrdinalIgnoreCase);
if (pos >= 0)
{
baseUrl = absoluteUri.Substring(0, pos);
return baseUrl.NormalizeScheme();
}
}
baseUrl = httpReq.AbsoluteUri.InferBaseUrl(fromPathInfo: httpReq.PathInfo);
if (baseUrl != null)
return baseUrl.NormalizeScheme();

var handlerPath = HostContext.Config.HandlerFactoryPath;

Expand Down
2 changes: 0 additions & 2 deletions tests/CheckWeb/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
</head>
<body>
<h1>Heading</h1>

<p>
Body!
</p>
</body>
</html>

0 comments on commit e68da6e

Please sign in to comment.