{"record":{"id":"2c4be4edebc81ce9","repo":"quarkusio/quarkus","slug":"a-rest-client-restresponse-object-was-returned-fro","errorCode":null,"errorMessage":"A REST Client RestResponse 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 RestResponse by extracting the status, entity and headers you need.","messagePattern":"A REST Client RestResponse 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 RestResponse 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":104,"sourceCode":"            if (existing.getMediaType() != null) {\n                requestContext.setResponseContentType(existing.getMediaType());\n                mediaTypeAlreadyExists = true;\n            }\n            EncodedMediaType produces = requestContext.getResponseContentType();\n            if (!mediaTypeAlreadyExists && (produces != null) && (responseBuilder.getEntity() != null)) {\n                responseBuilder.header(HttpHeaders.CONTENT_TYPE, produces.toString());\n            }\n            if ((responseBuilder instanceof ResponseBuilderImpl)) {\n                // avoid unnecessary copying of HTTP headers from the Builder to the Response\n                requestContext\n                        .setResponse(\n                                new LazyResponse.Existing(((ResponseBuilderImpl) responseBuilder).build(false)));\n            } else {\n                requestContext.setResponse(new LazyResponse.Existing(responseBuilder.build()));\n            }\n        } else if (result instanceof RestResponse<?> existing) {\n            if (existing instanceof RestResponseImpl<?> restResponseImpl && restResponseImpl.isClientResponse()) {\n                throw new IllegalStateException(\n                        \"A REST Client RestResponse 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 RestResponse 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                //TODO: super inefficient\n                responseBuilder = fromResponse(existing);\n                if ((result instanceof RestResponseImpl<?> responseImpl)) {\n                    // needed in order to preserve entity annotations","sourceCodeStart":86,"sourceCodeEnd":122,"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#L86-L122","documentation":"Same family as the client-Response case but for org.jboss.resteasy.reactive.client.RestResponse: a server endpoint returned the RestResponse instance obtained from a REST Client call (RestResponseImpl flagged as client response). Its connection-specific headers make it unsuitable for direct forwarding, so IllegalStateException is thrown.","triggerScenarios":"A resource method returns the RestResponse<T> received from a MicroProfile/REST Client call, e.g. `return myClient.call();` where the client method returns RestResponse<String>.","commonSituations":"Service-to-service proxy endpoints; generic wrappers where RestResponse<T> is the return type both client-side and expected server-side; copy-paste between client and server APIs.","solutions":["Unwrap and rebuild: return the entity (existing.getEntity()) or a new server Response carrying extracted status/headers","Use existing.readEntity(Class) to consume the body, then build a fresh Response","Change the resource method's return type to the entity type rather than RestResponse","If header forwarding is needed, copy selected headers explicitly into a new Response"],"exampleFix":"// before\n@GET\npublic RestResponse<String> call() {\n    return client.get(); // client RestResponse\n}\n// after\n@GET\npublic Response call() {\n    RestResponse<String> existing = client.get();\n    return Response.ok(existing.readEntity(String.class)).build();\n}","handlingStrategy":"type-guard","validationCode":"if (result instanceof RestResponseImpl<?> r && r.isClientResponse()) result = Response.ok(r.readEntity(Object.class)).build();","typeGuard":"static boolean isServerRestResponse(RestResponse<?> r) {\n    return !(r instanceof org.jboss.resteasy.reactive.client.impl.RestResponseImpl<?> impl && impl.isClientResponse());\n}","tryCatchPattern":"try { return proxy(); } catch (IllegalStateException e) { if (e.getMessage().contains(\"REST Client RestResponse\")) { return Response.ok(clientResp.readEntity(String.class)).build(); } throw e; }","preventionTips":["Return the entity type, not RestResponse, from resource methods","Unwrap client RestResponse with readEntity before returning","Never forward client responses verbatim"],"tags":["resteasy-reactive","rest-client","restresponse","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-12T22:17:10.623Z"}