[BUG] [Server: C++] [Qt5] Missing headers and wrong status code
Created by: natanlaverde
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator? -
What's the version of OpenAPI Generator used? -
Have you search for related issues/PRs? -
What's the actual output vs expected output?
Description
In class ApiRequest, the helper method writeResponseHeaders is being called in beginning of generated {{nickname}}Response and {{nickname}}Error methods, in such case, some response headers are not present yet (e.g.: Content-Type or Content-Length).
When one of the generated methods {{nickname}}Error are called, the HTTP Status Code is wrong, the status code will be always HTTP/1.0 200 OK, even if setStatusCode(QHttpEngine::Socket::NotFound) has been called.
openapi-generator version
5.0.0-SNAPSHOT (master).
OpenAPI declaration file content or url
N/A.
Command line used for generation
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate
-i https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml
-g cpp-qt5-qhttpengine-server
-o /tmp/server/petstore/cpp-qt5-qhttpengine-server
Steps to reproduce
Just generate the code, start server and compare the response headers.
When a method that returns json is called, the headers Content-Length and Content-Type are not present.
If the generated method set the status to other than HTTP/1.0 200 OK, the code 200 is not incorrectly returned.
Related issues/PRs
N/A.
Suggest a fix
Change helper method writeResponseHeaders implementation to just set the headers, instead of write them, and also rename the method to setSocketResponseHeaders, to maintain the new semantic.
The implementation of QHttpEngine::Socket::write or QHttpEngine::Socket::writeJson implementations will call Socket::writeData that writes the Headers and Status Code before write the content if they are not already written.
If these methods are not called (e.g.: empty reply), we could set the headers just before close the socket.