public Yield ProxyToService(DreamContext context, DreamMessage request, Result<DreamMessage> response) {
            PermissionsBL.IsUserAllowed(DekiContext.Current.User, Permissions.ADMIN);

            //Private feature requires api-key
            var identifier = context.GetParam("id");
            ServiceRepository.IServiceInfo serviceInfo = null;
            if(identifier.StartsWith("=")) {
                serviceInfo = DekiContext.Current.Instance.RunningServices[XUri.Decode(identifier.Substring(1))];
            } else {
                uint serviceId;
                if(uint.TryParse(identifier, out serviceId)) {
                    serviceInfo = DekiContext.Current.Instance.RunningServices[serviceId];
                } else {
                    throw new DreamBadRequestException(string.Format("Invalid id '{0}'", identifier));
                }
            }
            if(serviceInfo == null) {
                response.Return(DreamMessage.NotFound(string.Format(DekiResources.SERVICE_NOT_FOUND, identifier)));
                yield break;
            }
            var proxyUri = serviceInfo.ServiceUri.At(context.GetSuffixes(UriPathFormat.Original).Skip(1).ToArray());

            yield return context.Relay(Plug.New(proxyUri), request, response);
        }
示例#2
0
 public Yield GetHttp(DreamContext context, DreamMessage request, Result<DreamMessage> response)
 {
     yield return context.Relay(_redirect.At(context.GetSuffixes(UriPathFormat.Original)), request, response);
 }
 public Yield GetImage(DreamContext context, DreamMessage request, Result<DreamMessage> response) {
     string image = context.GetParam("name");
     if(Path.GetExtension(image) != ".png") {
         response.Return(DreamMessage.NotFound("image not found"));
     } else {
         yield return context.Relay(Storage.At(image), request, response);
     }
 }
示例#4
0
 public Yield GetImage(DreamContext context, DreamMessage request, Result<DreamMessage> response) {
     yield return context.Relay(Storage.At(context.GetParam("name")), request, response);
 }
示例#5
0
 public Yield GetFiles(DreamContext context, DreamMessage request, Result<DreamMessage> response) {
     if(_resourcesUri != null) {
         yield return context.Relay(Plug.New(_resourcesUri).AtPath(string.Join("/", context.GetSuffixes(UriPathFormat.Original))), request, response);
     } else {
         response.Return(GetFile(context));
     }
     yield break;
 }
示例#6
0
 public Yield GetErrorXsl(DreamContext context, DreamMessage request, Result<DreamMessage> response)
 {
     string resource = context.GetParam("resource");
     Plug plug = Plug.New(string.Format("resource://mindtouch.core/MindTouch.Dream.resources.host.{0}", resource)).With(DreamOutParam.TYPE, MimeType.FromFileExtension(resource).FullType);
     yield return context.Relay(plug, request, response);
 }
 public Yield home(DreamContext context) {
     yield return context.Relay(_fs.At("metl.html"), "GET:", null, null);
 }
示例#8
0
 public Yield PostUnsubscribeEvents(DreamContext context, DreamMessage request, Result<DreamMessage> response)
 {
     yield return context.Relay(_events.At("unsubscribe"), request, response);
 }
示例#9
0
 public Yield FeatureGetAuthenticate(DreamContext context, DreamMessage request, Result<DreamMessage> response) {
     string user = Authenticate(context, request);
     
     string password;
     HttpUtil.GetAuthentication(context.Uri.ToUri(), request.Headers, out user, out password);
     yield return context.Relay(Self.At("users", XUri.Encode(user)).WithCredentials(user, password), request, response);
 }