void ProcessHtmlPostBody(int readpos, Internal.RecvIO recvIO) { //parse body int transferedBytes = recvIO.BytesTransferred; int remaining = transferedBytes - readpos; if (!IsMsgBodyComplete) { int wantBytes = ContentLength - contentByteCount; if (wantBytes <= remaining) { //complete here byte[] buff = new byte[wantBytes]; recvIO.CopyTo(readpos, buff, wantBytes); //add to req AddMsgBody(buff, 0, wantBytes); //complete this.parseState = HttpParsingState.Complete; return; } else { //continue read if (remaining > 0) { byte[] buff = new byte[remaining]; recvIO.CopyTo(readpos, buff, remaining); //add to req AddMsgBody(buff, 0, remaining); } return; } } this.parseState = HttpParsingState.Complete; }
int ParseHttpRequestHeader(Internal.RecvIO recvIO) { //start from pos0 int readpos = 0; int lim = recvIO.BytesTransferred - 1; int i = 0; for (; i <= lim; ++i) { //just read if (recvIO.ReadByte(i) == '\r' && recvIO.ReadByte(i + 1) == '\n') { //each line //translate if (i - readpos < 512) { //copy recvIO.CopyTo(readpos, tmpReadBuffer, i - readpos); //translate string line = Encoding.UTF8.GetString(tmpReadBuffer, 0, i - readpos); readpos = i + 2; i++; //skip \n //translate header *** if (line == "") { //complete http header parseState = HttpParsingState.Body; return(readpos); } else { //parse header line AddReqHeader(line); } } else { //just skip? //skip too long line readpos = i + 2; i++; //skip \n } } } return(readpos); }