public NetHttpServiceRespone(OutgoingWebResponseContext response, out Stream stream)
 {
     stream = new MemoryStream();
     this.stream = stream;
     this.writer = new StreamWriter(stream); 
     this.response = response;
 }
Пример #2
0
        private static void SetNancyResponseToOutgoingWebResponse(OutgoingWebResponseContext webResponse, Response nancyResponse)
        {
            SetHttpResponseHeaders(webResponse, nancyResponse);

            webResponse.ContentType = nancyResponse.ContentType;
            webResponse.StatusCode = nancyResponse.StatusCode;
        }
Пример #3
0
 public static void CheckModifiedSince(IncomingWebRequestContext incomingRequest, OutgoingWebResponseContext outgoingResponse, DateTime serverModifiedDate) 
 { 
     DateTime modifiedSince = Convert.ToDateTime(incomingRequest.Headers[HttpRequestHeader.LastModified]); 
     if (modifiedSince != serverModifiedDate) 
         return; 
     outgoingResponse.SuppressEntityBody = true; 
     outgoingResponse.StatusCode = HttpStatusCode.NotModified; 
 }
        public OutgoingWebResponseContextWrapper(OutgoingWebResponseContext outgoingResponse)
        {
            if (outgoingResponse == null)
            {
                throw new ArgumentNullException("outgoingResponse");
            }

            this.outgoingResponse = outgoingResponse;
        }
Пример #5
0
 public static void CheckETag(IncomingWebRequestContext incomingRequest, OutgoingWebResponseContext outgoingResponse, Guid ServerETag) 
 { 
     string test = incomingRequest.Headers[HttpRequestHeader.IfNoneMatch]; 
     if (test == null)   
         return; 
     Guid? eTag = new Guid(test); 
     if (eTag != ServerETag) return; 
     outgoingResponse.SuppressEntityBody = true; 
     outgoingResponse.StatusCode = HttpStatusCode.NotModified; 
 }  
 private static void SetHeader(OutgoingWebResponseContext response, string headerName, string headerValue)
 {
     if (string.IsNullOrWhiteSpace(response.Headers.Get(headerName)))
     {
         response.Headers.Add(headerName, headerValue);
     }
     else
     {
         response.Headers.Set(headerName, headerValue);
     }
 }
Пример #7
0
 private static void SetHttpResponseHeaders(OutgoingWebResponseContext context, Response response)
 {
     foreach (var kvp in response.Headers)
     {
         context.Headers.Add(kvp.Key, kvp.Value);
     }
     foreach (var cookie in response.Cookies)
     {
         context.Headers.Add("Set-Cookie", cookie.ToString());
     }
 }
 public IIdentity Authenticate(
     IncomingWebRequestContext request,
     OutgoingWebResponseContext response,
     object[] parameters,
     UserNamePasswordValidator validator,
     bool secure,
     bool requiresTransportLayerSecurity,
     string source)
 {
     if (requiresTransportLayerSecurity && !secure)
         throw new BasicRequiresTransportSecurityException();
     var authentication = new BasicAuthentication(request.Headers);
     if (!authentication.Authenticate(validator))
         throw new BasicUnauthorizedException(source);
     return new GenericIdentity(authentication.Username, "WebBasicAuthenticationHandler");
 }
Пример #9
0
        /// <summary>
        /// Authenticates the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="response">The response.</param>
        /// <param name="parameters">The parameters.</param>
        /// <param name="secure">if set to <c>true</c> [secure].</param>
        /// <param name="requiresTransportLayerSecurity">if set to <c>true</c> [requires transport layer security].</param>
        /// <param name="scope">The scope.</param>
        /// <returns></returns>
        public IIdentity Authenticate(IncomingWebRequestContext request, OutgoingWebResponseContext response, object[] parameters, bool secure, bool requiresTransportLayerSecurity, string scope, bool allowAnonymous)
        {
            var clientProvider = new ClientProvider();
              var passwordProvider = new PasswordProvider();
              var tokenProvider = new TokenProvider();
              var scopes = new List<string>();

              var oAuthProvider = OAuthFactory.BuildOAuthProvider(clientProvider, tokenProvider, scopes, passwordProvider: passwordProvider);

              var token = request.Headers["Authorization"];
              if (string.IsNullOrWhiteSpace(token))
              {
            token = HttpContext.Current.Request.QueryString["access_token"];
              }
              else
              {
            if (!string.IsNullOrWhiteSpace(token) && token.StartsWith("OAuth") && token.Contains(" "))
            {
              var splitToken = token.Split(' ');
              if (splitToken.Length > 1)
              {
            token = splitToken[1];
              }
            }
              }

              var authentication = oAuthProvider.VerifyToken(token, scope);
              if (authentication.ErrorCode != ErrorCode.None)
              {
            if (allowAnonymous)
            {
              return null;
            }

            var errorCode = authentication.StatusCode();
            var oauthError = authentication.Error();
            if (errorCode == HttpStatusCode.Unauthorized)
            {
              response.Headers.Add(HttpResponseHeader.WwwAuthenticate, string.Format("OAuth realm='PollMe Service', error='{0}'", oauthError));
            }

            throw new WebFaultException<string>(oauthError, authentication.StatusCode());
              }

              return new GenericIdentity("Authorized User", "OAuth2");
        }
 public IIdentity Authenticate(
     IncomingWebRequestContext request,
     OutgoingWebResponseContext response,
     object[] parameters,
     Type validatorType,
     bool secure,
     bool requiresTransportLayerSecurity,
     string source)
 {
     if (requiresTransportLayerSecurity && !secure)
         throw new BasicRequiresTransportSecurityException();
     var authentication = new BasicAuthentication(request.Headers);
     var validator = validatorType != null
         ? DependencyResolver.Current.GetOperationService<UserNamePasswordValidator>(OperationContainer.GetCurrent(), validatorType)
         : DependencyResolver.Current.GetOperationService<UserNamePasswordValidator>(OperationContainer.GetCurrent()).ThrowIfNull();
     if (!authentication.Authenticate(validator))
         throw new BasicUnauthorizedException(source);
     return new GenericIdentity(authentication.Username, "WebBasicAuthenticationHandler");
 }
        private IAsyncResult DispatchToHttpServer(
            IncomingWebRequestContext incomingRequest, 
            Stream body,
            OutgoingWebResponseContext outgoingResponse, 
            bool bufferBody,
            AsyncCallback callback, 
            object state)
        {
            var request = MakeHttpRequestMessageFrom(incomingRequest, body, bufferBody);
            var tcs = new TaskCompletionSource<Stream>(state);
            _server.SubmitRequestAsync(request, new CancellationToken())
                .ContinueWith(t =>
                {
                    var response = t.Result;
                    CopyHttpResponseMessageToOutgoingResponse(response, outgoingResponse);
                    Action<Task<Stream>> complete = (t2) =>
                    {
                        if (t2.IsFaulted)
                            tcs.TrySetException(
                                t2.Exception.InnerExceptions);
                        else if (t2.IsCanceled) tcs.TrySetCanceled();
                        else tcs.TrySetResult(t2.Result);

                        if (callback != null) callback(tcs.Task);
                    };

                    if (response.Content == null)
                    {
                        tcs.TrySetResult(null);
                        if (callback != null) callback(tcs.Task);
                    }
                    else
                    {
                        response.Content.ReadAsStreamAsync()
                            .ContinueWith(complete);
                    }
                });
            return tcs.Task;
        }
Пример #12
0
        private static void SetNancyResponseToOutgoingWebResponse(OutgoingWebResponseContext webResponse, Response nancyResponse)
        {
            SetHttpResponseHeaders(webResponse, nancyResponse);

            if (nancyResponse.ContentType != null)
            {
                webResponse.ContentType = nancyResponse.ContentType;
            }
            webResponse.StatusCode = (System.Net.HttpStatusCode)nancyResponse.StatusCode;
        }
Пример #13
0
 public oEmbedWriter(OutgoingWebResponseContext response)
 {
     _response = response;
 }
 private void SetCacheHeaders(OutgoingWebResponseContext response)
 {
     response.ContentType = "image/png";
     response.Headers[HttpResponseHeader.CacheControl] = "public";
     response.LastModified = new DateTime(1900, 1, 1);
     response.Headers[HttpResponseHeader.Expires] = (DateTime.Now + Settings.ClientCacheMaxAge).ToUniversalTime().ToString("ddd, dd MMM yyyy HH:mm:ss 'GMT'");
 }
Пример #15
0
		public OutgoingWebResponseContextWrapper(OutgoingWebResponseContext context)
		{
			this.context = context;
		}
 private static void CopyHttpResponseMessageToOutgoingResponse(HttpResponseMessage response,
                                                               OutgoingWebResponseContext outgoingResponse)
 {
     outgoingResponse.StatusCode = response.StatusCode;
     outgoingResponse.StatusDescription = response.ReasonPhrase;
     if (response.Content == null) outgoingResponse.SuppressEntityBody = true;
     foreach (var kvp in response.Headers)
     {
         foreach (var value in kvp.Value)
         {
             outgoingResponse.Headers.Add(kvp.Key, value);
         }
     }
     if (response.Content != null)
     {
         foreach (var kvp in response.Content.Headers)
         {
             foreach (var value in kvp.Value)
             {
                 outgoingResponse.Headers.Add(kvp.Key, value);
             }
         }
     }
 }
Пример #17
0
 private static void SetNancyResponseToOutgoingResponse(OutgoingWebResponseContext resp, Response response)
 {
     resp.ContentType = response.ContentType;
     resp.StatusCode = response.StatusCode;
 }
 private void Respond(OutgoingWebResponseContext responseContext, HttpResponseMessage responseMessage)
 {
     responseContext.StatusCode = responseMessage.StatusCode;
     responseContext.SuppressEntityBody = true;
     foreach (var header in responseMessage.Headers)
     {
         responseContext.Headers[header.Key] = header.Value.First();
     }
 }
		/// <summary>
		/// Submits this response to a WCF response context.  Only available when no response body is included.
		/// </summary>
		/// <param name="responseContext">The response context to apply the response to.</param>
		public virtual void Respond(OutgoingWebResponseContext responseContext) {
			Requires.NotNull(responseContext, "responseContext");
			if (this.ResponseStream != null) {
				throw new NotSupportedException(Strings.ResponseBodyNotSupported);
			}

			responseContext.StatusCode = this.Status;
			responseContext.SuppressEntityBody = true;
			foreach (string header in this.Headers) {
				responseContext.Headers[header] = this.Headers[header];
			}
		}
 public OutgoingWebResponseContextWrapper(OutgoingWebResponseContext context)
 {
     this.context = context;
 }
 private void CopyOwinContextToOutgoingResponse(OwinContext owinContext, OutgoingWebResponseContext outgoingResponse)
 {
     outgoingResponse.StatusCode = (HttpStatusCode)owinContext.Response.StatusCode;
     foreach (var h in owinContext.Response.Headers)
     {
         outgoingResponse.Headers.Add(h.Key, owinContext.Response.Headers[h.Key]); // TODO remove double lookup
     }
 }
Пример #22
0
 public PortalService()
 {
     request = WebOperationContext.Current.IncomingRequest;
     response = WebOperationContext.Current.OutgoingResponse;
 }
        public void CheckConditionalRetrieve(long entityTag)
        {
            string validEtag = OutgoingWebResponseContext.GenerateValidEtag(entityTag);

            CheckConditionalRetrieveWithValidatedEtag(validEtag);
        }
        public void CheckConditionalUpdate(Guid entityTag)
        {
            string validEtag = OutgoingWebResponseContext.GenerateValidEtag(entityTag);

            CheckConditionalUpdateWithValidatedEtag(validEtag);
        }
Пример #25
0
 private static void SetNancyResponseToOutgoingWebResponse(OutgoingWebResponseContext webResponse, Response nancyResponse)
 {
     webResponse.ContentType = nancyResponse.ContentType;
     webResponse.StatusCode = nancyResponse.StatusCode;
 }