public void Execute() { NetworkStream responseStream = currentClient.GetStream(); EnsureResponseStream(responseStream); string payload = string.Empty; if (serializerOptions != null) { payload = JsonSerializer.Serialize(dataTransferObject, dataTransferObject.GetType(), serializerOptions); } else { payload = JsonSerializer.Serialize(dataTransferObject, dataTransferObject.GetType()); } HttpResponseHeader responseHeader = new HttpResponseHeader(HttpStatusCode.OK, payload?.Length ?? 0, "Json"); responseHeader.AddRange(tempHeaderEntries); byte[] responseHeaderBytes = Encoding.UTF8.GetBytes(responseHeader.ToString()); responseStream.Write(responseHeaderBytes); byte[] responseMessageBytes = Encoding.UTF8.GetBytes(payload); responseStream.Write(responseMessageBytes); }
public static HttpStatusCodeResult StatusMessage(HttpStatusCode status, TcpClient client, string message) { HttpResponseHeader responseHeader = new HttpResponseHeader(status, message?.Length ?? 0, "text, plain"); return(new HttpStatusCodeResult(client, responseHeader, message)); }
public HttpStatusCodeResult(TcpClient currentClient, HttpResponseHeader responseHeader, string message) : base(currentClient, responseHeader) { this.message = message; }
public HttpStatusCodeResult(TcpClient currentClient, HttpResponseHeader responseHeader) : this(currentClient, responseHeader, null) { }
public HttpActionResult(TcpClient currentClient, HttpResponseHeader responseHeader) { this.currentClient = currentClient ?? throw new ArgumentNullException($"{nameof(currentClient)} cannot be null."); this.responseHeader = responseHeader ?? throw new ArgumentNullException($"{nameof(responseHeader)} cannot be null."); }