public static ReadVariableInt ( Stream Stream ) : int | ||
Stream | Stream | |
return | int |
public static int ReadVariableInt(Stream Stream)
{
// FastCGI transmits a name-value pair as the length of the name, followed by the length of the value, followed by the name, followed by the value.
// Lengths of 127 bytes and less can be encoded in one byte, while longer lengths are always encoded in four bytes:
int Byte = Stream.ReadByte();
if (Byte < 0) throw (new Exception("Can't ready more bytes"));
if ((Byte & 0x80) != 0)
{
return (
(Byte & 0x7F ) << 24 |
Stream.ReadByte() << 16 |
Stream.ReadByte() << 8 |
Stream.ReadByte() << 0
);
}
else
{
return Byte;
}
}
public void ParseParamsStream() { Params = new Dictionary <string, string>(); ParamsStream.Position = 0; while (!ParamsStream.Eof()) { var Key = new byte[FastcgiPacketReader.ReadVariableInt(ParamsStream)]; var Value = new byte[FastcgiPacketReader.ReadVariableInt(ParamsStream)]; ParamsStream.Read(Key, 0, Key.Length); ParamsStream.Read(Value, 0, Value.Length); Params[Encoding.ASCII.GetString(Key)] = Encoding.ASCII.GetString(Value); } ParamsStream = new FascgiRequestInputStream(); }