public ByteString ReadLine() { ByteString line = null; for (int i = _pos; i < _bytes.Length; i++) { if (_bytes[i] == (byte)'\n') { int len = i - _pos; if (len > 0 && _bytes[i - 1] == (byte)'\r') { len--; } line = new ByteString(_bytes, _pos, len); _pos = i + 1; return line; } } if (_pos < _bytes.Length) { line = new ByteString(_bytes, _pos, _bytes.Length - _pos); } _pos = _bytes.Length; return line; }
public ByteString ReadLine() { ByteString str = null; for (int i = this._pos; i < this._bytes.Length; i++) { if (this._bytes[i] == 10) { int length = i - this._pos; if ((length > 0) && (this._bytes[i - 1] == 13)) { length--; } str = new ByteString(this._bytes, this._pos, length); this._pos = i + 1; return str; } } if (this._pos < this._bytes.Length) { str = new ByteString(this._bytes, this._pos, this._bytes.Length - this._pos); } this._pos = this._bytes.Length; return str; }
public ByteString[] Split(char sep) { int index; ArrayList list = new ArrayList(); int offset = 0; while (offset < this._length) { index = this.IndexOf(sep, offset); if (index < 0) { break; } list.Add(this.Substring(offset, index - offset)); offset = index + 1; while ((this[offset] == ((byte) sep)) && (offset < this._length)) { offset++; } } if (offset < this._length) { list.Add(this.Substring(offset)); } int count = list.Count; ByteString[] strArray = new ByteString[count]; for (index = 0; index < count; index++) { strArray[index] = (ByteString) list[index]; } return strArray; }
public ByteString[] Split(char sep) { ArrayList list = new ArrayList(); int pos = 0; while (pos < _length) { int i = IndexOf(sep, pos); if (i < 0) { break; } list.Add(Substring(pos, i-pos)); pos = i+1; while (this[pos] == (byte)sep && pos < _length) { pos++; } } if (pos < _length) { list.Add(Substring(pos)); } int n = list.Count; ByteString[] result = new ByteString[n]; for (int i = 0; i < n; i++) { result[i] = (ByteString)list[i]; } return result; }
private void ParseRequestLine() { ByteString requestLine = (ByteString)_headerByteStrings[0]; ByteString[] elems = requestLine.Split(' '); if (elems == null || elems.Length < 2 || elems.Length > 3) { _connection.WriteErrorAndClose(400); return; } _verb = elems[0].GetString(); ByteString urlBytes = elems[1]; _url = urlBytes.GetString(); if (elems.Length == 3) { _prot = elems[2].GetString(); } else { _prot = "HTTP/1.0"; } // query string int iqs = urlBytes.IndexOf('?'); if (iqs > 0) { _queryStringBytes = urlBytes.Substring(iqs + 1).GetBytes(); } else { _queryStringBytes = new byte[0]; } iqs = _url.IndexOf('?'); if (iqs > 0) { _path = _url.Substring(0, iqs); _queryString = _url.Substring(iqs + 1); } else { _path = _url; _queryStringBytes = new byte[0]; } // url-decode path if (_path.IndexOf('%') >= 0) { _path = HttpUtility.UrlDecode(_path, Encoding.UTF8); iqs = _url.IndexOf('?'); if (iqs >= 0) { _url = _path + _url.Substring(iqs); } else { _url = _path; } } // path info int lastDot = _path.LastIndexOf('.'); int lastSlh = _path.LastIndexOf('/'); if (lastDot >= 0 && lastSlh >= 0 && lastDot < lastSlh) { int ipi = _path.IndexOf('/', lastDot); _filePath = _path.Substring(0, ipi); _pathInfo = _path.Substring(ipi); } else { _filePath = _path; _pathInfo = String.Empty; } _pathTranslated = MapPath(_filePath); }
private bool TryReadAllHeaders() { // read the first packet (up to 32K) byte[] headerBytes = _connection.ReadRequestBytes(maxHeaderBytes); if (headerBytes == null || headerBytes.Length == 0) { return(false); } if (_headerBytes != null) { // previous partial read int len = headerBytes.Length + _headerBytes.Length; if (len > maxHeaderBytes) { return(false); } byte[] bytes = new byte[len]; Buffer.BlockCopy(_headerBytes, 0, bytes, 0, _headerBytes.Length); Buffer.BlockCopy(headerBytes, 0, bytes, _headerBytes.Length, headerBytes.Length); _headerBytes = bytes; } else { _headerBytes = headerBytes; } // start parsing _startHeadersOffset = -1; _endHeadersOffset = -1; _headerByteStrings = new ArrayList(); // find the end of headers ByteParser parser = new ByteParser(_headerBytes); for (;;) { ByteString line = parser.ReadLine(); if (line == null) { break; } if (_startHeadersOffset < 0) { _startHeadersOffset = parser.CurrentOffset; } if (line.IsEmpty) { _endHeadersOffset = parser.CurrentOffset; break; } _headerByteStrings.Add(line); } return(true); }