Reqord.ContentAnalyzer (reqord v0.4.0)
View SourceAnalyzes HTTP response content to determine optimal storage strategy.
This module provides utilities for:
- Detecting binary vs text content
- Determining appropriate encoding strategies
- Identifying streaming responses
Summary
Functions
Analyzes response content and returns encoding recommendation.
Extracts content-type from headers map or list.
Determines if content should be stored externally based on size and type.
Functions
Analyzes response content and returns encoding recommendation.
Returns
{:text, content}- Text content, use Base64 encoding{:binary, content}- Binary content, consider external storage{:stream, content}- Streaming content, requires special handling
Examples
iex> Reqord.ContentAnalyzer.analyze_content("application/json", ~s({"key": "value"}))
{:text, ~s({"key": "value"})}
iex> Reqord.ContentAnalyzer.analyze_content("image/png", <<137, 80, 78, 71>>)
{:binary, <<137, 80, 78, 71>>}
iex> Reqord.ContentAnalyzer.analyze_content("text/event-stream", "data: chunk1\n\n")
{:stream, "data: chunk1\n\n"}
Extracts content-type from headers map or list.
Examples
iex> Reqord.ContentAnalyzer.extract_content_type(%{"content-type" => "application/json"})
"application/json"
iex> Reqord.ContentAnalyzer.extract_content_type([{"Content-Type", "image/png; charset=utf-8"}])
"image/png"
@spec should_store_externally?(atom(), non_neg_integer()) :: boolean()
Determines if content should be stored externally based on size and type.
Examples
iex> Reqord.ContentAnalyzer.should_store_externally?(:binary, 2_000_000)
true
iex> Reqord.ContentAnalyzer.should_store_externally?(:text, 500_000)
false