本文整理汇总了C#中Request.Get方法的典型用法代码示例。如果您正苦于以下问题:C# Request.Get方法的具体用法?C# Request.Get怎么用?C# Request.Get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Request
的用法示例。
在下文中一共展示了Request.Get方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Middleware
public static AppFunc Middleware(AppFunc app)
{
return env =>
{
var request = new Request(env);
string opaqueSupport = request.Get<string>("opaque.Support");
OpaqueUpgrade opaqueUpgrade = request.Get<OpaqueUpgrade>("opaque.Upgrade");
string websocketSupport = request.Get<string>("websocket.Support");
WebSocketAccept webSocketAccept = request.Get<WebSocketAccept>("websocket.Accept");
if (opaqueSupport == "opaque.Upgrade" // If we have opaque support
&& opaqueUpgrade != null
&& websocketSupport != "websocket.Accept" // and no current websocket support
&& webSocketAccept == null) // and this request is a websocket request...
{
// This middleware is adding support for websockets.
env["websocket.Support"] = "websocket.Accept";
if (IsWebSocketRequest(env))
{
IDictionary<string, object> acceptOptions = null;
WebSocketFunc webSocketFunc = null;
// Announce websocket support
env["websocket.Accept"] = new WebSocketAccept(
(options, callback) =>
{
acceptOptions = options;
webSocketFunc = callback;
env[OwinConstants.ResponseStatusCode] = 101;
});
return app(env).Then(() =>
{
Response response = new Response(env);
if (response.StatusCode == 101
&& webSocketFunc != null)
{
SetWebSocketResponseHeaders(env, acceptOptions);
opaqueUpgrade(acceptOptions, opaqueEnv =>
{
WebSocketLayer webSocket = new WebSocketLayer(opaqueEnv);
return webSocketFunc(webSocket.Environment)
.Then(() => webSocket.CleanupAsync());
});
}
});
}
}
// else
return app(env);
};
}
示例2: CheckRequiredCallData
private static bool CheckRequiredCallData(IDictionary<string, object> env, IList<string> warnings)
{
var req = new Request(env);
string[] requiredKeys = new string[]
{
"owin.Version",
"owin.CallCancelled",
"owin.RequestBody",
"owin.RequestHeaders",
"owin.RequestMethod",
"owin.RequestPath",
"owin.RequestPathBase",
"owin.RequestProtocol",
"owin.RequestQueryString",
"owin.RequestScheme",
"owin.ResponseHeaders",
"owin.ResponseBody",
};
object temp;
foreach (string key in requiredKeys)
{
if (!env.TryGetValue(key, out temp))
{
SetFatalResult(env, "3.2", "Missing required Environment key: " + key);
return false;
}
if (temp == null)
{
SetFatalResult(env, "3.2", "Required Environment value is null: " + key);
return false;
}
}
IDictionary<string, string[]> requestHeaders = req.Get<IDictionary<string, string[]>>("owin.RequestHeaders");
IDictionary<string, string[]> responseHeaders = req.Get<IDictionary<string, string[]>>("owin.ResponseHeaders");
if (!TryValidateHeaderCollection(env, requestHeaders, "Request", warnings))
{
return false;
}
if (!TryValidateHeaderCollection(env, responseHeaders, "Response", warnings))
{
return false;
}
string[] header;
if (!requestHeaders.TryGetValue("HOST", out header) || header.Length == 0)
{
SetFatalResult(env, "5.2", "Missing Host header");
return false;
}
// Validate values
string[] stringValueTypes = new string[]
{
"owin.RequestMethod",
"owin.RequestPath",
"owin.RequestPathBase",
"owin.RequestProtocol",
"owin.RequestQueryString",
"owin.RequestScheme",
"owin.Version"
};
foreach (string key in stringValueTypes)
{
if (!(env[key] is string))
{
SetFatalResult(env, "3.2", key + " value is not of type string: " + env[key].GetType().FullName);
return false;
}
}
if (!(env["owin.CallCancelled"] is CancellationToken))
{
SetFatalResult(env, "3.2.3", "owin.CallCancelled is not of type CancellationToken: " + env["owin.CallCancelled"].GetType().FullName);
return false;
}
if (req.Get<CancellationToken>("owin.CallCancelled").IsCancellationRequested)
{
warnings.Add(CreateWarning("3.6", "The owin.CallCancelled CancellationToken was cancelled before processing the request."));
}
if (string.IsNullOrWhiteSpace(req.Get<string>("owin.RequestMethod")))
{
SetFatalResult(env, "3.2.1", "owin.RequestMethod is empty.");
return false;
}
string pathBase = req.Get<string>("owin.RequestPathBase");
if (pathBase.EndsWith("/"))
{
SetFatalResult(env, "5.3", "owin.RequestBasePath ends with a slash: " + pathBase);
//.........这里部分代码省略.........
示例3: TryValidateCall
// Returns false for fatal errors, along with a resulting message.
// Otherwise any warnings are appended.
private static bool TryValidateCall(IDictionary<string, object> env, IList<string> warnings)
{
if (env == null)
{
throw new ArgumentNullException("env");
}
var req = new Request(env);
// Must be mutable
try
{
string key = "validator.MutableKey";
string input = "Mutable Value";
req.Set(key, input);
string output = req.Get<string>(key);
if (output == null || output != input)
{
SetFatalResult(env, "3.2", "Environment is not fully mutable.");
return false;
}
req.Set<string>(key, null);
}
catch (Exception ex)
{
SetFatalResult(env, "3.2", "Environment is not mutable: \r\n" + ex.ToString());
return false;
}
// Environment key names MUST be case sensitive.
string upperKey = "Validator.CaseKey";
string lowerKey = "validator.casekey";
string[] caseValue = new string[] { "Case Value" };
env[upperKey] = caseValue;
string[] resultValue = req.Get<string[]>(lowerKey);
if (resultValue != null)
{
SetFatalResult(env, "3.2", "Environment is not case sensitive.");
return false;
}
env.Remove(upperKey);
// Check for required owin.* keys and the HOST header.
if (!CheckRequiredCallData(env, warnings))
{
return false;
}
return true;
}
示例4: Instantiate
public object Instantiate(Request request)
{
var resolver = (IResolver)request.Get(resolverType);
return resolver.Instantiate(request);
}