void ParseContentBody() { if (!pendingHead) { if (currentMessage.ContentLength > 0) { long lenghtToRead = streamInner.Length - streamInner.Position; if (lenghtToRead > 0) { if (currentMessage.Body == null) { currentMessage.CreateBody(); } long pendingToRead = currentMessage.ContentLength - currentMessage.Body.Length; if (lenghtToRead > pendingToRead) { lenghtToRead = pendingToRead; } long oldLength = currentMessage.Body.Length; Streams.CopyToEnd(streamInner, currentMessage.Body, lenghtToRead); currentRead += lenghtToRead; if (currentMessage.Body.Length >= currentMessage.ContentLength) { if (currentMessage.TransferEncoding == TransferEncodings.CHUNKED) { pendingChunkedContentSize = true; } else { ResetPendingComplete(); } } if (currentMessage.IsCompleted && currentMessage.ContentType == HttpConst.FormUrlEncoded) { currentMessage.Form = HttpUtility.ParseQueryString(currentMessage.Body.GetPlainText(), currentMessage.ContentTransferEncoding); } } } else if (currentMessage.TransferEncoding != TransferEncodings.CHUNKED) { currentMessage.IsCompleted = true; firstField = true; pendingHead = true; } } }
public override IHttpMessage Serialize() { IHttpMessage ret = null; if (Payload is OverlayRequest) { var tmp = new HttpRequest() { Host = Destiny.ToString() }; ret = (HttpRequest)tmp; } else if (Payload is OverlayReply) { var tmp = new HttpReply(); ret = (HttpReply)tmp; } // head ret.Url = Payload.GetType().FullName; ret.AddField(new HttpField(HttpConst.MessageSource, Source)); ret.AddField(new HttpField(HttpConst.MessageDestiny, Destiny)); ret.AddField(new HttpField(HttpConst.MessagePath, Path)); ret.AddField(new HttpField(HttpConst.MessageHops, Hops)); // body ret.CreateBody(); ret.Body.CreateStream(); if (Payload != null) { var formatter = new BinaryFormatter(); formatter.Serialize(ret.Body.ContentStream, Payload); ret.Body.ContentType = HttpConst.ContentTypeDodoNetObject; } else { ret.Body.ContentType = ""; } return(ret); }