public void WriteStatus(Status aStatus, EVersion aVersion) { iWriter.Write(Http.ByteArray(Http.Version(aVersion))); iWriter.WriteSpace(); iWriter.WriteUint(aStatus.Code); iWriter.WriteSpace(); iWriter.Write(Http.ByteArray(aStatus.Reason)); iWriter.WriteNewline(); }
public void Read() { iReader.ReadFlush(); uint count = 0; while (true) { byte[] line = Ascii.Trim(iReader.ReadUntil(Ascii.kAsciiLf)); int bytes = line.Length; if (bytes == 0) { if (count == 0) continue; // a blank line before first header - ignore (RFC 2616 section 4.1) iWriter.WriteFlush(); return; } if (Ascii.IsWhitespace(line[0])) continue; // a line starting with spaces is a continuation line Parser parser = new Parser(line); if (count == 0) { // status EVersion version = Http.Version(parser.Next()); uint code; try { code = Ascii.Uint(parser.Next()); } catch (AsciiError) { throw new HttpError(); } byte[] temp = Ascii.Trim(parser.Remaining()); string reason = Encoding.UTF8.GetString(temp, 0, temp.Length); Status status = new Status(code, reason); iWriter.WriteStatus(status, version); } else { // header byte[] field = parser.Next(Ascii.kAsciiColon); byte[] value = Ascii.Trim(parser.Remaining()); iWriter.WriteHeader(field, value); } count++; } }