当前位置: 首页>>代码示例>>C#>>正文


C# IRequest.GetHeader方法代码示例

本文整理汇总了C#中IRequest.GetHeader方法的典型用法代码示例。如果您正苦于以下问题:C# IRequest.GetHeader方法的具体用法?C# IRequest.GetHeader怎么用?C# IRequest.GetHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IRequest的用法示例。


在下文中一共展示了IRequest.GetHeader方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetHeaderValue

 private string GetHeaderValue(string header, IRequest request)
 {
     switch (header) {
         case "(request-target)":
             return request.Method.ToString().ToLower () + " " + request.Path;
         default:
             return request.GetHeader(header);
     }
 }
开发者ID:karlbohlmark,项目名称:http-signatures-csharp,代码行数:9,代码来源:HttpSignatureStringExtractor.cs

示例2: Signature

        public VerifiedSignature Signature(IRequest r, ISignatureSpecification spec, IKeyStore keyStore)
        {
            var authorization = r.GetHeader("authorization");
            if (string.IsNullOrEmpty(authorization)) throw new SignatureMissingException("No authorization header present");

            var signatureAuth = authorizationParser.Parse(authorization);
            if (spec == null) {
                spec = signatureAuth;
            } else {
                if (spec.Algorithm != signatureAuth.Algorithm) {
                    throw new InvalidSignatureException(string.Format("Algorith mismatch. Wanted: {0}, found: {1}", spec.Algorithm, signatureAuth.Algorithm));
                }
                var missingHeaders = spec.Headers.Where(h=> !signatureAuth.Headers.Contains(h)).ToList();
                if (missingHeaders.Any()) {
                    throw new InvalidSignatureException(string.Format("Missing headers in signature: {0}", string.Join(",", missingHeaders)));
                }
            }

            var signature = CalculateSignature(r, spec, keyStore.Get(signatureAuth.KeyId));
            return new VerifiedSignature(signatureAuth, signature);
        }
开发者ID:karlbohlmark,项目名称:http-signatures-csharp,代码行数:21,代码来源:HttpSigner.cs

示例3: AuthorizationFilter

        private void AuthorizationFilter(IRequest request, IResponse response, object requestDto)
        {
#if DEBUG
            if (request.IsLocal)
                return;
#endif

            if (request.PathInfo.StartsWith("/json/reply/Login") || request.PathInfo.StartsWith("/json/reply/Register") || request.PathInfo.StartsWith("/resource"))
                return;

            var claims = JwtTokenGenerator.Instance.GetClaims(request.GetHeader("token"));
            if (claims == null)
                response.ReturnAuthRequired();
            else
            {
                var userName = claims.FindFirst(ClaimTypes.Name).Value;

                var session = this.container.Resolve<IDocumentSession>();
                var user = session.Query<User>().FirstOrDefault(u => u.Username == userName);

                //Set the current user in the request
                request.Items.Add(RequestItem.User, user);
            }
        }
开发者ID:rvhelden,项目名称:SchoolOpdracht,代码行数:24,代码来源:AppHost.cs

示例4: ExtractTokenFromRequestFilter

        public void ExtractTokenFromRequestFilter(IRequest req, IResponse res, object requestDto)
        {
            var auth = req.GetHeader("Authorization");

            if (!String.IsNullOrEmpty(auth) && auth.StartsWith(bearerPrefix) && auth.Length > bearerPrefix.Length)
            {
                SecurityToken loginToken = null;

                try
                {
                    loginToken = tokenManager.ToSecurityToken(auth.Substring(bearerPrefix.Length), "login");
                }
                catch (Exception)
                {
                    throw HttpError.Unauthorized("Login token is invalid");
                }

                // Validate the token is not expired
                if (DateTime.UtcNow > loginToken.ExpiresAtUtc)
                    throw HttpError.Unauthorized("Login token has expired");

                req.SetItem("LoginToken", loginToken);
            }
        }
开发者ID:jlyonsmith,项目名称:ToolBelt,代码行数:24,代码来源:LoginTokenFeature.cs

示例5: ExecuteMessage

        protected Message ExecuteMessage(Message message, RequestAttributes requestAttributes, IRequest httpReq, IResponse httpRes)
        {
            var soapFeature = requestAttributes.ToSoapFeature();
            HostContext.AppHost.AssertFeatures(soapFeature);

            if (httpReq == null)
                httpReq = HostContext.GetCurrentRequest();

            if (httpRes == null && httpReq != null)
                httpRes = httpReq.Response;

            if (httpReq == null)
                throw new ArgumentNullException("httpReq");

            if (httpRes == null)
                throw new ArgumentNullException("httpRes");

            httpReq.UseBufferedStream = true;
            var requestMsg = message ?? GetRequestMessageFromStream(httpReq.InputStream);

            var soapAction = httpReq.GetHeader(HttpHeaders.SOAPAction)
                ?? GetAction(requestMsg);

            if (soapAction != null)
            {
                httpReq.OperationName = soapAction.Trim('"');
            }

            if (HostContext.ApplyPreRequestFilters(httpReq, httpRes))
                return PrepareEmptyResponse(message, httpReq);

            string requestXml = GetRequestXml(requestMsg);
            var requestType = GetRequestType(requestMsg, requestXml);
            httpReq.OperationName = requestType.GetOperationName();
            if (!HostContext.Metadata.CanAccess(requestAttributes, soapFeature.ToFormat(), requestType.GetOperationName()))
                throw HostContext.UnauthorizedAccess(requestAttributes);

            try
            {
                var useXmlSerializerRequest = requestType.HasAttribute<XmlSerializerFormatAttribute>();

                var request = useXmlSerializerRequest
                    ? XmlSerializableSerializer.Instance.DeserializeFromString(requestXml, requestType)
                    : Serialization.DataContractSerializer.Instance.DeserializeFromString(requestXml, requestType);

                httpReq.Dto = request;

                var requiresSoapMessage = request as IRequiresSoapMessage;
                if (requiresSoapMessage != null)
                {
                    requiresSoapMessage.Message = requestMsg;
                }

                httpReq.SetItem("SoapMessage", requestMsg);

                httpRes.ContentType = GetSoapContentType(httpReq.ContentType);

                var hasRequestFilters = HostContext.GlobalRequestFilters.Count > 0
                    || FilterAttributeCache.GetRequestFilterAttributes(request.GetType()).Any();

                if (hasRequestFilters && HostContext.ApplyRequestFilters(httpReq, httpRes, request))
                    return EmptyResponse(requestMsg, requestType);

                httpReq.RequestAttributes |= requestAttributes;
                var response = ExecuteService(request, httpReq);

                var taskResponse = response as Task;
                if (taskResponse != null)
                {
                    taskResponse.Wait();
                    response = TypeAccessor.Create(taskResponse.GetType())[taskResponse, "Result"];
                }

                var hasResponseFilters = HostContext.GlobalResponseFilters.Count > 0
                   || FilterAttributeCache.GetResponseFilterAttributes(response.GetType()).Any();

                if (hasResponseFilters && HostContext.ApplyResponseFilters(httpReq, httpRes, response))
                    return EmptyResponse(requestMsg, requestType);

                var httpResult = response as IHttpResult;
                if (httpResult != null)
                    response = httpResult.Response;

                var noMsgAction = requestMsg.Headers.Action == null;
                var responseMsg = CreateResponseMessage(response, requestMsg.Version, requestType, noMsgAction);

                if (httpResult != null)
                {
                    SetErrorStatusIfAny(httpReq.Response, responseMsg, httpResult.Status);
                }

                return responseMsg;
            }
            catch (Exception ex)
            {
                throw new SerializationException("3) Error trying to deserialize requestType: "
                    + requestType
                    + ", xml body: " + requestXml, ex);
            }
        }
开发者ID:softwx,项目名称:ServiceStack,代码行数:100,代码来源:SoapHandler.cs


注:本文中的IRequest.GetHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。