public static bool WriteToOutputStream(IResponse response, object result, byte[] bodyPrefix, byte[] bodySuffix) { if (HostContext.Config.AllowPartialResponses && result is IPartialWriter partialResult && partialResult.IsPartialRequest) { response.AllowSyncIO(); partialResult.WritePartialTo(response); return(true); } if (result is IStreamWriter streamWriter) { response.AllowSyncIO(); if (bodyPrefix != null) { response.OutputStream.Write(bodyPrefix, 0, bodyPrefix.Length); } streamWriter.WriteTo(response.OutputStream); if (bodySuffix != null) { response.OutputStream.Write(bodySuffix, 0, bodySuffix.Length); } return(true); } return(false); }
public static void Write(this IResponse response, string contents) { #if !NETSTANDARD2_0 if (response is Host.AspNet.AspNetResponse aspRes) { aspRes.Response.Write(contents); return; } #endif if (contents == null) { response.SetContentLength(0); response.EndRequest(); return; } //retain behavior with ASP.NET's response.Write(string) if (response.ContentType?.IndexOf(';') == -1) { response.ContentType += ContentFormat.Utf8Suffix; } var bytes = contents.ToUtf8Bytes(); response.SetContentLength(bytes.Length); response.AllowSyncIO().OutputStream.Write(bytes, 0, bytes.Length); }
public override async Task ProcessRequestAsync(IRequest httpReq, IResponse httpRes, string operationName) { if (HostContext.ApplyCustomHandlerRequestFilters(httpReq, httpRes)) { return; } if (!AssertAccess(httpReq, httpRes, httpReq.QueryString["op"])) { return; } if (httpReq.QueryString["xsd"] != null) { #if !NETSTANDARD2_0 var operationTypes = HostContext.Metadata.GetAllSoapOperationTypes(); var xsdNo = Convert.ToInt32(httpReq.QueryString["xsd"]); var schemaSet = XsdUtils.GetXmlSchemaSet(operationTypes); var schemas = schemaSet.Schemas(); var i = 0; if (xsdNo >= schemas.Count) { throw new ArgumentOutOfRangeException("xsd"); } httpRes.ContentType = "text/xml"; foreach (XmlSchema schema in schemaSet.Schemas()) { if (xsdNo != i++) { continue; } schema.Write(httpRes.AllowSyncIO().OutputStream); break; } #endif } else { httpRes.ContentType = "text/html; charset=utf-8"; await ProcessOperationsAsync(httpRes.OutputStream, httpReq, httpRes); } await httpRes.EndHttpHandlerRequestAsync(skipHeaders : true); }