本文整理汇总了C#中MindTouch.Dream.Plug.WithHeader方法的典型用法代码示例。如果您正苦于以下问题:C# Plug.WithHeader方法的具体用法?C# Plug.WithHeader怎么用?C# Plug.WithHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MindTouch.Dream.Plug
的用法示例。
在下文中一共展示了Plug.WithHeader方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Invoke
public Yield Invoke(Plug plug, string verb, XUri uri, DreamMessage request, Result<DreamMessage> response)
{
// NOTE (steveb): we convert 'xri://@name/path?params' into 'http://xri.net/@name/path?params'
// prepend segments with authority
List<string> segments = new List<string>();
segments.Add(uri.Authority);
if(uri.Segments != null) {
segments.AddRange(uri.Segments);
}
// build new plug
List<PlugHandler> preHandlers = (plug.PreHandlers != null) ? new List<PlugHandler>(plug.PreHandlers) : null;
List<PlugHandler> postHandlers = (plug.PostHandlers != null) ? new List<PlugHandler>(plug.PostHandlers) : null;
Plug xri = new Plug(new XUri("http", null, null, "xri.net", 80, segments.ToArray(), uri.TrailingSlash, uri.Params, uri.Fragment), plug.Timeout, request.Headers, preHandlers, postHandlers, plug.Credentials, plug.CookieJar, plug.MaxAutoRedirects);
// add 'Accept' header for 'application/xrds+xml' mime-type
if((xri.Headers == null) || (xri.Headers.Accept == null)) {
xri = xri.WithHeader(DreamHeaders.ACCEPT, MimeType.RenderAcceptHeader(MimeType.XRDS));
}
// BUGBUGBUG (steveb): this will probably fail in some cases since we may exit this coroutine before the call has completed!
xri.InvokeEx(verb, request, response);
yield break;
}
示例2: AuthenticateImportUser
private IEnumerator<IYield> AuthenticateImportUser(Plug api, string wikiId, string apikey, Result<Plug> result) {
XDoc settings = null;
yield return api.At("site", "settings").With("apikey", apikey).GetAsync().Set(x => settings = x.ToDocument());
var username = settings["packageupdater/username"].AsText ?? settings["security/admin-user-for-impersonation"].AsText;
string authToken = null;
if(string.IsNullOrEmpty(username)) {
_log.DebugFormat("[{0}] no user in 'packageupdater/username' config key, trying 'admin'", wikiId);
username = "admin";
yield return Coroutine.Invoke(Authenticate, api, username, apikey, new Result<string>()).Set(x => authToken = x);
if(string.IsNullOrEmpty(authToken)) {
_log.DebugFormat("[{0}] 'admin' didn't authenticate, trying 'sysop'", wikiId);
username = "sysop";
}
}
if(string.IsNullOrEmpty(authToken)) {
_log.DebugFormat("[{0}] authenticating as '{1}'", wikiId, username);
yield return Coroutine.Invoke(Authenticate, api, username, apikey, new Result<string>()).Set(x => authToken = x);
}
if(string.IsNullOrEmpty(authToken)) {
throw new UnauthorizedAccessException(string.Format("Unable to authenticate as '{0}'", username));
}
result.Return(api.WithHeader(DekiWikiService.AUTHTOKEN_HEADERNAME, authToken));
}
示例3: SubscribeIndexer
private Yield SubscribeIndexer(Plug pubsubPlug, Result result) {
_log.DebugFormat("subscribing indexer to pubsub {0}", pubsubPlug.Uri.ToString());
var subscriptionSet = new XDoc("subscription-set")
.Elem("uri.owner", Self.Uri)
.Start("subscription")
.Add(DreamCookie.NewSetCookie("service-key", InternalAccessKey, Self.Uri).AsSetCookieDocument)
.Elem("channel", "event://*/deki/pages/noop")
.Elem("channel", "event://*/deki/pages/create")
.Elem("channel", "event://*/deki/pages/move")
.Elem("channel", "event://*/deki/pages/update")
.Elem("channel", "event://*/deki/pages/delete")
.Elem("channel", "event://*/deki/pages/revert")
.Elem("channel", "event://*/deki/pages/rated")
.Elem("channel", "event://*/deki/pages/createalias")
.Elem("channel", "event://*/deki/pages/tags/update")
.Elem("channel", "event://*/deki/pages/dependentschanged/properties/*")
.Elem("channel", "event://*/deki/files/noop")
.Elem("channel", "event://*/deki/files/create")
.Elem("channel", "event://*/deki/files/update")
.Elem("channel", "event://*/deki/files/delete")
.Elem("channel", "event://*/deki/files/move")
.Elem("channel", "event://*/deki/files/restore")
.Elem("channel", "event://*/deki/comments/noop")
.Elem("channel", "event://*/deki/comments/create")
.Elem("channel", "event://*/deki/comments/update")
.Elem("channel", "event://*/deki/comments/delete")
.Elem("channel", "event://*/deki/users/dependentschanged/properties/*")
.Elem("channel", "event://*/deki/users/create")
.Elem("channel", "event://*/deki/users/update")
.Elem("channel", "event://*/deki/users/login")
.Start("recipient")
.Attr("authtoken", _apikey)
.Elem("uri", Self.Uri.At("queue"))
.End()
.End();
if(_usePersistentSubscription) {
var locationKey = StringUtil.ComputeHashString(pubsubPlug.Uri.AsPublicUri().WithoutQuery() + InternalAccessKey);
var accessKey = StringUtil.ComputeHashString(InternalAccessKey);
subscriptionSet.Attr("max-failure-duration", _subscriptionMaxFailureDuration);
pubsubPlug = pubsubPlug.WithHeader("X-Set-Access-Key", accessKey).WithHeader("X-Set-Location-Key", locationKey);
}
DreamMessage subscription = null;
yield return pubsubPlug.At("subscribers").PostAsync(subscriptionSet).Set(x => subscription = x);
// only care about created responses, but log other failures
switch(subscription.Status) {
case DreamStatus.Created: {
var accessKey = subscription.ToDocument()["access-key"].AsText;
var location = subscription.Headers.Location;
Cookies.Update(DreamCookie.NewSetCookie("access-key", accessKey, location), null);
_subscriptionLocation = location.AsLocalUri().WithoutQuery();
_log.DebugFormat("subscribed indexer for events at {0}", _subscriptionLocation);
break;
}
case DreamStatus.Conflict:
_log.DebugFormat("didn't subscribe, since we already had a subscription in place");
break;
default:
_log.WarnFormat("subscribe to {0} failed: {1}", pubsubPlug.Uri.ToString(), subscription.Status);
break;
}
result.Return();
}