Skip to content

Commit 29e86a0

Browse files
committed
Add ToAbsoluteUri() to generate Uri's from typed IReturn Request DTO's
1 parent 63841f0 commit 29e86a0

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

src/ServiceStack.Common/Web/ContentType.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,9 @@ public static string GetContentFormat(Format format)
186186

187187
public static string GetContentFormat(string contentType)
188188
{
189-
if (contentType == null) return contentType;
189+
if (contentType == null)
190+
return null;
191+
190192
var parts = contentType.Split('/');
191193
return parts[parts.Length - 1];
192194
}

src/ServiceStack/HttpExtensions.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
using System.Net;
22
using System.Web;
3+
using ServiceStack.Common;
4+
using ServiceStack.Common.Web;
5+
using ServiceStack.ServiceClient.Web;
36
using ServiceStack.ServiceHost;
7+
using ServiceStack.WebHost.Endpoints;
48
using ServiceStack.WebHost.Endpoints.Extensions;
59

610
namespace ServiceStack
@@ -22,5 +26,16 @@ public static HttpRequestContext ToRequestContext(this HttpListenerContext httpC
2226
httpContext.Response.ToResponse(),
2327
requestDto);
2428
}
29+
30+
public static string ToAbsoluteUri(this IReturn request, string httpMethod = null, string formatFallbackToPredefinedRoute = null)
31+
{
32+
var relativeUrl = request.ToUrl(
33+
httpMethod ?? HttpMethods.Get,
34+
formatFallbackToPredefinedRoute ?? EndpointHost.Config.DefaultContentType.ToContentFormat());
35+
36+
var absoluteUrl = EndpointHost.Config.WebHostUrl.CombineWith(relativeUrl);
37+
return absoluteUrl;
38+
}
39+
2540
}
2641
}

0 commit comments

Comments
 (0)