g(Encoding encoding)
{
Decoder decoder = encoding.GetDecoder();
StringBuilder sb = new StringBuilder();
BytesNode tempNode = this;
while (tempNode != null)
{
char[] chars = new char[decoder.GetCharCount(tempNode.Value, tempNode.Start, tempNode.Length)];
decoder.GetChars(tempNode.Value, tempNode.Start,
tempNode.Length, chars, 0);
sb.Append(chars);
tempNode = tempNode.Next;
}
return sb.ToString();
}
}
HttpMessage?宸戦燕幣匯倖渇?議Http?連?茅阻**根?連遊??連悶吉奉來翌?珊減夭兜兵晒?連 遊?盾裂?連悶海業?鳩範?連頁Request,Response吉孔嬬。
public class HttpMessage
{
public const string PROTOCOL = "HTTP";
public const string CONTENT_LENGTH_HEADER = "Content-Length";
public MessageType MessageType = MessageType.UnKnow;
public BytesNode BodyStr;
public int ContentLength;
public Dictionary<string, string> Headers = new Dictionary<string, string>();
internal BytesNode HeaderStr;
public string Protocol;
private string startLine;
public object SyncRoot = new object(); //todo:壙扮短喘
public HttpMessage()
{
}
public HttpMessage(HttpMessage message)
{
startLine = message.startLine;
Headers = message.Headers;
BodyStr = message.BodyStr;
}
internal void InitHeaders(List<BytesLine> lines)
{
if (MessageType == MessageType.UnKnow)
{
#region 盾裂MessageType,ContentLength式野割?連遊
for (int i = 0; i < lines.Count; i++)
{
BytesLine line = lines[i];
if (i == 0)
{
string tempStr = line.FullString;
MessageType = tempStr.StartsWith(PROTOCOL)
?
MessageType.Response
: MessageType.Request;
startLine = tempStr;
continue;
}
if (line.Pos1 == -1) throw new ApplicationException("header line error:"
+ line.FullString);
|