private static ResponseFragment ParseBatchFragment(StringReader reader, string boundary) { //HTTP/1.1 200 Ok //Content-Type: application/atom+xml;type=entry //Content-Length: ### string line = reader.ReadLine(); Match match = Regex.Match(line, @"HTTP/1.1 ([0-9]{3}).*"); if (!match.Success) { AstoriaTestLog.FailAndThrow(String.Format("Expected HTTP protocol and status code, got '{0}'", line)); } HttpStatusCode statusCode = (HttpStatusCode)Enum.Parse(typeof(HttpStatusCode), match.Groups[1].Value); Dictionary <string, string> headers = new Dictionary <string, string>(); while (null != (line = reader.ReadLine()) && !line.Contains(boundary) && (match = Regex.Match(line, @"([A-Za-z-]+):\s*(.+)")).Success) { string headerString = match.Groups[1].Value;//.Replace("-", String.Empty).ToLowerInvariant(); string value = match.Groups[2].Value; headers.Add(headerString, value); } // the rest is payload StringBuilder payload = new StringBuilder(); while (null != (line = reader.ReadLine()) && !line.Contains(boundary)) { payload.AppendLine(line); } ResponseFragment fragment = new ResponseFragment() { ContentID = null, ContentType = "application/xml", // will be overwritten if present Payload = payload.ToString().Trim(), StatusCode = statusCode, Headers = headers }; headers.TryGetValue("Content-Type", out fragment.ContentType); headers.TryGetValue("Content-ID", out fragment.ContentID); return(fragment); }
private static AstoriaResponse FragmentToResponse(AstoriaRequest request, ResponseFragment fragment) { AstoriaResponse response = new AstoriaResponse(request); response.Payload = fragment.Payload; response.ContentType = fragment.ContentType; response.ActualStatusCode = fragment.StatusCode; response.ETagHeaderFound = false; foreach (var header in fragment.Headers) { if (header.Key == "ETag") response.ETagHeaderFound = true; response.Headers[header.Key] = header.Value; } return response; }
private static AstoriaResponse FragmentToResponse(AstoriaRequest request, ResponseFragment fragment) { AstoriaResponse response = new AstoriaResponse(request); response.Payload = fragment.Payload; response.ContentType = fragment.ContentType; response.ActualStatusCode = fragment.StatusCode; response.ETagHeaderFound = false; foreach (var header in fragment.Headers) { if (header.Key == "ETag") { response.ETagHeaderFound = true; } response.Headers[header.Key] = header.Value; } return(response); }
private static ResponseFragment ParseBatchFragment(StringReader reader, string boundary) { //HTTP/1.1 200 Ok //Content-Type: application/atom+xml;type=entry //Content-Length: ### string line = reader.ReadLine(); Match match = Regex.Match(line, @"HTTP/1.1 ([0-9]{3}).*"); if (!match.Success) AstoriaTestLog.FailAndThrow(String.Format("Expected HTTP protocol and status code, got '{0}'", line)); HttpStatusCode statusCode = (HttpStatusCode)Enum.Parse(typeof(HttpStatusCode), match.Groups[1].Value); Dictionary<string, string> headers = new Dictionary<string, string>(); while (null != (line = reader.ReadLine()) && !line.Contains(boundary) && (match = Regex.Match(line, @"([A-Za-z-]+):\s*(.+)")).Success) { string headerString = match.Groups[1].Value;//.Replace("-", String.Empty).ToLowerInvariant(); string value = match.Groups[2].Value; headers.Add(headerString, value); } // the rest is payload StringBuilder payload = new StringBuilder(); while (null != (line = reader.ReadLine()) && !line.Contains(boundary)) payload.AppendLine(line); ResponseFragment fragment = new ResponseFragment() { ContentID = null, ContentType = "application/xml", // will be overwritten if present Payload = payload.ToString().Trim(), StatusCode = statusCode, Headers = headers }; headers.TryGetValue("Content-Type", out fragment.ContentType); headers.TryGetValue("Content-ID", out fragment.ContentID); return fragment; }