Repository: oatpp/oatpp
File: src/oatpp/codegen/api_controller/cors_define.hpp (C++)

Code before:
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 ***************************************************************************/

#define OATPP_MACRO_API_CONTROLLER_ADDCORS_BODY_DEFAULT_ORIGIN "*"
#define OATPP_MACRO_API_CONTROLLER_ADDCORS_BODY_DEFAULT_METHODS "GET, POST, OPTIONS"
#define OATPP_MACRO_API_CONTROLLER_ADDCORS_BODY_DEFAULT_HEADERS "DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization"
#define OATPP_MACRO_API_CONTROLLER_ADDCORS_BODY_DEFAULT_MAX_AGE "1728000"

#define OATPP_MACRO_API_CONTROLLER_ADDCORS_BODY(ARG_ORIGIN, ARG_METHODS, ARG_HEADERS, ARG_MAX_AGE) \
  resp->putHeaderIfNotExists(oatpp::web::protocol::http::Header::CORS_ORIGIN, ARG_ORIGIN); \
  resp->putHeaderIfNotExists(oatpp::web::protocol::http::Header::CORS_METHODS, ARG_METHODS); \
  resp->putHeaderIfNotExists(oatpp::web::protocol::http::Header::CORS_HEADERS, ARG_HEADERS);\
  resp->putHeaderIfNotExists(oatpp::web::protocol::http::Header::CORS_MAX_AGE, ARG_MAX_AGE);

#define OATPP_MACRO_API_CONTROLLER_ADDCORS_MACRO_1(ENDPOINTNAME, ...) \
ENDPOINT_INTERCEPTOR(ENDPOINTNAME, ZZ__CORS_INTERCEPTOR_##ENDPOINTNAME) { \
  auto resp = (this->*intercepted)(request); \
  OATPP_MACRO_API_CONTROLLER_ADDCORS_BODY( \
    OATPP_MACRO_API_CONTROLLER_ADDCORS_BODY_DEFAULT_ORIGIN, \
    OATPP_MACRO_API_CONTROLLER_ADDCORS_BODY_DEFAULT_METHODS, \
    OATPP_MACRO_API_CONTROLLER_ADDCORS_BODY_DEFAULT_HEADERS, \
    OATPP_MACRO_API_CONTROLLER_ADDCORS_BODY_DEFAULT_MAX_AGE \
  ) \
  return resp; \
} \
ENDPOINT("OPTIONS", Z__ENDPOINT_##ENDPOINTNAME->info()->path, ZZ__CORS_OPTIONS_ENDPOINT_##ENDPOINTNAME) { \
  auto resp = createResponse(Status::CODE_204, ""); \
    OATPP_MACRO_API_CONTROLLER_ADDCORS_BODY( \
    OATPP_MACRO_API_CONTROLLER_ADDCORS_BODY_DEFAULT_ORIGIN, \
    OATPP_MACRO_API_CONTROLLER_ADDCORS_BODY_DEFAULT_METHODS, \
    OATPP_MACRO_API_CONTROLLER_ADDCORS_BODY_DEFAULT_HEADERS, \
    OATPP_MACRO_API_CONTROLLER_ADDCORS_BODY_DEFAULT_MAX_AGE \
  ) \
  return resp; \
}

#define OATPP_MACRO_API_CONTROLLER_ADDCORS_MACRO_2(ENDPOINTNAME, ORIGIN) \
ENDPOINT_INTERCEPTOR(ENDPOINTNAME, ZZ__CORS_INTERCEPTOR_##ENDPOINTNAME) { \
  auto resp = (this->*intercepted)(request); \
  OATPP_MACRO_API_CONTROLLER_ADDCORS_BODY( \
      ORIGIN, \

Review comment (suggestion):
You may use just `CORS` instead of `ZZ__CORS_INTERCEPTOR_##ENDPOINTNAME`
because interceptor is already unique for the pair of `{<endpoint name>, <Interceptor name>}`

```cpp
ENDPOINT_INTERCEPTOR(ENDPOINTNAME, CORS /* name of interceptor unique for the endpoint */) 
```

Code after:
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 ***************************************************************************/

#define OATPP_MACRO_API_CONTROLLER_ADDCORS_BODY_DEFAULT_ORIGIN "*"
#define OATPP_MACRO_API_CONTROLLER_ADDCORS_BODY_DEFAULT_METHODS "GET, POST, OPTIONS"
#define OATPP_MACRO_API_CONTROLLER_ADDCORS_BODY_DEFAULT_HEADERS "DNT, User-Agent, X-Requested-With, If-Modified-Since, Cache-Control, Content-Type, Range, Authorization"
#define OATPP_MACRO_API_CONTROLLER_ADDCORS_BODY_DEFAULT_MAX_AGE "1728000"

#define OATPP_MACRO_API_CONTROLLER_ADDCORS_BODY(ARG_ORIGIN, ARG_METHODS, ARG_HEADERS, ARG_MAX_AGE) \
  resp->putHeaderIfNotExists(oatpp::web::protocol::http::Header::CORS_ORIGIN, ARG_ORIGIN); \
  resp->putHeaderIfNotExists(oatpp::web::protocol::http::Header::CORS_METHODS, ARG_METHODS); \
  resp->putHeaderIfNotExists(oatpp::web::protocol::http::Header::CORS_HEADERS, ARG_HEADERS);\
  resp->putHeaderIfNotExists(oatpp::web::protocol::http::Header::CORS_MAX_AGE, ARG_MAX_AGE);

#define OATPP_MACRO_API_CONTROLLER_ADDCORS_MACRO_1(ENDPOINTNAME, ...) \
ENDPOINT_INTERCEPTOR(ENDPOINTNAME, CORS) { \
  auto resp = (this->*intercepted)(request); \
  OATPP_MACRO_API_CONTROLLER_ADDCORS_BODY( \
    OATPP_MACRO_API_CONTROLLER_ADDCORS_BODY_DEFAULT_ORIGIN, \
    OATPP_MACRO_API_CONTROLLER_ADDCORS_BODY_DEFAULT_METHODS, \
    OATPP_MACRO_API_CONTROLLER_ADDCORS_BODY_DEFAULT_HEADERS, \
    OATPP_MACRO_API_CONTROLLER_ADDCORS_BODY_DEFAULT_MAX_AGE \
  ) \
  return resp; \
} \
ENDPOINT("OPTIONS", Z__ENDPOINT_##ENDPOINTNAME->info()->path, ZZ__CORS_OPTIONS_ENDPOINT_##ENDPOINTNAME) { \
  auto resp = createResponse(Status::CODE_204, ""); \
    OATPP_MACRO_API_CONTROLLER_ADDCORS_BODY( \
    OATPP_MACRO_API_CONTROLLER_ADDCORS_BODY_DEFAULT_ORIGIN, \
    OATPP_MACRO_API_CONTROLLER_ADDCORS_BODY_DEFAULT_METHODS, \
    OATPP_MACRO_API_CONTROLLER_ADDCORS_BODY_DEFAULT_HEADERS, \
    OATPP_MACRO_API_CONTROLLER_ADDCORS_BODY_DEFAULT_MAX_AGE \
  ) \
  return resp; \
}

#define OATPP_MACRO_API_CONTROLLER_ADDCORS_MACRO_2(ENDPOINTNAME, ORIGIN) \
ENDPOINT_INTERCEPTOR(ENDPOINTNAME, CORS) { \
  auto resp = (this->*intercepted)(request); \
  OATPP_MACRO_API_CONTROLLER_ADDCORS_BODY( \
      ORIGIN, \