public Task <HttpResponseMessage> Write(ResponseWriterContext context) { var response = new HttpResponseMessage(); var streamInfo = context.Response.As <IStreamInfo>() ?? context .RequestContext.Action.Method.GetAttribute <OutputStreamAttribute>(); var stream = context.Response.As <OutputStream>()?.Stream ?? context.Response as Stream; var bufferSize = streamInfo?.BufferSize ?? _configuration.DownloadBufferSize; if (stream != null) { response.Content = new StreamContent(stream, bufferSize); if (streamInfo != null) { if (streamInfo.ContentType.IsNotNullOrEmpty()) { response.Content.Headers.SetContentType(streamInfo.ContentType); } if (streamInfo.Filename.IsNotNullOrEmpty()) { response.Content.Headers.SetAttachmentDisposition(streamInfo.Filename); } } if (response.Content.Headers.ContentType == null) { response.Content.Headers.SetContentType(MimeTypes.ApplicationOctetStream); } } return(response.ToTaskResult()); }
public virtual bool AppliesTo(ResponseWriterContext context) { var responseType = context.RequestContext.Route.ResponseType?.Type; return(context.RequestContext.Route.HasResponse && (responseType == typeof(OutputStream) || responseType == typeof(Stream))); }
protected override void WriteToStream(ResponseWriterContext context, Stream output) { var streamWriter = output.CreateWriter(_configuration.DefaultEncoding, _configuration.SerializerBufferSize); var writer = System.Xml.XmlWriter.Create(streamWriter, _xmlWriterSettings); new XmlSerializer(context.Response.GetType()) .Serialize(writer, context.Response); }
protected override void WriteToStream(ResponseWriterContext context, Stream output) { var streamWriter = output.CreateWriter(_configuration.DefaultEncoding, _configuration.SerializerBufferSize); var jsonWriter = new JsonTextWriter(streamWriter); _serializer.Serialize(jsonWriter, context.Response); jsonWriter.Flush(); }
public Task <HttpResponseMessage> Write(ResponseWriterContext context) { var response = new HttpResponseMessage(); var data = GetResponse(context); if (data != null) { response.Content = new StringContent(data, _encoding, _mimeType); } return(response.ToTaskResult()); }
public override bool AppliesTo(ResponseWriterContext context) { var responseType = _routeDescriptor.ResponseType?.Type; if (!typeof(IRedirectable).IsAssignableFrom(responseType)) { return(false); } var redirect = context.Response.As <IRedirectable>(); return(redirect.RedirectStatus.HasValue); }
public Task <HttpResponseMessage> Write(ResponseWriterContext context) { var response = new HttpResponseMessage(); var data = context.Response?.ToString(); if (data != null) { response.Content = new StringContent(data, Encoding.UTF8, data.ContainsIgnoreCase("</") ? MimeTypes.TextHtml : MimeTypes.TextPlain); } return(response.ToTaskResult()); }
public Task <HttpResponseMessage> Write(ResponseWriterContext context) { var redirect = context.Response.As <IRedirectable>(); return(new HttpResponseMessage { Headers = { Location = new Uri(redirect.RidirectUrl) }, StatusCode = (HttpStatusCode)redirect.Ridirect }.ToTaskResult()); }
public virtual bool AppliesTo(ResponseWriterContext context) { var responseType = context.RequestContext.Route.ResponseType?.Type; if (!context.RequestContext.Route.HasResponse || !typeof(IRedirectable).IsAssignableFrom(responseType)) { return(false); } var redirect = context.Response.As <IRedirectable>(); return(redirect.Ridirect != RedirectType.None && redirect.RidirectUrl.IsNotNullOrEmpty()); }
public override Task <HttpResponseMessage> WriteResponse(ResponseWriterContext context) { var redirect = context.Response.As <IRedirectable>(); if (redirect.RedirectStatus.HasValue) { _responseMessage.StatusCode = redirect.RedirectStatus.Value; } if (redirect.RedirectUrl.IsNotNullOrEmpty()) { _responseMessage.Headers.Location = new Uri(redirect.RedirectUrl, UriKind.RelativeOrAbsolute); } return(_responseMessage.ToTaskResult()); }
public override Task <HttpResponseMessage> WriteResponse(ResponseWriterContext context) { _responseMessage.Content = GetContent(context); if (_responseMessage.Content != null) { var contentType = _acceptType.Value?.ContentType ?? _mimeTypes.First(); if (contentType.IsNotNullOrEmpty()) { _responseMessage.Content.Headers.ContentType = new MediaTypeHeaderValue(contentType); } } return(_responseMessage.ToTaskResult()); }
protected sealed override HttpContent GetContent(ResponseWriterContext context) { return(new AsyncContent(output => { try { WriteToStream(context, output); } finally { if (_configuration.DisposeSerializedObjects) { context.Response.As <IDisposable>()?.Dispose(); } } return Task.CompletedTask; })); }
public override Task <HttpResponseMessage> WriteResponse(ResponseWriterContext context) { var outputInfo = context.Response.As <TOutputInfo>() ?? _actionMethod.GetAttribute <TAttribute>(); var data = context.Response.As <OutputBody <T> >()?.Data ?? context.Response as T; if (data != null) { _responseMessage.Content = GetContent(data, outputInfo); _responseMessage.Content.Headers.SetContentType( outputInfo?.ContentType ?? GetContentType(data)); if (outputInfo != null && outputInfo.Filename.IsNotNullOrEmpty()) { _responseMessage.Content.Headers.SetAttachmentDisposition(outputInfo.Filename); } } return(_responseMessage.ToTaskResult()); }
public virtual bool AppliesTo(ResponseWriterContext context) { return(context.RequestContext.Route.HasResponse && context .RequestContext.Route.ResponseType.Type == typeof(string)); }
public Task <HttpResponseMessage> Write(ResponseWriterContext context) { return(WriteResponse(context)); }
public abstract Task <HttpResponseMessage> WriteResponse( ResponseWriterContext context);
public virtual bool AppliesTo(ResponseWriterContext context) { return(true); }
protected abstract void WriteToStream(ResponseWriterContext context, Stream output);
protected override string GetResponse(ResponseWriterContext context) { return(JsonConvert.SerializeObject(context.Response, _settings)); }
protected abstract HttpContent GetContent(ResponseWriterContext context);
protected override string GetResponse(ResponseWriterContext context) { return(context.Response.SerializeXml(context .RequestContext.Route.ResponseType.Type)); }
public override bool AppliesTo(ResponseWriterContext context) { return(_acceptType.Value != null); }
public override bool AppliesTo(ResponseWriterContext context) { var responseType = _routeDescriptor.ResponseType?.Type; return(responseType == typeof(TWrapper) || responseType == typeof(T)); }
protected abstract string GetResponse(ResponseWriterContext context);
protected override HttpContent GetContent(ResponseWriterContext context) { return(new AsyncContent(GetResponse(context), _encoding)); }
public virtual bool AppliesTo(ResponseWriterContext context) { return(context.RequestContext.Route.HasResponse && context .RequestContext.RequestMessage.AcceptsMimeType(_mimeType)); }