Repository: vapor/vapor
File: Sources/Vapor/Response/Response.swift (Swift)

Code before:
                guard let body = box.body.buffer else {
                    throw Abort(.unprocessableEntity)
                }
                return try decoder.decode(D.self, from: body, headers: box.headers)
            }
        }

        func encode<C>(_ content: C, using encoder: ContentEncoder) throws where C : Content {
            var content = content
            try content.beforeEncode()
            try self.response.responseBox.withLockedValue { box in
                var body = box.body.byteBufferAllocator.buffer(capacity: 0)
                try encoder.encode(content, to: &body, headers: &box.headers)
                box.body = .init(buffer: body, byteBufferAllocator: box.body.byteBufferAllocator)
            }
        }

        func decode<C>(_ content: C.Type, using decoder: ContentDecoder) throws -> C where C : Content {
            try self.response.responseBox.withLockedValue { box in
                guard let body = box.body.buffer else {
                    throw Abort(.unprocessableEntity)
                }
                var decoded = try decoder.decode(C.self, from: body, headers: box.headers)
                try decoded.afterDecode()
                return decoded
            }
        }
    }

    public var content: ContentContainer {
        get {
            return _ContentContainer(response: self)
        }
        set {
            // ignore since Request is a reference type
        }
    }
    
    struct ResponseBox: Sendable {
        var version: HTTPVersion
        var status: HTTPResponseStatus
        var headers: HTTPHeaders
        var body: Body {
            didSet {
                self.headers.updateContentLength(body.count)
            }
        }
        var upgrader: Upgrader?
        // If `true`, don't serialize the body.
        var forHeadRequest: Bool


Review comment (suggestion):
The `try decoded.afterDecode()` should be outside?
```suggestion
            var decoded = try self.response.responseBox.withLockedValue { box in
                guard let body = box.body.buffer else {
                    throw Abort(.unprocessableEntity)
                }
                return try decoder.decode(C.self, from: body, headers: box.headers)
            }
            try decoded.afterDecode()
            return decoded
```

Code after:
                guard let body = box.body.buffer else {
                    throw Abort(.unprocessableEntity)
                }
                return try decoder.decode(D.self, from: body, headers: box.headers)
            }
        }

        func encode<C>(_ content: C, using encoder: ContentEncoder) throws where C : Content {
            var content = content
            try content.beforeEncode()
            try self.response.responseBox.withLockedValue { box in
                var body = box.body.byteBufferAllocator.buffer(capacity: 0)
                try encoder.encode(content, to: &body, headers: &box.headers)
                box.body = .init(buffer: body, byteBufferAllocator: box.body.byteBufferAllocator)
            }
        }

        func decode<C>(_ content: C.Type, using decoder: ContentDecoder) throws -> C where C : Content {
            var decoded = try self.response.responseBox.withLockedValue { box in
                guard let body = box.body.buffer else {
                    throw Abort(.unprocessableEntity)
                }
                return try decoder.decode(C.self, from: body, headers: box.headers)
            }
            try decoded.afterDecode()
            return decoded
        }
    }

    public var content: ContentContainer {
        get {
            return _ContentContainer(response: self)
        }
        set {
            // ignore since Request is a reference type
        }
    }
    
    struct ResponseBox: Sendable {
        var version: HTTPVersion
        var status: HTTPResponseStatus
        var headers: HTTPHeaders
        var body: Body {
            didSet {
                self.headers.updateContentLength(body.count)
            }
        }
        var upgrader: Upgrader?
        // If `true`, don't serialize the body.
        var forHeadRequest: Bool