public ChunkedInputStream(HttpListenerContext context, Stream stream, byte[] buffer, int offset, int length) : base(stream, buffer, offset, length) { this.context = context; WebHeaderCollection headers = (WebHeaderCollection)context.Request.Headers; this.decoder = new ChunkStream(headers); }
internal ChunkedRequestStream( Stream stream, byte[] buffer, int offset, int count, HttpListenerContext context) : base(stream, buffer, offset, count) { _context = context; _decoder = new ChunkStream((WebHeaderCollection)context.Request.Headers); }
internal ChunkedRequestStream ( Stream stream, byte[] buffer, int offset, int count, HttpListenerContext context) : base (stream, buffer, offset, count) { _context = context; _decoder = new ChunkStream ((WebHeaderCollection) context.Request.Headers); }
public ChunkedRequestStream ( HttpListenerContext context, Stream stream, byte [] buffer, int offset, int length) : base (stream, buffer, offset, length) { _context = context; _decoder = new ChunkStream ((WebHeaderCollection) context.Request.Headers); }
public ChunkedRequestStream( HttpListenerContext context, Stream stream, byte [] buffer, int offset, int length) : base(stream, buffer, offset, length) { _context = context; _decoder = new ChunkStream((WebHeaderCollection)context.Request.Headers); }
private InputChunkState seekCrLf(byte[] buffer, ref int offset, int length) { int num; InputChunkState inputChunkState; if (!this._sawCr) { num = offset; offset = num + 1; if (buffer[num] != 13) { ChunkStream.throwProtocolViolation("CR is expected."); } this._sawCr = true; if (offset == length) { inputChunkState = InputChunkState.DataEnded; return(inputChunkState); } } num = offset; offset = num + 1; if (buffer[num] != 10) { ChunkStream.throwProtocolViolation("LF is expected."); } inputChunkState = InputChunkState.None; return(inputChunkState); }
public ChunkedInputStream( HttpListenerContext context, Stream stream, byte [] buffer, int offset, int length) : base(stream, buffer, offset, length) { this.context = context; WebHeaderCollection coll = (WebHeaderCollection) context.Request.Headers; decoder = new ChunkStream (coll); }
private ChunkStream.State ReadTrailer(byte[] buffer, ref int offset, int size) { if (this.trailerState == 2 && (ushort)buffer[offset] == 13 && this.saved.Length == 0) { offset++; if (offset < size && (ushort)buffer[offset] == 10) { offset++; return(ChunkStream.State.None); } offset--; } int num = this.trailerState; string text = "\r\n\r"; while (offset < size && num < 4) { char c = (char)buffer[offset++]; if ((num == 0 || num == 2) && c == '\r') { num++; } else if ((num == 1 || num == 3) && c == '\n') { num++; } else if (num > 0) { this.saved.Append(text.Substring(0, (this.saved.Length != 0) ? num : (num - 2))); num = 0; if (this.saved.Length > 4196) { ChunkStream.ThrowProtocolViolation("Error reading trailer (too long)."); } } } if (num < 4) { this.trailerState = num; if (offset < size) { ChunkStream.ThrowProtocolViolation("Error reading trailer."); } return(ChunkStream.State.Trailer); } StringReader stringReader = new StringReader(this.saved.ToString()); string text2; while ((text2 = stringReader.ReadLine()) != null && text2 != "") { this.headers.Add(text2); } return(ChunkStream.State.None); }
private void write(byte[] buffer, ref int offset, int length) { if (this._state == InputChunkState.End) { ChunkStream.throwProtocolViolation("The chunks were ended."); } if (this._state == InputChunkState.None) { this._state = this.setChunkSize(buffer, ref offset, length); if (this._state == InputChunkState.None) { return; } this._saved.Length = 0; this._sawCr = false; this._gotIt = false; } if ((this._state != InputChunkState.Data ? false : offset < length)) { this._state = this.writeData(buffer, ref offset, length); if (this._state == InputChunkState.Data) { return; } } if ((this._state != InputChunkState.DataEnded ? false : offset < length)) { this._state = this.seekCrLf(buffer, ref offset, length); if (this._state == InputChunkState.DataEnded) { return; } this._sawCr = false; } if ((this._state != InputChunkState.Trailer ? false : offset < length)) { this._state = this.setTrailer(buffer, ref offset, length); if (this._state == InputChunkState.Trailer) { return; } this._saved.Length = 0; } if (offset < length) { this.write(buffer, ref offset, length); } }
private ChunkStream.State ReadCRLF(byte[] buffer, ref int offset, int size) { if (!this.sawCR) { if ((ushort)buffer[offset++] != 13) { ChunkStream.ThrowProtocolViolation("Expecting \\r."); } this.sawCR = true; if (offset == size) { return(ChunkStream.State.BodyFinished); } } if (this.sawCR && (ushort)buffer[offset++] != 10) { ChunkStream.ThrowProtocolViolation("Expecting \\n."); } return(ChunkStream.State.None); }
private ChunkStream.State GetChunkSize(byte[] buffer, ref int offset, int size) { char c = '\0'; while (offset < size) { c = (char)buffer[offset++]; if (c == '\r') { if (this.sawCR) { ChunkStream.ThrowProtocolViolation("2 CR found."); } this.sawCR = true; } else { if (this.sawCR && c == '\n') { break; } if (c == ' ') { this.gotit = true; } if (!this.gotit) { this.saved.Append(c); } if (this.saved.Length > 20) { ChunkStream.ThrowProtocolViolation("Chunk size too long."); } } } if (!this.sawCR || c != '\n') { if (offset < size) { ChunkStream.ThrowProtocolViolation("Missing \\n."); } try { if (this.saved.Length > 0) { this.chunkSize = int.Parse(ChunkStream.RemoveChunkExtension(this.saved.ToString()), NumberStyles.HexNumber); } } catch (Exception) { ChunkStream.ThrowProtocolViolation("Cannot parse chunk size."); } return(ChunkStream.State.None); } this.chunkRead = 0; try { this.chunkSize = int.Parse(ChunkStream.RemoveChunkExtension(this.saved.ToString()), NumberStyles.HexNumber); } catch (Exception) { ChunkStream.ThrowProtocolViolation("Cannot parse chunk size."); } if (this.chunkSize == 0) { this.trailerState = 2; return(ChunkStream.State.Trailer); } return(ChunkStream.State.Body); }
private InputChunkState setTrailer(byte[] buffer, ref int offset, int length) { InputChunkState inputChunkState; if ((this._trailerState != 2 || buffer[offset] != 13 ? false : this._saved.Length == 0)) { offset++; if ((offset >= length ? false : buffer[offset] == 10)) { offset++; inputChunkState = InputChunkState.End; return(inputChunkState); } offset--; } while (true) { if ((offset >= length ? true : this._trailerState >= 4)) { break; } int num = offset; offset = num + 1; byte num1 = buffer[num]; this._saved.Append((char)num1); if (this._saved.Length > 4196) { ChunkStream.throwProtocolViolation("The trailer is too long."); } if ((this._trailerState == 1 ? true : this._trailerState == 3)) { if (num1 != 10) { ChunkStream.throwProtocolViolation("LF is expected."); } this._trailerState++; } else if (num1 != 13) { if (num1 == 10) { ChunkStream.throwProtocolViolation("LF is unexpected."); } this._trailerState = 0; } else { this._trailerState++; } } if (this._trailerState >= 4) { StringBuilder stringBuilder = this._saved; stringBuilder.Length = stringBuilder.Length - 2; StringReader stringReader = new StringReader(this._saved.ToString()); while (true) { string str = stringReader.ReadLine(); string str1 = str; if ((str == null ? true : str1.Length <= 0)) { break; } this._headers.Add(str1); } inputChunkState = InputChunkState.End; } else { inputChunkState = InputChunkState.Trailer; } return(inputChunkState); }
private InputChunkState setChunkSize(byte[] buffer, ref int offset, int length) { InputChunkState inputChunkState; byte num = 0; while (offset < length) { int num1 = offset; offset = num1 + 1; num = buffer[num1]; if (this._sawCr) { if (num != 10) { ChunkStream.throwProtocolViolation("LF is expected."); } break; } else if (num != 13) { if (num == 10) { ChunkStream.throwProtocolViolation("LF is unexpected."); } if (num == 32) { this._gotIt = true; } if (!this._gotIt) { this._saved.Append((char)num); } if (this._saved.Length > 20) { ChunkStream.throwProtocolViolation("The chunk size is too long."); } } else { this._sawCr = true; } } if ((!this._sawCr ? false : num == 10)) { this._chunkRead = 0; try { this._chunkSize = int.Parse(ChunkStream.removeChunkExtension(this._saved.ToString()), NumberStyles.HexNumber); } catch { ChunkStream.throwProtocolViolation("The chunk size cannot be parsed."); } if (this._chunkSize != 0) { inputChunkState = InputChunkState.Data; } else { this._trailerState = 2; inputChunkState = InputChunkState.Trailer; } } else { inputChunkState = InputChunkState.None; } return(inputChunkState); }