本文整理汇总了C#中IRequest类的典型用法代码示例。如果您正苦于以下问题:C# IRequest类的具体用法?C# IRequest怎么用?C# IRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IRequest类属于命名空间,在下文中一共展示了IRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RequestFilter
public static void RequestFilter(IRequest req, IResponse res, object requestDto)
{
var validator = ValidatorCache.GetValidator(req, requestDto.GetType());
if (validator == null) return;
var validatorWithHttpRequest = validator as IRequiresRequest;
if (validatorWithHttpRequest != null)
validatorWithHttpRequest.Request = req;
var ruleSet = req.Verb;
var validationResult = validator.Validate(
new ValidationContext(requestDto, null, new MultiRuleSetValidatorSelector(ruleSet)));
if (validationResult.IsValid) return;
var errorResponse = DtoUtils.CreateErrorResponse(
requestDto, validationResult.ToErrorResult());
var validationFeature = HostContext.GetPlugin<ValidationFeature>();
if (validationFeature != null && validationFeature.ErrorResponseFilter != null)
{
errorResponse = validationFeature.ErrorResponseFilter(validationResult, errorResponse);
}
res.WriteToResponse(req, errorResponse);
}
示例2: ProcessRequest
public override void ProcessRequest(IRequest httpReq, IResponse httpRes, string operationName)
{
HostContext.ApplyCustomHandlerRequestFilters(httpReq, httpRes);
if (httpRes.IsClosed) return;
httpRes.ContentType = MimeTypes.Html;
if (RazorFormat == null)
RazorFormat = RazorFormat.Instance;
var contentPage = RazorPage ?? RazorFormat.FindByPathInfo(PathInfo);
if (contentPage == null)
{
httpRes.StatusCode = (int)HttpStatusCode.NotFound;
httpRes.EndHttpHandlerRequest();
return;
}
var model = Model;
if (model == null)
httpReq.Items.TryGetValue("Model", out model);
if (model == null)
{
var modelType = RazorPage != null ? RazorPage.ModelType : null;
model = modelType == null || modelType == typeof(DynamicRequestObject)
? null
: DeserializeHttpRequest(modelType, httpReq, httpReq.ContentType);
}
RazorFormat.ProcessRazorPage(httpReq, contentPage, model, httpRes);
}
示例3: RequestEntityReaderHydrator
public RequestEntityReaderHydrator(IDependencyResolver resolver, IRequest request)
{
this.Log = NullLogger<CodecLogSource>.Instance;
this.ErrorCollector = NullErrorCollector.Instance;
this.resolver = resolver;
this.request = request;
}
示例4: OnConnected
protected override Task OnConnected(IRequest request, string connectionId)
{
// Should throw 404
using (HttpWebRequest.Create("http://httpstat.us/404").GetResponse()) { }
return base.OnConnected(request, connectionId);
}
示例5: ProcessRequestAsync
public override Task ProcessRequestAsync(IRequest httpReq, IResponse httpRes, string operationName)
{
try
{
var appHost = HostContext.AppHost;
if (appHost.ApplyPreRequestFilters(httpReq, httpRes))
return EmptyTask;
var restPath = GetRestPath(httpReq.Verb, httpReq.PathInfo);
if (restPath == null)
{
return new NotSupportedException("No RestPath found for: " + httpReq.Verb + " " + httpReq.PathInfo)
.AsTaskException();
}
httpReq.SetRoute(restPath as RestPath);
operationName = restPath.RequestType.GetOperationName();
var callback = httpReq.GetJsonpCallback();
var doJsonp = HostContext.Config.AllowJsonpRequests
&& !string.IsNullOrEmpty(callback);
if (ResponseContentType != null)
httpReq.ResponseContentType = ResponseContentType;
var responseContentType = httpReq.ResponseContentType;
appHost.AssertContentType(responseContentType);
var request = httpReq.Dto = CreateRequest(httpReq, restPath);
if (appHost.ApplyRequestFilters(httpReq, httpRes, request))
return EmptyTask;
var rawResponse = GetResponse(httpReq, request);
return HandleResponse(rawResponse, response =>
{
response = appHost.ApplyResponseConverters(httpReq, response);
if (appHost.ApplyResponseFilters(httpReq, httpRes, response))
return EmptyTask;
if (responseContentType.Contains("jsv") && !string.IsNullOrEmpty(httpReq.QueryString[Keywords.Debug]))
return WriteDebugResponse(httpRes, response);
if (doJsonp && !(response is CompressedResult))
return httpRes.WriteToResponse(httpReq, response, (callback + "(").ToUtf8Bytes(), ")".ToUtf8Bytes());
return httpRes.WriteToResponse(httpReq, response);
},
ex => !HostContext.Config.WriteErrorsToResponse
? ex.ApplyResponseConverters(httpReq).AsTaskException()
: HandleException(httpReq, httpRes, operationName, ex.ApplyResponseConverters(httpReq)));
}
catch (Exception ex)
{
return !HostContext.Config.WriteErrorsToResponse
? ex.ApplyResponseConverters(httpReq).AsTaskException()
: HandleException(httpReq, httpRes, operationName, ex.ApplyResponseConverters(httpReq));
}
}
示例6: Uri
CefReturnValue IRequestHandler.OnBeforeResourceLoad(IWebBrowser browserControl, IBrowser browser, IFrame frame,
IRequest request, IRequestCallback callback) {
if (CommonUrls.IsWithSixUrl(request.Url)) {
var headers = request.Headers;
headers[Common.ClientHeader] = DomainEvilGlobal.SecretData.UserInfo.ClientId.ToString();
headers[Common.ClientHeaderV] = Common.App.ProductVersion;
request.Headers = headers;
}
return CefReturnValue.Continue;
//Example of how to set Referer
// Same should work when setting any header
// For this example only set Referer when using our custom scheme
var url = new Uri(request.Url);
if (url.Scheme == "customscheme") // CefSharpSchemeHandlerFactory.SchemeName
{
var headers = request.Headers;
headers["Referer"] = "http://google.com";
request.Headers = headers;
}
//NOTE: If you do not wish to implement this method returning false is the default behaviour
// We also suggest you explicitly Dispose of the callback as it wraps an unmanaged resource.
//callback.Dispose();
//return false;
//NOTE: When executing the callback in an async fashion need to check to see if it's disposed
if (!callback.IsDisposed) {
using (callback) {
if (request.Method == "POST") {
using (var postData = request.PostData) {
if (postData != null) {
var elements = postData.Elements;
var charSet = request.GetCharSet();
foreach (var element in elements) {
if (element.Type == PostDataElementType.Bytes) {
var body = element.GetBody(charSet);
}
}
}
}
}
//Note to Redirect simply set the request Url
//if (request.Url.StartsWith("https://www.google.com", StringComparison.OrdinalIgnoreCase))
//{
// request.Url = "https://github.com/";
//}
//Callback in async fashion
//callback.Continue(true);
//return CefReturnValue.ContinueAsync;
}
}
return CefReturnValue.Continue;
}
示例7: HttpResponseStreamWrapper
public HttpResponseStreamWrapper(Stream stream, IRequest request)
{
this.OutputStream = stream;
this.Request = request;
this.Headers = new Dictionary<string, string>();
this.Items = new Dictionary<string, object>();
}
示例8: OnConnectedAsync
OnConnectedAsync(IRequest request, string connectionId)
{
_userCount += 1;
Debug.WriteLine("OnConnectedAsync " + _userCount);
this.Connection.Broadcast(_userCount);
return base.OnConnectedAsync(request, connectionId);
}
示例9: using
CefReturnValue IRequestHandler.OnBeforeResourceLoad(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IRequestCallback callback)
{
using (callback)
{
if (request.Method == "POST")
{
using (var postData = request.PostData)
{
var elements = postData.Elements;
var charSet = request.GetCharSet();
foreach (var element in elements)
{
if (element.Type == PostDataElementType.Bytes)
{
var body = element.GetBody(charSet);
}
}
}
}
//Note to Redirect simply set the request Url
//if (request.Url.StartsWith("https://www.google.com", StringComparison.OrdinalIgnoreCase))
//{
// request.Url = "https://github.com/";
//}
//Callback in async fashion
//callback.Continue(true);
//return CefReturnValue.ContinueAsync;
}
return CefReturnValue.Continue;
}
示例10: Log
public override void Log(IRequest request, object requestDto, object response, TimeSpan requestDuration)
{
var requestType = requestDto != null ? requestDto.GetType() : null;
if (ExcludeRequestType(requestType))
return;
using (var redis = redisManager.GetClient())
{
var redisLogEntry = redis.As<RequestLogEntry>();
var entry = CreateEntry(request, requestDto, response, requestDuration, requestType);
entry.Id = redisLogEntry.GetNextSequence();
var key = UrnId.Create<RequestLogEntry>(entry.Id).ToLower();
var nowScore = DateTime.UtcNow.ToUnixTime();
using (var trans = redis.CreateTransaction())
{
trans.QueueCommand(r => r.AddItemToSortedSet(SortedSetKey, key, nowScore));
trans.QueueCommand(r => r.Store(entry));
if (loggerCapacity != null)
{
trans.QueueCommand(r => r.RemoveRangeFromSortedSet(SortedSetKey, 0, -loggerCapacity.Value - 1));
}
trans.Commit();
}
}
}
示例11: OnReceived
protected override Task OnReceived(IRequest request, string connectionId, string data)
{
ProcessInfo process;
data = data ?? String.Empty;
var shell = request.QueryString != null ? request.QueryString["shell"] : String.Empty;
if (!_processes.TryGetValue(connectionId, out process) || process.Process.HasExited)
{
process = _processes.AddOrUpdate(connectionId, cId => StartProcess(cId, shell), (s, p) => StartProcess(s, shell));
}
else
{
if (data == "\x3")
{
// If the user hit CTRL+C we sent the ^C character "\x3" from the client
// If the data is just ^C we then attach to the console and generate a CTRL_C signal (SIGINT)
CommandsNativeMethods.SetConsoleCtrlHandler(null, true);
CommandsNativeMethods.AttachConsole((uint)process.Process.Id);
CommandsNativeMethods.GenerateConsoleCtrlEvent(CommandsNativeMethods.ConsoleCtrlEvent.CTRL_C, 0);
Thread.Sleep(_cmdWaitTimeSpan);
CommandsNativeMethods.FreeConsole();
CommandsNativeMethods.SetConsoleCtrlHandler(null, false);
}
else
{
//Both cmd.exe and powershell.exe are okay with either \r\n or \n for end-of-line.
process.Process.StandardInput.Write(data);
process.Process.StandardInput.Flush();
}
process.LastInputTime = DateTime.UtcNow;
}
return base.OnReceived(request, connectionId, data);
}
示例12: WriteRequestBody
private void WriteRequestBody(IRequest request)
{
lock (thisLock)
{
File.WriteAllText(Environment.GetEnvironmentVariable("directory") + request.Resource, request.Body);
}
}
示例13: Execute
public override void Execute(IRequest req, IResponse res, object requestDto)
{
var authErrorMessage = "";
try
{
// Perform security check
if (CanExecute(req))
return;
}
catch (System.Exception ex)
{
authErrorMessage = ex.Message;
var message = string.Format("Blocked unauthorized request: {0} {1} by ip = {2} due to {3}",
req.Verb,
req.AbsoluteUri,
req.UserHostAddress ?? "unknown",
authErrorMessage);
Log.Error(message);
}
// Security failed!
var responseMessage = "You are not authorized. " + authErrorMessage;
res.StatusCode = (int)HttpStatusCode.Unauthorized;
res.StatusDescription = responseMessage;
res.AddHeader(HttpHeaders.WwwAuthenticate, string.Format("{0} realm=\"{1}\"", "", "custom api"));
res.ContentType = "text/plain";
res.Write(responseMessage);
res.Close();
}
示例14: PrettyPrintEndpoint
internal static string PrettyPrintEndpoint(IRequest request, string endpoint)
{
var pretty = ReplaceParams.Replace(endpoint, (m) =>
{
var key = m.Groups[1].Value.ToLowerInvariant();
switch(key)
{
case "index" : return PrettyParam(key, request.RouteValues.Index);
case "name" : return PrettyParam(key, request.RouteValues.Name);
case "feature" : return PrettyParam(key, request.RouteValues.Feature);
case "field" : return PrettyParam(key, request.RouteValues.Field);
case "fields" : return PrettyParam(key, request.RouteValues.Fields);
case "id" : return PrettyParam(key, request.RouteValues.Id);
case "index_metric" : return PrettyParam(key, request.RouteValues.IndexMetric);
case "lang" : return PrettyParam(key, request.RouteValues.Lang);
case "metric" : return PrettyParam(key, request.RouteValues.Metric);
case "node_id" : return PrettyParam(key, request.RouteValues.NodeId);
case "repository" : return PrettyParam(key, request.RouteValues.Repository);
case "scroll_id" : return PrettyParam(key, request.RouteValues.ScrollId);
case "snapshot" : return PrettyParam(key, request.RouteValues.Snapshot);
case "type" : return PrettyParam(key, request.RouteValues.Type);
default: return PrettyParam(key, "<Unknown route variable>");
}
});
return pretty;
}
示例15: RenderOperation
protected override void RenderOperation(System.Web.UI.HtmlTextWriter writer, IRequest httpReq, string operationName, string requestMessage, string responseMessage, string metadataHtml)
{
var operationControl = new Soap11OperationControl
{
HttpRequest = httpReq,
MetadataConfig = HostContext.Config.ServiceEndpointsMetadataConfig,
Title = HostContext.ServiceName,
Format = this.Format,
OperationName = operationName,
HostName = httpReq.GetUrlHostName(),
RequestMessage = requestMessage,
ResponseMessage = responseMessage,
MetadataHtml = metadataHtml,
};
if (!this.ContentType.IsNullOrEmpty())
{
operationControl.ContentType = this.ContentType;
}
if (!this.ContentFormat.IsNullOrEmpty())
{
operationControl.ContentFormat = this.ContentFormat;
}
operationControl.Render(writer);
}