diff --git a/CHANGELOG.md b/CHANGELOG.md index f8a5e14..0ff9c25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added a launcher function `launch` to make it easier to launch the app. - Semantic caching enabled by SemanticCaches.jl. You can change it by setting `cached=false` in the `launch()` function. +### Fixed +- Fixed a bug when caching would error for certain types of HTTP body (eg, `IOBuffer`) + + ## [0.3.0] ### Added diff --git a/src/CacheLayer.jl b/src/CacheLayer.jl index abbff43..7124619 100644 --- a/src/CacheLayer.jl +++ b/src/CacheLayer.jl @@ -32,7 +32,9 @@ const HASH_CACHE = HashCache() function cache_layer(handler) return function (req; kw...) VERBOSE = Base.get(ENV, "CACHES_VERBOSE", "true") == "true" - if req.method == "POST" && !isempty(req.body) + has_body = (req.body isa IOBuffer || + (req.body isa AbstractVector && !isempty(req.body))) + if req.method == "POST" && has_body body = JSON3.read(copy(req.body)) ## chat/completions is for OpenAI, v1/messages is for Anthropic if occursin("v1/chat/completions", req.target) ||