Skip to content

Commit

Permalink
Merge pull request #58 from syskill/misc-fixes
Browse files Browse the repository at this point in the history
Misc fixes
  • Loading branch information
Dynalon authored Jan 2, 2017
2 parents c2e18b5 + 3a16791 commit de698f9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Rainy/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ private static void ComposeObjectGraph(Funq.Container container)
return handler;
});
*/
AddDummyUserIfRequired (container);
if (config.Development == true)
AddDummyUserIfRequired (container);
}

}
Expand Down
3 changes: 1 addition & 2 deletions Rainy/WebService/ApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public object Get (ApiRequest request)

Logger.Debug ("ApiRequest received");
var response = new DTO.ApiResponse ();
var baseUri = ((HttpListenerRequest)this.Request.OriginalRequest).Url;
string baseUrl = baseUri.Scheme + "://" + baseUri.Authority + "/";
string baseUrl = ((HttpListenerRequest)this.Request.OriginalRequest).GetBaseUrl ();

// should only be set if authenticated
response.UserRef = new DTO.ContentRef () {
Expand Down
18 changes: 18 additions & 0 deletions Rainy/WebService/Common.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Net;
using System.Linq;
using DevDefined.OAuth.Storage.Basic;
using Rainy.Db;
using ServiceStack;
Expand Down Expand Up @@ -188,4 +189,21 @@ protected IUser requestingUser {
}
}
}


public static class BaseUrlMapper
{
public static string GetBaseUrl (this HttpListenerRequest request)
{
string scheme =
request.Headers.AllKeys.Contains ("X-Forwarded-Proto") ?
request.Headers["X-Forwarded-Proto"] :
request.Url.Scheme;
string authority =
request.Headers.AllKeys.Contains ("X-Forwarded-Host") ?
request.Headers["X-Forwarded-Host"] :
request.Url.Authority;
return scheme + "://" + authority + "/";
}
}
}
3 changes: 1 addition & 2 deletions Rainy/WebService/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public UserService (IDataBackend backend, IDbConnectionFactory factory) : base (
public object Get (UserRequest request)
{
var u = new DTO.UserResponse ();
var baseUri = ((HttpListenerRequest)this.Request.OriginalRequest).Url;
string baseUrl = baseUri.Scheme + "://" + baseUri.Authority + "/";
string baseUrl = ((HttpListenerRequest)this.Request.OriginalRequest).GetBaseUrl ();

u.Username = request.Username;
u.Firstname = "Not";
Expand Down

0 comments on commit de698f9

Please sign in to comment.