public Request ReadBody(IAppSocket socket, Request req) { if (!req.ContainsHeader("Content-Length")) { return(req); } var contentLength = int.Parse(req.GetHeader("Content-Length").Value); var(bytesRead, readByteCount) = socket.Receive(contentLength); var body = Encoding.UTF8.GetString(bytesRead); return(new Request(req, body)); }
public byte[] ReadSocket(IAppSocket socket) { var bytesToReturn = new byte[0]; while (!Encoding.UTF8.GetString(bytesToReturn).Contains("\r\n\r\n")) { var(bytesRead, readByteCount) = socket.Receive(1); Array.Resize(ref bytesToReturn, bytesToReturn.Length + readByteCount); bytesToReturn[bytesToReturn.Length - readByteCount] = bytesRead[0]; } return(bytesToReturn); }
private string retrieveData(IAppSocket appSocket) { var bufferText = ""; var receivedData = new byte[0]; while (bufferText.IndexOf("\n") == -1) { var(data, dataLength) = appSocket.Receive(1); var originalLength = receivedData.Length; Array.Resize(ref receivedData, originalLength + dataLength); Array.Copy(data, 0, receivedData, originalLength, dataLength); bufferText = Encoding.ASCII.GetString(receivedData, 0, receivedData.Length); } _optionalLogger?.Info($"Got Data: {bufferText}"); return(bufferText); }