public static RecordEntryContentType GetContetTypeFromHeaders(Dictionary <string, List <string> > responseHeaders) { string mimeType = string.Empty; RecordEntryContentType contentType = RecordEntryContentType.Null; var header = responseHeaders.Where <KeyValuePair <string, List <string> > >((hkv) => hkv.Key.Equals("Content-Type", StringComparison.OrdinalIgnoreCase)); if (header.Any <KeyValuePair <string, List <string> > >()) { mimeType = header.First <KeyValuePair <string, List <string> > >().Value?.First <string>(); } if (!string.IsNullOrWhiteSpace(mimeType)) { if (IsHttpContentBinary(mimeType)) { contentType = RecordEntryContentType.Binary; } else { contentType = RecordEntryContentType.Ascii; } } return(contentType); }
public static HttpContent CreateHttpContent(string contentData, RecordEntryContentType recordContentType) { HttpContent createdContent = null; byte[] hashBytes = null; switch (recordContentType) { case RecordEntryContentType.Binary: { try { hashBytes = Convert.FromBase64String(contentData); if (hashBytes != null) { createdContent = new ByteArrayContent(hashBytes); } } catch { if (contentData != null) { createdContent = new StringContent(contentData); } else { createdContent = new StringContent(string.Empty); } } break; } case RecordEntryContentType.Ascii: { createdContent = new StringContent(contentData); break; } case RecordEntryContentType.Null: default: { createdContent = new StringContent(string.Empty); break; } } return(createdContent); }
private RecordEntryContentType DetectContentType(HttpContent content) { RecordEntryContentType contentType = RecordEntryContentType.Null; if (content != null) { if (RecorderUtilities.IsHttpContentBinary(content)) { contentType = RecordEntryContentType.Binary; } else { contentType = RecordEntryContentType.Ascii; } } return(contentType); }