// called by socket reader to find the total read size public unsafe int ParseRequestHeader(int totalRead) { if (RequestBodyStart == 0) { RequestBodyStart = findHeaderEnd(totalRead); } if (RequestBodyStart > 0) { if (Method.IsEmpty) // headers unparsed { var headers = new AString(Buffer, 0, RequestBodyStart); while (headers.Length > 0) { // get the next line var i = headers.IndexOfCRLF(); if (i < 0) { break; } // get the next line and advance the header span var line = headers.Substring(0, i); headers = headers.Substring(i + 2); // remove leading spaces while (line.Length > 0 && line[0] < 'A') { line = line.Substring(1); } // skip the empty line if (line.Length == 0) { continue; } if (Method.IsEmpty) // first line is not parsed, so this is it { FirstLine = line; ParseFirstLine(line); } else // the only other line we are interested in is content-length if (RequestBodyLength == 0) { //var str = Encoding.ASCII.GetString(line); // for debugging, remove if (line.StartsWith(content_length)) { i = line.IndexOf((byte)':'); line = line.Substring(i + 2); line.TryToInt(out RequestBodyLength); } } } } return(ResponseStart); } return(0); }
public AString areaCodeFromPhone(AString phone) { if (phone.IsEmpty) { return(AString.Empty); } var openBrace = phone.IndexOf('('); var closeBrace = phone.IndexOf(')'); if (openBrace >= 0 && closeBrace == openBrace + 4) { return(phone.Substring(openBrace + 1, 3)); } return(null); }
public bool bufferFromEmail(AString email, out byte[] buffer) { var amp = email.IndexOf((byte)'@'); if (amp < 0 || amp == email.Length - 1) { buffer = null; return(false); } byte domainIdx = (byte)Domains.GetOrCreateRange(email.Substring(amp + 1)).Index; buffer = new byte[amp + 1]; for (int i = 0; i < amp; i++) { buffer[i] = email[i]; } buffer[amp] = domainIdx; return(true); }