{"record":{"id":"80f71c2355d98d9d","repo":"quarkusio/quarkus","slug":"a-rest-client-response-object-was-returned-from-a","errorCode":null,"errorMessage":"A REST Client Response object was returned from a server endpoint. This is not supported because it carries connection-specific headers that are not suitable for forwarding. Please create a new Response using Response.fromResponse() or by extracting the status, entity and headers you need.","messagePattern":"A REST Client Response object was returned from a server endpoint\\. This is not supported because it carries connection-specific headers that are not suitable for forwarding\\. Please create a new Response using Response\\.fromResponse\\(\\) or by extracting the status, entity and headers you need\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/ResponseHandler.java","lineNumber":51,"sourceCode":"    private static final Set<String> IGNORED_HEADERS = Collections.singleton(ServerSerialisers.TRANSFER_ENCODING.toLowerCase(\n            Locale.ROOT));\n\n    private final List<ResponseBuilderCustomizer> responseBuilderCustomizers;\n\n    public ResponseHandler(List<ResponseBuilderCustomizer> responseBuilderCustomizers) {\n        this.responseBuilderCustomizers = responseBuilderCustomizers;\n    }\n\n    private ResponseHandler() {\n        this.responseBuilderCustomizers = Collections.emptyList();\n    }\n\n    @Override\n    public void handle(ResteasyReactiveRequestContext requestContext) throws Exception {\n        Object result = requestContext.getResult();\n        if (result instanceof Response existing) {\n            if (existing instanceof ResponseImpl responseImpl && responseImpl.isClientResponse()) {\n                throw new IllegalStateException(\n                        \"A REST Client Response object was returned from a server endpoint. \"\n                                + \"This is not supported because it carries connection-specific headers \"\n                                + \"that are not suitable for forwarding. \"\n                                + \"Please create a new Response using Response.fromResponse() or \"\n                                + \"by extracting the status, entity and headers you need.\");\n            }\n            boolean mediaTypeAlreadyExists = false;\n            //we already have a response\n            //set it explicitly\n            ResponseBuilderImpl responseBuilder;\n            if (existing.getEntity() instanceof GenericEntity<?> genericEntity) {\n                requestContext.setGenericReturnType(genericEntity.getType());\n                responseBuilder = fromResponse(existing);\n                responseBuilder.entity(genericEntity.getEntity());\n            } else {\n                // TCK says to use the entity type as generic type if we return a response\n                if (existing.hasEntity() && (existing.getEntity() != null))\n                    requestContext.setGenericReturnType(existing.getEntity().getClass());","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/ResponseHandler.java#L33-L69","documentation":"The server endpoint returned a JAX-RS Response produced by a REST Client call (resteasy-reactive's ResponseImpl flagged as a client response). Client responses hold connection-specific state (underlying HTTP connection headers, closed streams) that cannot be forwarded as a server response, so the server rejects it with IllegalStateException instead of producing a corrupt response.","triggerScenarios":"A resource method returns the Response object obtained directly from a REST Client interface call (or RestResponse/Uni<Response> unwrapped to a client ResponseImpl) instead of building a new server-side Response.","commonSituations":"Proxying another service's response verbatim; refactoring a client call into a resource method return; forgetting that quarkus-rest-client Response types are distinct from server Response implementations.","solutions":["Create a new server Response with Response.fromResponse(existing)","Extract status, entity and headers and rebuild via Response.ok(...).status(...).header(...)","Read the entity first (existing.readEntity(...)) and return that object directly","If proxying is intended, copy only safe headers explicitly"],"exampleFix":"// before\n@GET\npublic Response proxy() {\n    return client.get(); // client Response\n}\n// after\n@GET\npublic Response proxy() {\n    Response existing = client.get();\n    return Response.fromResponse(existing);\n}","handlingStrategy":"type-guard","validationCode":"if (result instanceof ResponseImpl r && r.isClientResponse()) result = Response.fromResponse(r);","typeGuard":"static boolean isServerResponse(Response r) {\n    return !(r instanceof org.jboss.resteasy.reactive.server.jaxrs.ResponseImpl impl && impl.isClientResponse());\n}","tryCatchPattern":"try { return proxy(); } catch (IllegalStateException e) { if (e.getMessage().contains(\"REST Client Response\")) { return Response.fromResponse(clientResp); } throw e; }","preventionTips":["Never return client Response objects directly from resource methods","Always convert with Response.fromResponse or rebuild explicitly","Separate client DTOs from server response construction"],"tags":["resteasy-reactive","rest-client","response-forwarding","proxy"],"backgroundTag":"client-response-returned-from-endpoint","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}