本文整理汇总了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);
}
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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);
}
}