public static WopiRequest Parse(HttpContext context)
        {
            var segments = context.Request.Path.Value.ToLowerInvariant()
                           .Split(new [] { '/' }, StringSplitOptions.RemoveEmptyEntries);

            var webRequest    = context.Request;
            var headers       = webRequest.Headers;
            var httpMethod    = webRequest.Method;
            var xWopiOverride = headers[WopiHeader.Override].FirstOrDefault();
            var requestStream = webRequest.Body;
            var accessToken   = webRequest.Query[AccessTokenParamName].FirstOrDefault();

            WopiRequest request;

            try
            {
                request = Parse(segments, httpMethod, xWopiOverride, headers, requestStream);
            }
            catch (Exception e)
            {
                request = new BadRequest(e);
            }

            request.AccessTokenValue = accessToken;
            return(request);
        }
Beispiel #2
0
        public static WopiRequest Parse(string wopiPath, PortalContext portalContext)
        {
            if (!portalContext.IsWopiRequest)
            {
                throw new InvalidOperationException("The Request is not a WOPI request.");
            }

            var segments = wopiPath.ToLowerInvariant().Split('/');

            var ownerContext  = portalContext.OwnerHttpContext;
            var webRequest    = ownerContext.Request;
            var headers       = webRequest.Headers;
            var httpMethod    = webRequest.HttpMethod;
            var xWopiOverride = headers[WopiHeader.Override];
            var requestStream = webRequest.InputStream;
            var accessToken   = webRequest.QueryString[AccessTokenParamName];

            WopiRequest request;

            try
            {
                request = Parse(segments, httpMethod, xWopiOverride, headers, requestStream);
            }
            catch (Exception e)
            {
                request = new BadRequest(e);
            }

            request.AccessTokenValue = accessToken;
            return(request);
        }