├── .gitattributes ├── .github └── issue_template.md ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── CMakeLists.txt ├── CONTRIBUTING.md ├── LICENSE ├── NOTICE ├── README.md ├── VERSION ├── appveyor.yml ├── cmake ├── AppleToolchain.cmake ├── DefineProjectConfig.cmake.in ├── DefineProjectMacros.cmake ├── DefineProjectVersion.cmake ├── WindowsToolchain.cmake └── easyhttpcppeasyhttpConfig.cmake.in ├── doc ├── CMakeLists.txt └── Doxyfile.in ├── include └── easyhttpcpp │ ├── CacheControl.h │ ├── Call.h │ ├── Connection.h │ ├── ConnectionPool.h │ ├── CrlCheckPolicy.h │ ├── EasyHttp.h │ ├── Headers.h │ ├── HttpAuthenticator.h │ ├── HttpAuthenticatorCallback.h │ ├── HttpAuthenticatorTypeDefs.h │ ├── HttpCache.h │ ├── HttpCacheUpdateCheckPolicy.h │ ├── HttpConstants.h │ ├── HttpException.h │ ├── HttpExports.h │ ├── Interceptor.h │ ├── LoggingInterceptor.h │ ├── LoggingInterceptorFactory.h │ ├── MediaType.h │ ├── Proxy.h │ ├── Request.h │ ├── RequestBody.h │ ├── Response.h │ ├── ResponseBody.h │ ├── ResponseBodyStream.h │ ├── ResponseCallback.h │ ├── common │ ├── AtomicBool.h │ ├── BaseException.h │ ├── BaseLogger.h │ ├── ByteArrayBuffer.h │ ├── Cache.h │ ├── CacheInfoWithDataSize.h │ ├── CacheManager.h │ ├── CacheMetadata.h │ ├── CacheStrategy.h │ ├── CacheStrategyListener.h │ ├── CommonException.h │ ├── CommonExports.h │ ├── CommonMacros.h │ ├── CoreException.h │ ├── CoreExports.h │ ├── CoreLogger.h │ ├── DefaultLogWriter.h │ ├── ExceptionConstants.h │ ├── FileUtil.h │ ├── Future.h │ ├── LogLevel.h │ ├── LogWriter.h │ ├── LruCacheByDataSizeStrategy.h │ ├── OpenSslInitializer.h │ ├── ProjectVersion.h │ ├── RefCountedRunnable.h │ ├── StringUtil.h │ └── Typedef.h │ ├── db │ ├── AutoSqliteCursor.h │ ├── AutoSqliteDatabase.h │ ├── AutoSqliteTransaction.h │ ├── ContentValues.h │ ├── Cursor.h │ ├── DbExports.h │ ├── SqlException.h │ ├── SqliteConflictAlgorithm.h │ ├── SqliteCursor.h │ ├── SqliteDatabase.h │ ├── SqliteDatabaseCorruptionListener.h │ ├── SqliteOpenHelper.h │ └── SqliteQueryBuilder.h │ ├── executorservice │ ├── BlockingQueue.h │ ├── BoundBlockingQueue.h │ ├── ExecutorServiceException.h │ ├── ExecutorServiceExports.h │ ├── FutureTask.h │ ├── QueuedThreadPool.h │ ├── ScheduledFutureTask.h │ ├── Task.h │ └── UnboundBlockingQueue.h │ └── messagedigest │ ├── DigestConstants.h │ ├── DigestEngine.h │ ├── DigestUtil.h │ ├── MessageDigestException.h │ └── MessageDigestExports.h ├── libversion ├── rocro.yml ├── samples ├── AsyncHttpClient │ ├── AsyncHttpClient.cpp │ └── CMakeLists.txt ├── CMakeLists.txt ├── README.md └── SimpleHttpClient │ ├── CMakeLists.txt │ └── SimpleHttpClient.cpp ├── scripts ├── 01_install_dependencies.sh ├── 02_run_alltests.sh └── 03_run_samples.sh ├── src ├── CacheControl.cpp ├── CallInterceptorChain.cpp ├── CallInterceptorChain.h ├── CallInternal.cpp ├── CallInternal.h ├── CallLoggingInterceptor.cpp ├── CallLoggingInterceptor.h ├── ConnectionInternal.cpp ├── ConnectionInternal.h ├── ConnectionPool.cpp ├── ConnectionPoolInternal.cpp ├── ConnectionPoolInternal.h ├── ConnectionStatusListener.h ├── EasyHttp.cpp ├── EasyHttpContext.cpp ├── EasyHttpContext.h ├── EasyHttpInternal.cpp ├── EasyHttpInternal.h ├── Headers.cpp ├── HttpAsyncExecutionTask.cpp ├── HttpAsyncExecutionTask.h ├── HttpCache.cpp ├── HttpCacheDatabase.cpp ├── HttpCacheDatabase.h ├── HttpCacheDatabaseOpenHelper.cpp ├── HttpCacheDatabaseOpenHelper.h ├── HttpCacheEnumerationListener.h ├── HttpCacheInfo.cpp ├── HttpCacheInfo.h ├── HttpCacheInternal.cpp ├── HttpCacheInternal.h ├── HttpCacheMetadata.cpp ├── HttpCacheMetadata.h ├── HttpCacheStrategy.cpp ├── HttpCacheStrategy.h ├── HttpConstants.cpp ├── HttpEngine.cpp ├── HttpEngine.h ├── HttpException.cpp ├── HttpExecutionTask.h ├── HttpExecutionTaskManager.cpp ├── HttpExecutionTaskManager.h ├── HttpFileCache.cpp ├── HttpFileCache.h ├── HttpInternalConstants.cpp ├── HttpInternalConstants.h ├── HttpLruCacheStrategy.cpp ├── HttpLruCacheStrategy.h ├── HttpRequestExecutor.cpp ├── HttpRequestExecutor.h ├── HttpTypedefs.h ├── HttpUtil.cpp ├── HttpUtil.h ├── KeepAliveTimeoutListener.h ├── KeepAliveTimeoutTask.cpp ├── KeepAliveTimeoutTask.h ├── LoggingInterceptorFactory.cpp ├── MediaType.cpp ├── NetworkInterceptorChain.cpp ├── NetworkInterceptorChain.h ├── NetworkLoggingInterceptor.cpp ├── NetworkLoggingInterceptor.h ├── Proxy.cpp ├── Request.cpp ├── RequestBody.cpp ├── RequestBodyForByteBuffer.cpp ├── RequestBodyForByteBuffer.h ├── RequestBodyForSharedPtrByteBuffer.cpp ├── RequestBodyForSharedPtrByteBuffer.h ├── RequestBodyForSharedPtrStream.cpp ├── RequestBodyForSharedPtrStream.h ├── RequestBodyForSharedPtrString.cpp ├── RequestBodyForSharedPtrString.h ├── RequestBodyForStream.cpp ├── RequestBodyForStream.h ├── RequestBodyForString.cpp ├── RequestBodyForString.h ├── RequestBodyUtil.cpp ├── RequestBodyUtil.h ├── Response.cpp ├── ResponseBody.cpp ├── ResponseBodyStreamFromCache.cpp ├── ResponseBodyStreamFromCache.h ├── ResponseBodyStreamInternal.cpp ├── ResponseBodyStreamInternal.h ├── ResponseBodyStreamWithCaching.cpp ├── ResponseBodyStreamWithCaching.h ├── ResponseBodyStreamWithoutCaching.cpp ├── ResponseBodyStreamWithoutCaching.h ├── SslContextCreator.cpp ├── SslContextCreator.h ├── common │ ├── AtomicBool.cpp │ ├── BaseException.cpp │ ├── BaseLogger.cpp │ ├── ByteArrayBuffer.cpp │ ├── CacheInfoWithDataSize.cpp │ ├── CacheManager.cpp │ ├── CacheMetadata.cpp │ ├── ColorConsoleChannelCreator.cpp │ ├── ColorConsoleChannelCreator.h │ ├── CommonException.cpp │ ├── CoreException.cpp │ ├── CoreLogger.cpp │ ├── DefaultLogWriter.cpp │ ├── ExceptionConstants.cpp │ ├── FileUtil.cpp │ ├── LruCacheByDataSizeStrategy.cpp │ ├── ProjectVersion.cpp │ ├── StringUtil.cpp │ ├── unix │ │ ├── ColorConsoleChannelCreatorImpl.cpp │ │ ├── ColorConsoleChannelCreatorImpl.h │ │ ├── FileUtilImpl.cpp │ │ └── FileUtilImpl.h │ └── windows │ │ ├── ColorConsoleChannelCreatorImpl.cpp │ │ ├── ColorConsoleChannelCreatorImpl.h │ │ ├── FileUtilImpl.cpp │ │ └── FileUtilImpl.h ├── db │ ├── ContentValues.cpp │ ├── SqlException.cpp │ ├── SqliteCursor.cpp │ ├── SqliteDatabase.cpp │ ├── SqliteOpenHelper.cpp │ └── SqliteQueryBuilder.cpp ├── executorservice │ ├── BoundBlockingQueue.cpp │ ├── ExecutorServiceException.cpp │ ├── QueuedThreadPool.cpp │ ├── RunnableWorker.cpp │ ├── RunnableWorker.h │ ├── Task.cpp │ └── UnboundBlockingQueue.cpp ├── messagedigest │ ├── DigestConstants.cpp │ ├── DigestEngine.cpp │ ├── DigestUtil.cpp │ ├── MessageDigestException.cpp │ ├── unix │ │ ├── DigestEngineImpl.cpp │ │ ├── DigestEngineImpl.h │ │ ├── DigestUtilImpl.cpp │ │ └── DigestUtilImpl.h │ └── windows │ │ ├── DigestEngineImpl.cpp │ │ ├── DigestEngineImpl.h │ │ ├── DigestUtilImpl.cpp │ │ └── DigestUtilImpl.h ├── unix │ ├── SslContextCreatorImpl.cpp │ └── SslContextCreatorImpl.h └── windows │ ├── SslContextCreatorImpl.cpp │ └── SslContextCreatorImpl.h └── tests ├── CMakeLists-integrationtests.txt ├── CMakeLists-unittests.txt ├── CMakeLists.txt ├── Data └── HttpIntegrationTest │ ├── 01_cache_from_db │ └── HttpCache │ │ ├── unix │ │ └── cache │ │ │ ├── 9548bfe183836899d66681fe4e6b0f7896aef2d0260ddcdf7e8b0697e8bd8977.data │ │ │ ├── 9f69b9b8c5cc8bec1aac9a61f850c6ce9c98eb135fcf3cedb70b27459f2a641e.data │ │ │ ├── cache_metadata.db │ │ │ └── d45fcd30cc134d7613dba07456a2ea845d2e0ff145466acace03b0ed5abafef6.data │ │ └── windows │ │ └── cache │ │ ├── 0c898621f37be5bb75f090362d28769dd8f5c020.data │ │ ├── 32e5eea70b79d340a52212871a1bdea48ca09a57.data │ │ ├── 86451cfc298fc6a03ea8067a483fc020fc9501cd.data │ │ └── cache_metadata.db │ ├── 02_https_localhost_cert │ └── cert │ │ ├── client │ │ ├── invalid_rootCa.txt │ │ ├── localhost_rootCa.pem │ │ ├── localhost_rootCa_invalid_common.pem │ │ ├── rootCa-invalid-common │ │ │ ├── 64b0d652.0 │ │ │ ├── c37db6da.0 │ │ │ ├── localhost_demoCA.crt │ │ │ └── localhost_interCA.crt │ │ ├── rootCa │ │ │ ├── 2eec780c.0 │ │ │ ├── c37db6da.0 │ │ │ ├── localhost_demoCA.crt │ │ │ └── localhost_interCA.crt │ │ └── rootCa_empty │ │ │ └── .gitkeep │ │ └── server │ │ └── server.pem │ └── 03_https_localhost_cert_expired │ └── cert │ ├── client │ └── rootCa │ │ ├── 2eec780c.0 │ │ ├── c37db6da.0 │ │ ├── localhost_demoCA_expired.crt │ │ └── localhost_interCA.crt │ └── server │ ├── server.pem │ └── server.pfx ├── integrationtests ├── CallExceptGetMethodIntegrationTest.cpp ├── CallExecuteAsyncIntegrationTest.cpp ├── CallWithCacheAfterSendRequestIntegrationTest.cpp ├── CallWithCacheBeforeSendRequestIntegrationTest.cpp ├── CallWithCacheManageIntegrationTest.cpp ├── CallWithCancelIntegrationTest.cpp ├── CallWithConnectionPoolAndCancelIntegrationTest.cpp ├── CallWithDatabaseCorruptionIntegrationTest.cpp ├── CallWithGetMethodIntegrationTest.cpp ├── CallWithHttpsIntegrationTest.cpp ├── CallWithInterceptorIntegrationTest.cpp ├── CallWithMultiThreadIntegrationTest.cpp ├── CallWithRedirectIntegrationTest.cpp ├── CallWithRetryByConnectionPoolIntegrationTest.cpp ├── CallWithoutConnectionPoolIntegrationTest.cpp ├── ConnectionConfirmationInterceptor.cpp ├── ConnectionConfirmationInterceptor.h ├── ConnectionPoolInternalIntegrationTest.cpp ├── ConnectionPoolInternalMultiThreadIntegrationTest.cpp ├── EasyHttpIntegrationTest.cpp ├── HttpCacheDatabaseCorruptionIntegrationTest.cpp ├── HttpCacheDatabaseIntegrationTest.cpp ├── HttpCacheIntegrationTest.cpp ├── HttpFileCacheDatabaseCorruptionIntegrationTest.cpp ├── HttpFileCacheIntegrationTest.cpp ├── HttpFileCacheWithMultiThreadIntegrationTest.cpp ├── HttpIntegrationTestCase.h ├── HttpTestBaseRequestHandler.cpp ├── HttpTestBaseRequestHandler.h ├── HttpTestCommonRequestHandler.cpp ├── HttpTestCommonRequestHandler.h ├── HttpTestConstants.cpp ├── HttpTestConstants.h ├── HttpTestResponseCallback.cpp ├── HttpTestResponseCallback.h ├── HttpTestUtil.cpp ├── HttpTestUtil.h ├── MockHttpCacheEnumerationListener.h ├── ResponseBodyStreamFromCacheIntegrationTest.cpp ├── ResponseBodyStreamWithCachingIntegrationTest.cpp ├── ResponseBodyStreamWithConnectionPoolIntegrationTest.cpp ├── ResponseBodyStreamWithDatabaseCorruptionIntegrationTest.cpp ├── ResponseBodyStreamWithReusedConnectionIntegrationTest.cpp ├── ResponseBodyStreamWithoutCachingIntegrationTest.cpp ├── SynchronizedExecutionRunner.cpp ├── SynchronizedExecutionRunner.h ├── db │ ├── SqliteCursorIntegrationTest.cpp │ ├── SqliteDatabaseCorruptionIntegrationTest.cpp │ ├── SqliteDatabaseIntegrationTest.cpp │ ├── SqliteDatabaseIntegrationTestConstants.cpp │ ├── SqliteDatabaseIntegrationTestConstants.h │ ├── SqliteDatabaseTestUtil.cpp │ ├── SqliteDatabaseTestUtil.h │ ├── SqliteIntegrationTest.cpp │ └── SqliteOpenHelperIntegrationTest.cpp └── executorservice │ ├── FutureTaskIntegrationTest.cpp │ ├── QueuedThreadPoolIntegrationTest.cpp │ └── ScheduledFutureTaskIntegrationTest.cpp ├── testutil ├── EasyHttpCppAssertions.h ├── ExceptionTestUtil.h ├── FileContentsEqualMatcher.cpp ├── FileContentsEqualMatcher.h ├── ForwardingMockSqliteDatabase.h ├── HeaderContainMatcher.cpp ├── HeaderContainMatcher.h ├── HeadersEqualMatcher.cpp ├── HeadersEqualMatcher.h ├── HttpTestRequestHandlerFactory.cpp ├── HttpTestRequestHandlerFactory.h ├── HttpTestServer.cpp ├── HttpTestServer.h ├── HttpsTestServer.cpp ├── HttpsTestServer.h ├── MockCache.h ├── MockCacheStrategyListener.h ├── MockFuture.h ├── MockHttpCache.h ├── MockInterceptor.h ├── MockRequest.h ├── MockResponseBodyStream.h ├── PartialMockFutureTask.h ├── PartialMockScheduledFutureTask.h ├── PartialMockSqliteOpenHelper.h ├── RandomUtil.cpp ├── RandomUtil.h ├── StdCLogCapture.cpp ├── StdCLogCapture.h ├── TestConstants.cpp ├── TestConstants.h ├── TestDatabaseUtil.cpp ├── TestDatabaseUtil.h ├── TestDefs.h ├── TestFileUtil.cpp ├── TestFileUtil.h ├── TestLogger.cpp ├── TestLogger.h ├── TestPreferences.cpp ├── TestPreferences.h ├── TestServer.cpp ├── TestServer.h ├── TestUtilExports.h ├── TimeInRangeMatcher.h ├── unix │ ├── TestFileUtilImpl.cpp │ └── TestFileUtilImpl.h └── windows │ ├── TestFileUtilImpl.cpp │ └── TestFileUtilImpl.h └── unittests ├── CacheControlUnitTest.cpp ├── CallInternalUnitTest.cpp ├── ConnectionInternalSetInuseParameterUnitTest.cpp ├── ConnectionInternalUnitTest.cpp ├── ConnectionPoolInternalUnitTest.cpp ├── ConnectionPoolUnitTest.cpp ├── EasyHttpContextUnitTest.cpp ├── EasyHttpInternalUnitTest.cpp ├── EasyHttpUnitTest.cpp ├── HeadersUnitTest.cpp ├── HttpCacheDatabaseUnitTest.cpp ├── HttpCacheInfoUnitTest.cpp ├── HttpCacheInternalUnitTest.cpp ├── HttpCacheStrategyFunctionUnitTest.cpp ├── HttpCacheStrategyUnitTest.cpp ├── HttpCacheUnitTest.cpp ├── HttpEngineUnitTest.cpp ├── HttpLruCacheStrategyUnitTest.cpp ├── HttpUtilUnitTest.cpp ├── HttpsExceptionUnitTest.cpp ├── KeepAliveTimeoutTaskUnitTest.cpp ├── MediaTypeUnitTest.cpp ├── MockConnectionPoolInternal.h ├── MockConnectionStatusListener.h ├── MockKeepAliveTimeoutListener.h ├── RequestBodyForByteBufferUnitTest.cpp ├── RequestBodyForSharedPtrByteBufferUnitTest.cpp ├── RequestBodyForSharedPtrStreamUnitTest.cpp ├── RequestBodyForSharedPtrStringUnitTest.cpp ├── RequestBodyForStreamUnitTest.cpp ├── RequestBodyForStringUnitTest.cpp ├── RequestBodyUnitTest.cpp ├── RequestUnitTest.cpp ├── ResponseBodyUnitTest.cpp ├── ResponseUnitTest.cpp ├── common ├── BaseLoggerUnitTest.cpp ├── ByteArrayBufferUnitTest.cpp ├── CacheInfoWithDataSizeUnitTest.cpp ├── CacheManagerMultiThreadUnitTest.cpp ├── CacheManagerUnitTest.cpp ├── CommonExceptionUnitTest.cpp ├── CoreLoggerUnitTest.cpp ├── DefaultLogWriterUnitTest.cpp ├── FileUtilMultiThreadUnitTest.cpp ├── FileUtilUnitTest.cpp ├── LruCacheByDataSizeStrategyUnitTest.cpp ├── ProjectVersionUnitTest.cpp └── StringUtilTest.cpp ├── db ├── ContentValuesUnitTest.cpp ├── SqlExceptionUnitTest.cpp └── SqliteQueryBuilderUnitTest.cpp ├── executorservice ├── BlockingQueueUnitTest.cpp ├── FutureTaskTypeParameterizedUnitTest.cpp └── QueuedThreadPoolUnitTest.cpp └── messagedigest ├── DigestUtilUnitTest.cpp └── MessageDigestExceptionUnitTest.cpp /.gitattributes: -------------------------------------------------------------------------------- 1 | # Set default behaviour, in case users don't have core.autocrlf set. 2 | # Handle line endings automatically for files detected as text 3 | # and leave all files detected as binary untouched. 4 | * text=auto 5 | 6 | # Explicitly declare text files we want to always be normalized and converted 7 | # to native line endings on checkout. (Convert crlf => lf) 8 | *.txt text 9 | *.cpp text 10 | *.cxx text 11 | *.c++ text 12 | *.c text 13 | *.cc text 14 | *.h text 15 | *.hpp text 16 | *.h++ text 17 | *.hh text 18 | *.cmd text 19 | *.sln text 20 | *.vcproj text 21 | *.vcxproj text 22 | *.vcxproj.filters text 23 | *.page text 24 | *.html text 25 | *.xhtml text 26 | *.css text 27 | *.js text 28 | *.progen text 29 | *.xml text 30 | *.xsd text 31 | *.template text 32 | *.properties text 33 | *.ini text 34 | *.vxbuild text 35 | 36 | # Denote all files that are truly binary and should not be modified. 37 | *.slo binary 38 | *.lo binary 39 | *.o binary 40 | *.obj binary 41 | *.so binary 42 | *.dylib binary 43 | *.dll binary 44 | *.lai binary 45 | *.la binary 46 | *.a binary 47 | *.lib binary 48 | *.exe binary 49 | *.out binary 50 | *.app binary 51 | *.gch binary 52 | *.pch binary 53 | *.bin binary 54 | *.mc binary 55 | *.png binary 56 | *.jpg binary 57 | *.gif binary 58 | -------------------------------------------------------------------------------- /.github/issue_template.md: -------------------------------------------------------------------------------- 1 | ### Brief overview 2 | ### Expected behavior 3 | ### Actual behavior 4 | ### Steps to reproduce 5 | ### Specifications like the version of the project, operating system, or hardware etc. 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | CMakeCache.txt 2 | CMakeFiles 3 | CMakeScripts 4 | Makefile 5 | cmake_install.cmake 6 | install_manifest.txt 7 | cmake_* 8 | nbproject/ 9 | build/ 10 | _backup 11 | _staging 12 | _build 13 | _install 14 | _external 15 | 16 | # IntelliJ project files 17 | **/.idea/* 18 | *.iml 19 | 20 | .DS_Store 21 | 22 | # Share code style settings with others 23 | !**/.idea/codeStyleSettings.xml 24 | 25 | # Share file templates with others 26 | !**/.idea/fileTemplates/ 27 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # This file can be validated on: 2 | # http://lint.travis-ci.org/ 3 | 4 | os: 5 | - linux 6 | - osx 7 | language: cpp 8 | cache: ccache 9 | # before_cache: 10 | # # print statistics before uploading new cache 11 | # - ccache --show-stats 12 | compiler: 13 | - gcc 14 | - clang 15 | sudo: false 16 | # install latest CMake (default of trusty is too outdated) 17 | before_install: 18 | - if [ $TRAVIS_OS_NAME = linux ]; then mkdir $HOME/usr; fi 19 | - if [ $TRAVIS_OS_NAME = linux ]; then export PATH="$HOME/usr/bin:$PATH"; fi 20 | - if [ $TRAVIS_OS_NAME = linux ]; then wget https://cmake.org/files/v3.7/cmake-3.7.2-Linux-x86_64.sh; fi 21 | - if [ $TRAVIS_OS_NAME = linux ]; then chmod +x cmake-3.7.2-Linux-x86_64.sh; fi 22 | - if [ $TRAVIS_OS_NAME = linux ]; then ./cmake-3.7.2-Linux-x86_64.sh --prefix=$HOME/usr --exclude-subdir --skip-license; fi 23 | - if [ $TRAVIS_OS_NAME = linux ]; then cmake --version; fi 24 | # # Install ccache on osx 25 | # - if [ "$TRAVIS_OS_NAME" == "osx" ]; then brew install ccache; fi 26 | # - if [ "$TRAVIS_OS_NAME" == "osx" ]; then export PATH="/usr/local/opt/ccache/libexec:$PATH"; fi 27 | # - ccache -V && ccache --show-stats && ccache --zero-stats 28 | # install: 29 | # # ccache on OS X needs installation first 30 | # - if [ $TRAVIS_OS_NAME = osx ]; then brew install ccache; export PATH="/usr/local/opt/ccache/libexec:$PATH"; fi 31 | # # reset ccache statistics 32 | # - ccache --zero-stats 33 | script: 34 | - set -e 35 | - ./scripts/01_install_dependencies.sh 36 | - ./scripts/02_run_alltests.sh 37 | - ./scripts/03_run_samples.sh 38 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributing Guide 2 | ================== 3 | :+1::tada: First off, thanks for taking the time to contribute! :tada::+1: 4 | 5 | Issue Tracker 6 | ------------- 7 | 8 | We use the [issue tracker](https://github.com/sony/easyhttpcpp/issues) hosted in 9 | [EasyHttp](https://github.com/sony/easyhttpcpp) repository. 10 | 11 | If you encounter any bugs, or come up with any feature requests, please first search if there is an already existing 12 | issue. If you can not find any, please feel free to post a new issue. 13 | 14 | Pull Request 15 | ------------ 16 | 17 | We appreciate contributors in the community, that are willing to improve EasyHttp. When submitting code, 18 | please make every effort to follow existing conventions and style in order to keep the code as readable as possible. 19 | 20 | We follow the development style used in many GitHub repositories. 21 | 22 | 1. Search existing issues and/or pull requests in the [GitHub repository](https://github.com/sony/easyhttpcpp). 23 | 24 | 2. If it doesn't exist, post an issue for the feature proposal. 25 | 26 | 3. Fork the repository, and develop your feature in the forked repo. 27 | 28 | 4. Create a pull request of your development branch to EasyHttp's `master` branch. 29 | Our maintainers will then review your changes. 30 | 31 | 5. Once your change is finalized, the maintainer will merge your change. -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Sony Corporation 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 2.1.0 2 | -------------------------------------------------------------------------------- /cmake/AppleToolchain.cmake: -------------------------------------------------------------------------------- 1 | # Cross-compilation loader for Apple 2 | # 3 | # This file is passed to cmake on the command line via 4 | # -DCMAKE_TOOLCHAIN_FILE. 5 | 6 | # OpenSSL must be downloaded manually: brew install openssl 7 | execute_process(COMMAND brew --prefix openssl OUTPUT_VARIABLE BREW_OPENSSL_DIR OUTPUT_STRIP_TRAILING_WHITESPACE) 8 | 9 | set(OPENSSL_ROOT_DIR "${BREW_OPENSSL_DIR}") 10 | set(OPENSSL_INCLUDE_DIR "${BREW_OPENSSL_DIR}/include") 11 | 12 | set(CMAKE_INCLUDE_PATH ${OPENSSL_INCLUDE_DIR}) 13 | set(CMAKE_LIBRARY_PATH "${OPENSSL_ROOT_DIR}/lib") 14 | 15 | include_directories( 16 | "${OPENSSL_INCLUDE_DIR}" 17 | ) 18 | 19 | link_directories( 20 | "${OPENSSL_ROOT_DIR}/lib" 21 | ) 22 | -------------------------------------------------------------------------------- /cmake/easyhttpcppeasyhttpConfig.cmake.in: -------------------------------------------------------------------------------- 1 | include("${CMAKE_CURRENT_LIST_DIR}/@CMAKE_PROJECT_NAME@@LIBRARY_TARGET_NAME@Targets.cmake") -------------------------------------------------------------------------------- /doc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (DOXYGEN_FOUND) 2 | set(DOC_OUTPUT_DIR ${CMAKE_INSTALL_PREFIX}/doc/api CACHE PATH "API documentation directory") 3 | set(DOXYGEN_OUTPUT ${APIDOC_DIR}/html/index.html) 4 | 5 | set(DOXYFILE_IN ${PROJECT_SOURCE_DIR}/doc/Doxyfile.in) 6 | set(DOXYFILE ${CMAKE_BINARY_DIR}/Doxyfile) 7 | 8 | configure_file(${DOXYFILE_IN} ${DOXYFILE} @ONLY) 9 | 10 | file(MAKE_DIRECTORY ${DOC_OUTPUT_DIR}/html) 11 | 12 | add_custom_target(doc 13 | COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYFILE} 14 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 15 | COMMENT "Generating API documentation with Doxygen" 16 | VERBATIM 17 | ) 18 | endif (DOXYGEN_FOUND) 19 | -------------------------------------------------------------------------------- /include/easyhttpcpp/Connection.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_CONNECTION_H_INCLUDED 6 | #define EASYHTTPCPP_CONNECTION_H_INCLUDED 7 | 8 | #include 9 | 10 | #include "Poco/AutoPtr.h" 11 | #include "Poco/RefCountedObject.h" 12 | 13 | namespace easyhttpcpp { 14 | 15 | /** 16 | * @brief A Connection store http connection information. 17 | */ 18 | class Connection : public Poco::RefCountedObject { 19 | public: 20 | typedef Poco::AutoPtr Ptr; 21 | 22 | virtual ~Connection() 23 | { 24 | } 25 | 26 | /** 27 | * @brief Get http protocol (ex. "HTTP/1.1") 28 | * @return protocol string. 29 | */ 30 | virtual const std::string& getProtocol() const = 0; 31 | }; 32 | 33 | } /* namespace easyhttpcpp */ 34 | 35 | #endif /* EASYHTTPCPP_CONNECTION_H_INCLUDED */ 36 | -------------------------------------------------------------------------------- /include/easyhttpcpp/CrlCheckPolicy.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_CRLCHECKPOLICY_H_INCLUDED 6 | #define EASYHTTPCPP_CRLCHECKPOLICY_H_INCLUDED 7 | 8 | namespace easyhttpcpp { 9 | 10 | enum CrlCheckPolicy { 11 | CrlCheckPolicyNoCheck = 0, 12 | CrlCheckPolicyCheckSoftFail, 13 | CrlCheckPolicyCheckHardFail 14 | }; 15 | 16 | } /* namespace easyhttpcpp */ 17 | 18 | #endif /* EASYHTTPCPP_CRLCHECKPOLICY_H_INCLUDED */ 19 | -------------------------------------------------------------------------------- /include/easyhttpcpp/HttpAuthenticatorCallback.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_HTTPAUTHENTICATORCALLBACK_H_INCLUDED 6 | #define EASYHTTPCPP_HTTPAUTHENTICATORCALLBACK_H_INCLUDED 7 | 8 | #include 9 | 10 | #include "Poco/AutoPtr.h" 11 | #include "Poco/RefCountedObject.h" 12 | 13 | #include "easyhttpcpp/HttpException.h" 14 | 15 | namespace easyhttpcpp { 16 | 17 | /** 18 | * @class HttpAuthenticatorCallback HttpAuthenticatorCallback.h "easyhttpcpp/HttpAuthenticatorCallback.h" 19 | * 20 | * Completion callback class for HttpAuthenticator. 21 | */ 22 | class HttpAuthenticatorCallback : public Poco::RefCountedObject { 23 | public: 24 | /** 25 | * A "smart" pointer for Loader to facilitate reference counting based garbage collection. 26 | */ 27 | typedef Poco::AutoPtr Ptr; 28 | 29 | virtual ~HttpAuthenticatorCallback() 30 | { 31 | } 32 | 33 | /** 34 | * Called when HttpAuthenticator completes operation. 35 | * 36 | * @param pWhat the exception occurred or null if the operation succeeded. 37 | * @param authorization the authorization or empty if an error occurred. 38 | */ 39 | virtual void onComplete(HttpException::Ptr pWhat, const std::string& authorization) = 0; 40 | }; 41 | 42 | } /* namespace easyhttpcpp */ 43 | 44 | #endif /* EASYHTTPCPP_HTTPAUTHENTICATORCALLBACK_H_INCLUDED */ 45 | -------------------------------------------------------------------------------- /include/easyhttpcpp/HttpAuthenticatorTypeDefs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_HTTPAUTHENTICATORTYPEDEFS_H_INCLUDED 6 | #define EASYHTTPCPP_HTTPAUTHENTICATORTYPEDEFS_H_INCLUDED 7 | 8 | #include 9 | 10 | #include "Poco/SharedPtr.h" 11 | 12 | #include "easyhttpcpp/common/Future.h" 13 | 14 | namespace easyhttpcpp { 15 | 16 | typedef Poco::SharedPtr > HttpAuthorizationFuturePtr; 17 | 18 | } /* namespace easyhttpcpp */ 19 | 20 | #endif /* EASYHTTPCPP_HTTPAUTHENTICATORTYPEDEFS_H_INCLUDED */ 21 | -------------------------------------------------------------------------------- /include/easyhttpcpp/HttpCache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_HTTPCACHE_H_INCLUDED 6 | #define EASYHTTPCPP_HTTPCACHE_H_INCLUDED 7 | 8 | #include 9 | 10 | #include "Poco/AutoPtr.h" 11 | #include "Poco/Path.h" 12 | #include "Poco/RefCountedObject.h" 13 | #include "Poco/Path.h" 14 | 15 | #include "easyhttpcpp/HttpExports.h" 16 | 17 | namespace easyhttpcpp { 18 | 19 | class EASYHTTPCPP_HTTP_API HttpCache : public Poco::RefCountedObject { 20 | public: 21 | typedef Poco::AutoPtr Ptr; 22 | 23 | /** 24 | * 25 | */ 26 | virtual ~HttpCache(); 27 | 28 | /** 29 | * 30 | * @param directory 31 | * @param maxSize 32 | * @return 33 | */ 34 | static HttpCache::Ptr createCache(const Poco::Path& path, size_t maxSize); 35 | 36 | /** 37 | * 38 | * @return 39 | */ 40 | virtual const Poco::Path& getPath() const = 0; 41 | 42 | /** 43 | * 44 | */ 45 | virtual void evictAll() = 0; 46 | 47 | /** 48 | * 49 | * @return 50 | */ 51 | virtual size_t getMaxSize() const = 0; 52 | 53 | /** 54 | * 55 | * @return 56 | */ 57 | virtual size_t getSize() = 0; 58 | 59 | }; 60 | 61 | } /* namespace easyhttpcpp */ 62 | 63 | #endif /* EASYHTTPCPP_HTTPCACHE_H_INCLUDED */ 64 | -------------------------------------------------------------------------------- /include/easyhttpcpp/HttpCacheUpdateCheckPolicy.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_HTTPCACHEUPDATECHECKPOLICY_H_INCLUDED 6 | #define EASYHTTPCPP_HTTPCACHEUPDATECHECKPOLICY_H_INCLUDED 7 | 8 | namespace easyhttpcpp { 9 | 10 | /* 11 | * @enum HttpCacheUpdateCheckPolicy HttpCacheUpdateCheckPolicy.h "easyhttpcpp/HttpCacheUpdateCheckPolicy.h" 12 | * 13 | * Defines the policy to be used when a network request couldn't be made to check for updates to the cached data. 14 | * This maybe due to network error, server being down or any other error. 15 | */ 16 | enum HttpCacheUpdateCheckPolicy { 17 | /** 18 | * Directs the Http to return the cached data (if available) when a network request couldn't be made to 19 | * check for updates to the cached data. The cached data might not be the same as the latest data present on the 20 | * remote server. 21 | */ 22 | HttpCacheUpdateCheckPolicyReturnCacheOnError, 23 | /** 24 | * Directs the Http to abort when a network request couldn't be made to check for updates to the 25 | * cached data. 26 | */ 27 | HttpCacheUpdateCheckPolicyAbortOnError 28 | }; 29 | 30 | } /* namespace easyhttpcpp */ 31 | 32 | #endif /* EASYHTTPCPP_HTTPCACHEUPDATECHECKPOLICY_H_INCLUDED */ 33 | -------------------------------------------------------------------------------- /include/easyhttpcpp/HttpException.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_HTTPEXCEPTION_H_INCLUDED 6 | #define EASYHTTPCPP_HTTPEXCEPTION_H_INCLUDED 7 | 8 | #include "easyhttpcpp/common/CoreException.h" 9 | #include "easyhttpcpp/HttpExports.h" 10 | 11 | namespace easyhttpcpp { 12 | 13 | EASYHTTPCPP_DECLARE_EXCEPTION_SUB_GROUP(EASYHTTPCPP_HTTP_API, HttpException, easyhttpcpp::common::CoreException) 14 | 15 | EASYHTTPCPP_DECLARE_EXCEPTION(EASYHTTPCPP_HTTP_API, HttpIllegalArgumentException, HttpException) 16 | 17 | EASYHTTPCPP_DECLARE_EXCEPTION(EASYHTTPCPP_HTTP_API, HttpIllegalStateException, HttpException) 18 | 19 | EASYHTTPCPP_DECLARE_EXCEPTION(EASYHTTPCPP_HTTP_API, HttpExecutionException, HttpException) 20 | 21 | EASYHTTPCPP_DECLARE_EXCEPTION(EASYHTTPCPP_HTTP_API, HttpTimeoutException, HttpException) 22 | 23 | EASYHTTPCPP_DECLARE_EXCEPTION(EASYHTTPCPP_HTTP_API, HttpSslException, HttpException) 24 | 25 | EASYHTTPCPP_DECLARE_EXCEPTION(EASYHTTPCPP_HTTP_API, HttpConnectionRetryException, HttpException) 26 | 27 | } /* namespace easyhttpcpp */ 28 | 29 | #endif /* EASYHTTPCPP_HTTPEXCEPTION_H_INCLUDED */ 30 | -------------------------------------------------------------------------------- /include/easyhttpcpp/HttpExports.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_HTTPEXPORTS_H_INCLUDED 6 | #define EASYHTTPCPP_HTTPEXPORTS_H_INCLUDED 7 | 8 | #ifdef EASYHTTPCPP_API_EXPORTS 9 | #include "easyhttpcpp/common/CoreExports.h" 10 | #endif 11 | 12 | namespace easyhttpcpp { 13 | 14 | #if defined(_WIN32) && defined(EASYHTTPCPP_DLL) 15 | #ifdef EASYHTTPCPP_HTTP_API_EXPORTS 16 | #define EASYHTTPCPP_HTTP_API __declspec(dllexport) 17 | #else 18 | #define EASYHTTPCPP_HTTP_API __declspec(dllimport) 19 | #endif 20 | #endif 21 | 22 | #ifndef EASYHTTPCPP_HTTP_API 23 | #define EASYHTTPCPP_HTTP_API 24 | #endif 25 | 26 | #if defined(_WIN32) && defined(EASYHTTPCPP_DLL_TESTS) 27 | #ifdef EASYHTTPCPP_HTTP_API_EXPORTS 28 | #define EASYHTTPCPP_HTTP_INTERNAL_API __declspec(dllexport) 29 | #else 30 | #define EASYHTTPCPP_HTTP_INTERNAL_API __declspec(dllimport) 31 | #endif 32 | #endif 33 | 34 | #ifndef EASYHTTPCPP_HTTP_INTERNAL_API 35 | #define EASYHTTPCPP_HTTP_INTERNAL_API 36 | #endif 37 | 38 | } /* namespace easyhttpcpp */ 39 | 40 | #endif /* EASYHTTPCPP_HTTPEXPORTS_H_INCLUDED */ 41 | 42 | -------------------------------------------------------------------------------- /include/easyhttpcpp/Interceptor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_INTERCEPTOR_H_INCLUDED 6 | #define EASYHTTPCPP_INTERCEPTOR_H_INCLUDED 7 | 8 | #include "Poco/AutoPtr.h" 9 | #include "Poco/RefCountedObject.h" 10 | 11 | #include "easyhttpcpp/Connection.h" 12 | #include "easyhttpcpp/Request.h" 13 | #include "easyhttpcpp/Response.h" 14 | 15 | namespace easyhttpcpp { 16 | 17 | class Interceptor : public Poco::RefCountedObject { 18 | public: 19 | typedef Poco::AutoPtr Ptr; 20 | 21 | class Chain; 22 | 23 | virtual ~Interceptor() 24 | { 25 | } 26 | 27 | virtual Response::Ptr intercept(Chain& chain) = 0; 28 | 29 | public: 30 | 31 | class Chain : public Poco::RefCountedObject { 32 | public: 33 | typedef Poco::AutoPtr Ptr; 34 | 35 | virtual ~Chain() 36 | { 37 | } 38 | 39 | virtual Request::Ptr getRequest() const = 0; 40 | 41 | virtual Connection::Ptr getConnection() const = 0; 42 | 43 | virtual Response::Ptr proceed(Request::Ptr pRequest) = 0; 44 | }; 45 | 46 | }; 47 | 48 | } /* namespace easyhttpcpp */ 49 | 50 | #endif /* EASYHTTPCPP_INTERCEPTOR_H_INCLUDED */ 51 | -------------------------------------------------------------------------------- /include/easyhttpcpp/LoggingInterceptor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_LOGGINGINTERCEPTOR_H_INCLUDED 6 | #define EASYHTTPCPP_LOGGINGINTERCEPTOR_H_INCLUDED 7 | 8 | #include "easyhttpcpp/HttpExports.h" 9 | #include "easyhttpcpp/Interceptor.h" 10 | 11 | namespace easyhttpcpp { 12 | 13 | enum LoggingInterceptorType { 14 | LoggingInterceptorTypeCall, 15 | LoggingInterceptorTypeNetwork 16 | }; 17 | 18 | class EASYHTTPCPP_HTTP_API LoggingInterceptor : public Interceptor { 19 | public: 20 | virtual ~LoggingInterceptor() 21 | { 22 | } 23 | }; 24 | 25 | } /* namespace easyhttpcpp */ 26 | 27 | #endif /* EASYHTTPCPP_LOGGINGINTERCEPTOR_H_INCLUDED */ 28 | -------------------------------------------------------------------------------- /include/easyhttpcpp/LoggingInterceptorFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_LOGGINGINTERCEPTORFACTORY_H_INCLUDED 6 | #define EASYHTTPCPP_LOGGINGINTERCEPTORFACTORY_H_INCLUDED 7 | 8 | #include "easyhttpcpp/LoggingInterceptor.h" 9 | #include "easyhttpcpp/HttpExports.h" 10 | 11 | namespace easyhttpcpp { 12 | 13 | class EASYHTTPCPP_HTTP_API LoggingInterceptorFactory { 14 | public: 15 | LoggingInterceptorFactory(); 16 | virtual ~LoggingInterceptorFactory(); 17 | 18 | virtual LoggingInterceptor::Ptr interceptor(LoggingInterceptorType interceptorType); 19 | private: 20 | }; 21 | 22 | } /* namespace easyhttpcpp */ 23 | 24 | 25 | #endif /* EASYHTTPCPP_LOGGINGINTERCEPTORFACTORY_H_INCLUDED */ 26 | -------------------------------------------------------------------------------- /include/easyhttpcpp/MediaType.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_MEDIATYPE_H_INCLUDED 6 | #define EASYHTTPCPP_MEDIATYPE_H_INCLUDED 7 | 8 | #include "Poco/AutoPtr.h" 9 | #include "Poco/RefCountedObject.h" 10 | 11 | #include "easyhttpcpp/HttpExports.h" 12 | 13 | namespace easyhttpcpp { 14 | 15 | /** 16 | * @brief A MediaType preserve Content-Type. 17 | */ 18 | class EASYHTTPCPP_HTTP_API MediaType : public Poco::RefCountedObject { 19 | public: 20 | typedef Poco::AutoPtr Ptr; 21 | 22 | /** 23 | * 24 | * @param contentType Content-Type 25 | */ 26 | MediaType(const std::string& contentType); 27 | 28 | /** 29 | * 30 | */ 31 | virtual ~MediaType(); 32 | 33 | /** 34 | * @brief Get Content-Type by string 35 | * @return string 36 | */ 37 | virtual std::string toString(); 38 | private: 39 | MediaType(); 40 | std::string m_contentType; 41 | }; 42 | 43 | } /* namespace easyhttpcpp */ 44 | 45 | #endif /* EASYHTTPCPP_MEDIATYPE_H_INCLUDED */ 46 | -------------------------------------------------------------------------------- /include/easyhttpcpp/ResponseBodyStream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_RESPONSEBODYSTREAM_H_INCLUDED 6 | #define EASYHTTPCPP_RESPONSEBODYSTREAM_H_INCLUDED 7 | 8 | #include 9 | 10 | #ifdef _WIN32 11 | #include 12 | typedef SSIZE_T ssize_t; 13 | #endif 14 | 15 | #include "Poco/AutoPtr.h" 16 | #include "Poco/RefCountedObject.h" 17 | 18 | namespace easyhttpcpp { 19 | 20 | /** 21 | * @brief A ResponseBodyStream preserve Http response body stream. 22 | */ 23 | class ResponseBodyStream : public Poco::RefCountedObject { 24 | public: 25 | typedef Poco::AutoPtr Ptr; 26 | 27 | virtual ~ResponseBodyStream() 28 | { 29 | } 30 | 31 | /** 32 | * @brief Read response body date from stream 33 | * @param pBuffer read buffer 34 | * @param readBytes request to read bytes 35 | * @return actually read bytes. If is eof, return -1. 36 | * @exception HttpIllegalStateException 37 | * @exception HttpExecutionException 38 | */ 39 | virtual ssize_t read(char* pBuffer, size_t readBytes) = 0; 40 | 41 | /** 42 | * @brief check eof 43 | * @return If eof, return true. 44 | * @exception HttpIllegalStateException 45 | */ 46 | virtual bool isEof() = 0; 47 | 48 | /** 49 | * @brief Close stream. 50 | * 51 | * after close, can not read response body. 52 | */ 53 | virtual void close() = 0; 54 | }; 55 | 56 | } /* namespace easyhttpcpp */ 57 | 58 | #endif /* EASYHTTPCPP_RESPONSEBODYSTREAM_H_INCLUDED */ 59 | -------------------------------------------------------------------------------- /include/easyhttpcpp/ResponseCallback.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_RESPONSECALLBACK_H_INCLUDED 6 | #define EASYHTTPCPP_RESPONSECALLBACK_H_INCLUDED 7 | 8 | #include "Poco/AutoPtr.h" 9 | #include "Poco/RefCountedObject.h" 10 | 11 | #include "easyhttpcpp/HttpException.h" 12 | #include "easyhttpcpp/Response.h" 13 | 14 | namespace easyhttpcpp { 15 | 16 | /** 17 | * @class ResponseCallback ResponseCallback.h "easyhttpcpp/ResponseCallback.h" 18 | * 19 | * Completion callback class for Call::executeAsync. 20 | */ 21 | class ResponseCallback : public Poco::RefCountedObject { 22 | public: 23 | /** 24 | * A "smart" pointer to facilitate reference counting based garbage collection. 25 | */ 26 | typedef Poco::AutoPtr Ptr; 27 | 28 | virtual ~ResponseCallback() 29 | { 30 | } 31 | 32 | /** 33 | * Called when the Http response was returned by the remote server. 34 | * 35 | * @param pResponse Response object that returned by remote server. 36 | */ 37 | virtual void onResponse(Response::Ptr pResponse) = 0; 38 | 39 | /** 40 | * Called when the exception occurred in executing Call::executeAsync. 41 | * 42 | * @param pWhat the exception that occurred in executing Call::executeAsync. 43 | */ 44 | virtual void onFailure(HttpException::Ptr pWhat) = 0; 45 | }; 46 | 47 | } /* namespace easyhttpcpp */ 48 | 49 | #endif /* EASYHTTPCPP_RESPONSECALLBACK_H_INCLUDED */ 50 | -------------------------------------------------------------------------------- /include/easyhttpcpp/common/AtomicBool.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_COMMON_ATOMICBOOL_H_INCLUDED 6 | #define EASYHTTPCPP_COMMON_ATOMICBOOL_H_INCLUDED 7 | 8 | #include "Poco/Mutex.h" 9 | 10 | #include "easyhttpcpp/common/CommonExports.h" 11 | 12 | namespace easyhttpcpp { 13 | namespace common { 14 | 15 | class EASYHTTPCPP_COMMON_API AtomicBool { 16 | public: 17 | AtomicBool(bool initValue); 18 | virtual ~AtomicBool(); 19 | 20 | virtual void set(bool newValue); 21 | virtual bool get() const; 22 | 23 | /** 24 | * Atomically sets the value to the given updated value if the current value == the expected value. 25 | * 26 | * @param expect the expected value. 27 | * @param update the new value. 28 | * @return true if successful. False return indicates that the actual value was not equal to the expected value. 29 | */ 30 | virtual bool compareAndSet(bool expect, bool update); 31 | 32 | private: 33 | mutable Poco::FastMutex m_instanceMutex; 34 | bool m_value; 35 | }; 36 | 37 | } /* namespace common */ 38 | } /* namespace easyhttpcpp */ 39 | 40 | #endif /* EASYHTTPCPP_COMMON_ATOMICBOOL_H_INCLUDED */ 41 | -------------------------------------------------------------------------------- /include/easyhttpcpp/common/ByteArrayBuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_COMMON_BYTEARRAYBUFFER_H_INCLUDED 6 | #define EASYHTTPCPP_COMMON_BYTEARRAYBUFFER_H_INCLUDED 7 | 8 | #include 9 | 10 | #include "easyhttpcpp/common/CommonExports.h" 11 | #include "easyhttpcpp/common/Typedef.h" 12 | 13 | namespace easyhttpcpp { 14 | namespace common { 15 | 16 | class EASYHTTPCPP_COMMON_API ByteArrayBuffer { 17 | public: 18 | ByteArrayBuffer(); 19 | ByteArrayBuffer(size_t capacity); 20 | ByteArrayBuffer(const std::string& src); 21 | virtual ~ByteArrayBuffer(); 22 | 23 | Byte* getBuffer() const; 24 | size_t getBufferSize() const; 25 | size_t getWrittenDataSize() const; 26 | void setWrittenDataSize(size_t newWrittenDataSize); 27 | size_t write(const Byte* pBuffer, size_t size); 28 | void clear(); 29 | std::string toString() const; 30 | 31 | bool copyTo(ByteArrayBuffer& dst) const; 32 | bool copyFrom(const std::string& src); 33 | bool copyFrom(const ByteArrayBuffer& src); 34 | 35 | protected: 36 | Byte* expand(size_t newBufferSize); 37 | 38 | Byte* m_pBuffer; 39 | size_t m_bufferSize; 40 | size_t m_writtenDataSize; 41 | }; 42 | 43 | } /* namespace common */ 44 | } /* namespace easyhttpcpp */ 45 | 46 | #endif /* EASYHTTPCPP_COMMON_BYTEARRAYBUFFER_H_INCLUDED */ 47 | -------------------------------------------------------------------------------- /include/easyhttpcpp/common/Cache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_COMMON_CACHE_H_INCLUDED 6 | #define EASYHTTPCPP_COMMON_CACHE_H_INCLUDED 7 | 8 | #include 9 | #include 10 | 11 | #include "Poco/AutoPtr.h" 12 | #include "Poco/RefCountedObject.h" 13 | #include "Poco/SharedPtr.h" 14 | 15 | #include "easyhttpcpp/common/ByteArrayBuffer.h" 16 | #include "easyhttpcpp/common/CacheMetadata.h" 17 | 18 | namespace easyhttpcpp { 19 | namespace common { 20 | 21 | class Cache : public Poco::RefCountedObject { 22 | public: 23 | typedef Poco::AutoPtr Ptr; 24 | 25 | virtual ~Cache() 26 | { 27 | } 28 | 29 | virtual bool getMetadata(const std::string& key, CacheMetadata::Ptr& pCacheMetadata) = 0; 30 | virtual bool getData(const std::string& key, std::istream*& pStream) = 0; 31 | virtual bool get(const std::string& key, CacheMetadata::Ptr& pCacheMetadata, std::istream*& pStream) = 0; 32 | virtual bool putMetadata(const std::string& key, CacheMetadata::Ptr pCacheMetadata) = 0; 33 | virtual bool put(const std::string& key, CacheMetadata::Ptr pCacheMetadata, const std::string& path) = 0; 34 | virtual bool put(const std::string& key, CacheMetadata::Ptr pCacheMetadata, 35 | Poco::SharedPtr pData) = 0; 36 | virtual bool remove(const std::string& key) = 0; 37 | virtual void releaseData(const std::string& key) = 0; 38 | virtual bool purge(bool mayDeleteIfBusy) = 0; 39 | }; 40 | 41 | } /* namespace common */ 42 | } /* namespace easyhttpcpp */ 43 | 44 | #endif /* EASYHTTPCPP_COMMON_CACHE_H_INCLUDED */ 45 | -------------------------------------------------------------------------------- /include/easyhttpcpp/common/CacheInfoWithDataSize.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_COMMON_CACHEINFOWITHDATASIZE_H_INCLUDED 6 | #define EASYHTTPCPP_COMMON_CACHEINFOWITHDATASIZE_H_INCLUDED 7 | 8 | #include 9 | 10 | #include "Poco/AutoPtr.h" 11 | #include "Poco/RefCountedObject.h" 12 | 13 | #include "easyhttpcpp/common/CommonExports.h" 14 | 15 | namespace easyhttpcpp { 16 | namespace common { 17 | 18 | class EASYHTTPCPP_COMMON_API CacheInfoWithDataSize : public Poco::RefCountedObject { 19 | public: 20 | typedef Poco::AutoPtr Ptr; 21 | 22 | CacheInfoWithDataSize(const std::string& key, size_t dataSize = 0); 23 | CacheInfoWithDataSize(const CacheInfoWithDataSize& original); 24 | virtual ~CacheInfoWithDataSize(); 25 | 26 | CacheInfoWithDataSize& operator=(const CacheInfoWithDataSize& original); 27 | bool operator==(const CacheInfoWithDataSize& target) const; 28 | 29 | void setKey(const std::string& key); 30 | const std::string& getKey() const; 31 | void setDataSize(size_t dataSize); 32 | size_t getDataSize() const; 33 | 34 | protected: 35 | void copyFrom(const CacheInfoWithDataSize& original); 36 | 37 | private: 38 | std::string m_key; 39 | size_t m_dataSize; 40 | }; 41 | 42 | } /* namespace common */ 43 | } /* namespace easyhttpcpp */ 44 | 45 | #endif /* EASYHTTPCPP_COMMON_CACHEINFOWITHDATASIZE_H_INCLUDED */ 46 | -------------------------------------------------------------------------------- /include/easyhttpcpp/common/CacheMetadata.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_COMMON_CACHEMETADATA_H_INCLUDED 6 | #define EASYHTTPCPP_COMMON_CACHEMETADATA_H_INCLUDED 7 | 8 | #include 9 | 10 | #include "Poco/AutoPtr.h" 11 | #include "Poco/RefCountedObject.h" 12 | 13 | #include "easyhttpcpp/common/CommonExports.h" 14 | 15 | namespace easyhttpcpp { 16 | namespace common { 17 | 18 | class EASYHTTPCPP_COMMON_API CacheMetadata : public Poco::RefCountedObject { 19 | public: 20 | typedef Poco::AutoPtr Ptr; 21 | 22 | CacheMetadata(); 23 | virtual ~CacheMetadata(); 24 | 25 | void setKey(const std::string& key); 26 | const std::string& getKey() const; 27 | 28 | private: 29 | std::string m_key; 30 | }; 31 | 32 | } /* namespace common */ 33 | } /* namespace easyhttpcpp */ 34 | 35 | #endif /* EASYHTTPCPP_COMMON_CACHEMETADATA_H_INCLUDED */ 36 | -------------------------------------------------------------------------------- /include/easyhttpcpp/common/CacheStrategy.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_COMMON_CACHESTRATEGY_H_INCLUDED 6 | #define EASYHTTPCPP_COMMON_CACHESTRATEGY_H_INCLUDED 7 | 8 | #include "Poco/AutoPtr.h" 9 | #include "Poco/RefCountedObject.h" 10 | #include "Poco/ScopedLock.h" 11 | 12 | #include "easyhttpcpp/common/CacheStrategyListener.h" 13 | 14 | namespace easyhttpcpp { 15 | namespace common { 16 | 17 | // TValue is intended Poco::AutoPtr. 18 | 19 | template 20 | class CacheStrategy : public Poco::RefCountedObject { 21 | public: 22 | typedef Poco::AutoPtr > Ptr; 23 | typedef Poco::ScopedLock > ScopedLock; 24 | 25 | virtual ~CacheStrategy() 26 | { 27 | } 28 | 29 | virtual void setListener(CacheStrategyListener * pListener) = 0; 30 | virtual bool add(const TKey& key, TValue value) = 0; 31 | virtual bool update(const TKey& key, TValue value) = 0; 32 | virtual bool remove(const TKey& key) = 0; 33 | virtual TValue get(const TKey& key) = 0; 34 | virtual bool clear(bool mayDeleteIfBusy) = 0; 35 | }; 36 | 37 | } /* namespace common */ 38 | } /* namespace easyhttpcpp */ 39 | 40 | #endif /* EASYHTTPCPP_COMMON_CACHESTRATEGY_H_INCLUDED */ 41 | -------------------------------------------------------------------------------- /include/easyhttpcpp/common/CacheStrategyListener.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_COMMON_CACHESTRATEGYLISTENER_H_INCLUDED 6 | #define EASYHTTPCPP_COMMON_CACHESTRATEGYLISTENER_H_INCLUDED 7 | 8 | namespace easyhttpcpp { 9 | namespace common { 10 | 11 | template 12 | class CacheStrategyListener { 13 | public: 14 | 15 | virtual ~CacheStrategyListener() 16 | { 17 | } 18 | 19 | virtual bool onAdd(const TKey& key, TValue value) = 0; 20 | virtual bool onUpdate(const TKey& key, TValue value) = 0; 21 | virtual bool onRemove(const TKey& key) = 0; 22 | virtual bool onGet(const TKey& key, TValue value) = 0; 23 | }; 24 | 25 | } /* namespace common */ 26 | } /* namespace easyhttpcpp */ 27 | 28 | #endif /* EASYHTTPCPP_COMMON_CACHESTRATEGYLISTENER_H_INCLUDED */ 29 | -------------------------------------------------------------------------------- /include/easyhttpcpp/common/CommonException.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_COMMON_COMMONEXCEPTION_H_INCLUDED 6 | #define EASYHTTPCPP_COMMON_COMMONEXCEPTION_H_INCLUDED 7 | 8 | #include "easyhttpcpp/common/CommonExports.h" 9 | #include "easyhttpcpp/common/CoreException.h" 10 | 11 | namespace easyhttpcpp { 12 | namespace common { 13 | 14 | EASYHTTPCPP_DECLARE_EXCEPTION_SUB_GROUP(EASYHTTPCPP_COMMON_API, CommonException, CoreException) 15 | 16 | EASYHTTPCPP_DECLARE_EXCEPTION(EASYHTTPCPP_COMMON_API, PocoException, CommonException) 17 | 18 | EASYHTTPCPP_DECLARE_EXCEPTION(EASYHTTPCPP_COMMON_API, StdException, CommonException) 19 | 20 | EASYHTTPCPP_DECLARE_EXCEPTION(EASYHTTPCPP_COMMON_API, FutureIllegalStateException, CommonException) 21 | 22 | EASYHTTPCPP_DECLARE_EXCEPTION(EASYHTTPCPP_COMMON_API, FutureCancellationException, CommonException) 23 | 24 | EASYHTTPCPP_DECLARE_EXCEPTION(EASYHTTPCPP_COMMON_API, FutureExecutionException, CommonException) 25 | 26 | EASYHTTPCPP_DECLARE_EXCEPTION(EASYHTTPCPP_COMMON_API, FutureTimeoutException, CommonException) 27 | 28 | } /* namespace common */ 29 | } /* namespace easyhttpcpp */ 30 | 31 | #endif /* EASYHTTPCPP_COMMON_COMMONEXCEPTION_H_INCLUDED */ 32 | -------------------------------------------------------------------------------- /include/easyhttpcpp/common/CommonExports.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_COMMON_COMMONEXPORTS_H_INCLUDED 6 | #define EASYHTTPCPP_COMMON_COMMONEXPORTS_H_INCLUDED 7 | 8 | #ifdef EASYHTTPCPP_API_EXPORTS 9 | #include "easyhttpcpp/common/CoreExports.h" 10 | #endif 11 | 12 | namespace easyhttpcpp { 13 | namespace common { 14 | 15 | #if defined(_WIN32) && defined(EASYHTTPCPP_DLL) 16 | #ifdef EASYHTTPCPP_COMMON_API_EXPORTS 17 | #define EASYHTTPCPP_COMMON_API __declspec(dllexport) 18 | #else 19 | #define EASYHTTPCPP_COMMON_API __declspec(dllimport) 20 | #endif 21 | #endif 22 | 23 | #ifndef EASYHTTPCPP_COMMON_API 24 | #define EASYHTTPCPP_COMMON_API 25 | #endif 26 | 27 | #if defined(_WIN32) && defined(EASYHTTPCPP_DLL_TESTS) 28 | #ifdef EASYHTTPCPP_COMMON_API_EXPORTS 29 | #define EASYHTTPCPP_CORE_COMMON_INTERNAL_API __declspec(dllexport) 30 | #else 31 | #define EASYHTTPCPP_CORE_COMMON_INTERNAL_API __declspec(dllimport) 32 | #endif 33 | #endif 34 | 35 | #ifndef EASYHTTPCPP_CORE_COMMON_INTERNAL_API 36 | #define EASYHTTPCPP_CORE_COMMON_INTERNAL_API 37 | #endif 38 | 39 | } /* namespace common */ 40 | } /* namespace easyhttpcpp */ 41 | 42 | #endif /* EASYHTTPCPP_COMMON_COMMONEXPORTS_H_INCLUDED */ 43 | 44 | -------------------------------------------------------------------------------- /include/easyhttpcpp/common/CommonMacros.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_COMMON_COMMONMACROS_H_INCLUDED 6 | #define EASYHTTPCPP_COMMON_COMMONMACROS_H_INCLUDED 7 | 8 | namespace easyhttpcpp { 9 | namespace common { 10 | 11 | #define EASYHTTPCPP_STRINGIFY_MACRO(macro) EASYHTTPCPP_STRINGIFY_MACRO_ARG(macro) 12 | #define EASYHTTPCPP_STRINGIFY_MACRO_ARG(macro) #macro "" 13 | 14 | #ifdef _WIN32 15 | #define EASYHTTPCPP_DEPRECATED(message) __declspec(deprecated(message)) 16 | #else 17 | #define EASYHTTPCPP_DEPRECATED(message) __attribute__ ((deprecated(message))) 18 | #endif 19 | } /* namespace common */ 20 | } /* namespace easyhttpcpp */ 21 | 22 | #endif /* EASYHTTPCPP_COMMON_COMMONMACROS_H_INCLUDED */ 23 | -------------------------------------------------------------------------------- /include/easyhttpcpp/common/CoreException.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_COMMON_COREEXCEPTION_H_INCLUDED 6 | #define EASYHTTPCPP_COMMON_COREEXCEPTION_H_INCLUDED 7 | 8 | #include "easyhttpcpp/common/BaseException.h" 9 | #include "easyhttpcpp/common/CommonExports.h" 10 | 11 | namespace easyhttpcpp { 12 | namespace common { 13 | 14 | EASYHTTPCPP_DECLARE_EXCEPTION_GROUP(EASYHTTPCPP_COMMON_API, CoreException) 15 | 16 | } /* namespace common */ 17 | } /* namespace easyhttpcpp */ 18 | 19 | #endif /* EASYHTTPCPP_COMMON_COREEXCEPTION_H_INCLUDED */ 20 | -------------------------------------------------------------------------------- /include/easyhttpcpp/common/CoreExports.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_COMMON_COREEXPORTS_H_INCLUDED 6 | #define EASYHTTPCPP_COMMON_COREEXPORTS_H_INCLUDED 7 | 8 | namespace easyhttpcpp { 9 | namespace common { 10 | 11 | #if defined(_WIN32) && defined(EASYHTTPCPP_DLL) 12 | #ifdef EASYHTTPCPP_API_EXPORTS 13 | #define EASYHTTPCPP_COMMON_API_EXPORTS 14 | #define EASYHTTPCPP_DB_API_EXPORTS 15 | #define EASYHTTPCPP_EXECUTORSERVICE_API_EXPORTS 16 | #define EASYHTTPCPP_HTTP_API_EXPORTS 17 | #define EASYHTTPCPP_MESSAGEDIGEST_API_EXPORTS 18 | #endif 19 | #endif 20 | 21 | } /* namespace easyhttpcpp */ 22 | } /* namespace common */ 23 | 24 | #endif /* EASYHTTPCPP_COMMON_COREEXPORTS_H_INCLUDED */ 25 | 26 | -------------------------------------------------------------------------------- /include/easyhttpcpp/common/DefaultLogWriter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_COMMON_DEFAULTLOGWRITER_H_INCLUDED 6 | #define EASYHTTPCPP_COMMON_DEFAULTLOGWRITER_H_INCLUDED 7 | 8 | #include "Poco/Logger.h" 9 | #include "Poco/FormattingChannel.h" 10 | 11 | #include "easyhttpcpp/common/CommonExports.h" 12 | #include "easyhttpcpp/common/LogWriter.h" 13 | 14 | namespace easyhttpcpp { 15 | namespace common { 16 | 17 | class EASYHTTPCPP_COMMON_API DefaultLogWriter : public LogWriter { 18 | public: 19 | DefaultLogWriter(); 20 | virtual ~DefaultLogWriter(); 21 | virtual const std::string& getName() const; 22 | virtual void log(const std::string& tag, LogLevel level, unsigned int line, const std::string& message); 23 | 24 | private: 25 | std::string createLoggerName(); 26 | Poco::Logger& createLogger(); 27 | Poco::AutoPtr createChannel(); 28 | 29 | std::string m_logWriterName; 30 | Poco::Logger& m_logger; 31 | 32 | }; 33 | 34 | } /* namespace common */ 35 | } /* namespace easyhttpcpp */ 36 | 37 | #endif /* EASYHTTPCPP_COMMON_DEFAULTLOGWRITER_H_INCLUDED */ 38 | -------------------------------------------------------------------------------- /include/easyhttpcpp/common/ExceptionConstants.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_COMMON_EXCEPTIONCONSTANTS_H_INCLUDED 6 | #define EASYHTTPCPP_COMMON_EXCEPTIONCONSTANTS_H_INCLUDED 7 | 8 | #include 9 | 10 | namespace easyhttpcpp { 11 | namespace common { 12 | 13 | class ExceptionConstants { 14 | public: 15 | static const std::string ErrorCodePrefix; 16 | 17 | /** 18 | * Exception group codes 19 | */ 20 | class GroupCode { 21 | public: 22 | static const unsigned int Core; 23 | }; 24 | 25 | /** 26 | * Exception subgroup codes 27 | */ 28 | class SubGroupCode { 29 | public: 30 | static const unsigned int Common; 31 | static const unsigned int Db; 32 | static const unsigned int MessageDigest; 33 | static const unsigned int ExecutorService; 34 | static const unsigned int Http; 35 | }; 36 | 37 | }; 38 | 39 | } /* namespace common */ 40 | } /* namespace easyhttpcpp */ 41 | 42 | #endif /* EASYHTTPCPP_COMMON_EXCEPTIONCONSTANTS_H_INCLUDED */ 43 | -------------------------------------------------------------------------------- /include/easyhttpcpp/common/FileUtil.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_COMMON_FILEUTIL_H_INCLUDED 6 | #define EASYHTTPCPP_COMMON_FILEUTIL_H_INCLUDED 7 | 8 | #include "Poco/File.h" 9 | #include "Poco/Path.h" 10 | 11 | #include "easyhttpcpp/common/CommonExports.h" 12 | 13 | namespace easyhttpcpp { 14 | namespace common { 15 | 16 | class EASYHTTPCPP_COMMON_API FileUtil { 17 | public: 18 | static bool createDirsIfAbsent(const Poco::File& dir); 19 | static bool removeDirsIfPresent(const Poco::Path& dirPath); 20 | static bool removeFileIfPresent(const Poco::File& file); 21 | static bool moveFile(const Poco::File& sourceFile, const Poco::File& destinationFile); 22 | static std::string convertToAbsolutePathString(const std::string& path, bool extendedPrefix = false); 23 | 24 | private: 25 | FileUtil(); 26 | }; 27 | 28 | } /* namespace common */ 29 | } /* namespace easyhttpcpp */ 30 | 31 | #endif /* EASYHTTPCPP_COMMON_FILEUTIL_H_INCLUDED */ 32 | -------------------------------------------------------------------------------- /include/easyhttpcpp/common/LogLevel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_COMMON_LOGLEVEL_H_INCLUDED 6 | #define EASYHTTPCPP_COMMON_LOGLEVEL_H_INCLUDED 7 | 8 | namespace easyhttpcpp { 9 | namespace common { 10 | 11 | enum LogLevel { 12 | LogLevelVerbose, 13 | LogLevelDebug, 14 | LogLevelInfo, 15 | LogLevelWarning, 16 | LogLevelError, 17 | LogLevelSilent 18 | }; 19 | 20 | } /* namespace common */ 21 | } /* namespace easyhttpcpp */ 22 | 23 | #endif /* EASYHTTPCPP_COMMON_LOGLEVEL_H_INCLUDED */ 24 | -------------------------------------------------------------------------------- /include/easyhttpcpp/common/LogWriter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_COMMON_LOGWRITER_H_INCLUDED 6 | #define EASYHTTPCPP_COMMON_LOGWRITER_H_INCLUDED 7 | 8 | #include "Poco/AutoPtr.h" 9 | #include "Poco/RefCountedObject.h" 10 | 11 | #include "easyhttpcpp/common/LogLevel.h" 12 | 13 | namespace easyhttpcpp { 14 | namespace common { 15 | 16 | class LogWriter : public Poco::RefCountedObject { 17 | public: 18 | typedef Poco::AutoPtr Ptr; 19 | 20 | virtual ~LogWriter() 21 | { 22 | } 23 | 24 | virtual const std::string& getName() const = 0; 25 | virtual void log(const std::string& tag, LogLevel level, unsigned int line, const std::string& message) = 0; 26 | }; 27 | 28 | } /* namespace common */ 29 | } /* namespace easyhttpcpp */ 30 | 31 | #endif /* EASYHTTPCPP_COMMON_LOGWRITER_H_INCLUDED */ 32 | -------------------------------------------------------------------------------- /include/easyhttpcpp/common/OpenSslInitializer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_COMMON_OPENSSLINITIALIZER_H_INCLUDED 6 | #define EASYHTTPCPP_COMMON_OPENSSLINITIALIZER_H_INCLUDED 7 | 8 | #ifndef _WIN32 9 | #include "Poco/Crypto/OpenSSLInitializer.h" 10 | #endif // !_WIN32 11 | 12 | namespace easyhttpcpp { 13 | namespace common { 14 | 15 | class OpenSslInitializer { 16 | public: 17 | OpenSslInitializer() 18 | { 19 | } 20 | 21 | #ifndef _WIN32 22 | private: 23 | Poco::Crypto::OpenSSLInitializer m_openSslInitializer; 24 | #endif // !_WIN32 25 | }; 26 | 27 | } /* namespace common */ 28 | } /* namespace easyhttpcpp */ 29 | 30 | #endif /* EASYHTTPCPP_COMMON_OPENSSLINITIALIZER_H_INCLUDED */ 31 | -------------------------------------------------------------------------------- /include/easyhttpcpp/common/ProjectVersion.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_COMMON_COREVERSION_H_INCLUDED 6 | #define EASYHTTPCPP_COMMON_COREVERSION_H_INCLUDED 7 | 8 | #include 9 | 10 | #include "easyhttpcpp/common/CommonExports.h" 11 | 12 | namespace easyhttpcpp { 13 | namespace common { 14 | 15 | class EASYHTTPCPP_COMMON_API ProjectVersion { 16 | public: 17 | static std::string getMajor(); 18 | static std::string getMinor(); 19 | static std::string getPatch(); 20 | static std::string getExtension(); 21 | static std::string asString(); 22 | 23 | private: 24 | ProjectVersion(); 25 | }; 26 | 27 | } /* namespace common */ 28 | } /* namespace easyhttpcpp */ 29 | 30 | #endif /* EASYHTTPCPP_COMMON_COREVERSION_H_INCLUDED */ 31 | -------------------------------------------------------------------------------- /include/easyhttpcpp/common/RefCountedRunnable.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_COMMON_REFCOUNTEDRUNNABLE_H_INCLUDED 6 | #define EASYHTTPCPP_COMMON_REFCOUNTEDRUNNABLE_H_INCLUDED 7 | 8 | #include "Poco/AutoPtr.h" 9 | #include "Poco/RefCountedObject.h" 10 | #include "Poco/Runnable.h" 11 | 12 | namespace easyhttpcpp { 13 | namespace common { 14 | 15 | class RefCountedRunnable : public Poco::Runnable, public Poco::RefCountedObject { 16 | public: 17 | typedef Poco::AutoPtr Ptr; 18 | 19 | }; 20 | 21 | } /* namespace common */ 22 | } /* namespace easyhttpcpp */ 23 | 24 | #endif /* EASYHTTPCPP_COMMON_REFCOUNTEDRUNNABLE_H_INCLUDED */ 25 | -------------------------------------------------------------------------------- /include/easyhttpcpp/common/Typedef.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_COMMON_TYPEDEF_H_INCLUDED 6 | #define EASYHTTPCPP_COMMON_TYPEDEF_H_INCLUDED 7 | 8 | namespace easyhttpcpp { 9 | namespace common { 10 | 11 | typedef unsigned char Byte; 12 | 13 | } /* namespace common */ 14 | } /* namespace easyhttpcpp */ 15 | 16 | #endif /* EASYHTTPCPP_COMMON_TYPEDEF_H_INCLUDED */ 17 | -------------------------------------------------------------------------------- /include/easyhttpcpp/db/AutoSqliteCursor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_DB_AUTOSQLITECURSOR_H_INCLUDED 6 | #define EASYHTTPCPP_DB_AUTOSQLITECURSOR_H_INCLUDED 7 | 8 | #include 9 | 10 | #include "easyhttpcpp/common/CoreLogger.h" 11 | #include "easyhttpcpp/db/SqliteCursor.h" 12 | #include "easyhttpcpp/db/SqlException.h" 13 | 14 | namespace easyhttpcpp { 15 | namespace db { 16 | 17 | class AutoSqliteCursor { 18 | public: 19 | AutoSqliteCursor(SqliteCursor::Ptr pCursor) : m_pCursor(pCursor) 20 | { 21 | } 22 | 23 | virtual ~AutoSqliteCursor() 24 | { 25 | static const std::string Tag = "AutoSqliteCursor"; 26 | // consumes exception since sqlite might be able to work even without closing the cursor as well 27 | try { 28 | if (m_pCursor) { 29 | m_pCursor->close(); 30 | } 31 | } catch (const SqlException& ignored) { 32 | EASYHTTPCPP_LOG_D(Tag, "Error while closing cursor. Ignored. Details: %s", ignored.getMessage().c_str()); 33 | } 34 | } 35 | 36 | private: 37 | SqliteCursor::Ptr m_pCursor; 38 | }; 39 | 40 | } /* namespace db */ 41 | } /* namespace easyhttpcpp */ 42 | 43 | #endif /* EASYHTTPCPP_DB_AUTOSQLITECURSOR_H_INCLUDED */ 44 | -------------------------------------------------------------------------------- /include/easyhttpcpp/db/AutoSqliteDatabase.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_DB_AUTOSQLITEDATABASE_H_INCLUDED 6 | #define EASYHTTPCPP_DB_AUTOSQLITEDATABASE_H_INCLUDED 7 | 8 | #include 9 | 10 | #include "easyhttpcpp/common/CoreLogger.h" 11 | #include "easyhttpcpp/db/SqliteDatabase.h" 12 | #include "easyhttpcpp/db/SqlException.h" 13 | 14 | namespace easyhttpcpp { 15 | namespace db { 16 | 17 | class AutoSqliteDatabase { 18 | public: 19 | AutoSqliteDatabase(SqliteDatabase::Ptr pDatabase) : m_pDatabase(pDatabase) 20 | { 21 | } 22 | 23 | virtual ~AutoSqliteDatabase() 24 | { 25 | static const std::string Tag = "AutoSqliteDatabase"; 26 | // consumes exception since sqlite might be able to work even without closing database as well 27 | try { 28 | if (m_pDatabase) { 29 | m_pDatabase->close(); 30 | } 31 | } catch (const SqlException& ignored) { 32 | EASYHTTPCPP_LOG_D(Tag, "Error while closing database. Ignored. Details: %s", ignored.getMessage().c_str()); 33 | } 34 | } 35 | 36 | private: 37 | SqliteDatabase::Ptr m_pDatabase; 38 | }; 39 | 40 | } /* namespace db */ 41 | } /* namespace easyhttpcpp */ 42 | 43 | #endif /* EASYHTTPCPP_DB_AUTOSQLITEDATABASE_H_INCLUDED */ 44 | -------------------------------------------------------------------------------- /include/easyhttpcpp/db/AutoSqliteTransaction.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_DB_AUTOSQLITETRANSACTION_H_INCLUDED 6 | #define EASYHTTPCPP_DB_AUTOSQLITETRANSACTION_H_INCLUDED 7 | 8 | #include 9 | 10 | #include "easyhttpcpp/common/CoreLogger.h" 11 | #include "easyhttpcpp/db/SqliteDatabase.h" 12 | #include "easyhttpcpp/db/SqlException.h" 13 | 14 | namespace easyhttpcpp { 15 | namespace db { 16 | 17 | class AutoSqliteTransaction { 18 | public: 19 | AutoSqliteTransaction(SqliteDatabase::Ptr pDatabase) : m_pDatabase(pDatabase) 20 | { 21 | // throws exception; caller must catch 22 | if (m_pDatabase) { 23 | m_pDatabase->beginTransaction(); 24 | } 25 | } 26 | 27 | virtual ~AutoSqliteTransaction() 28 | { 29 | static const std::string Tag = "AutoSqliteTransaction"; 30 | // consumes exception since transaction actually completes during setTransactionSuccessful() call if successful 31 | try { 32 | if (m_pDatabase) { 33 | m_pDatabase->endTransaction(); 34 | } 35 | } catch (const SqlException& ignored) { 36 | EASYHTTPCPP_LOG_D(Tag, "Error while endTransaction(). Ignored. Details: %s", ignored.getMessage().c_str()); 37 | } 38 | } 39 | 40 | private: 41 | SqliteDatabase::Ptr m_pDatabase; 42 | }; 43 | 44 | } /* namespace db */ 45 | } /* namespace easyhttpcpp */ 46 | 47 | #endif /* EASYHTTPCPP_DB_AUTOSQLITETRANSACTION_H_INCLUDED */ 48 | -------------------------------------------------------------------------------- /include/easyhttpcpp/db/DbExports.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_DB_DBEXPORTS_H_INCLUDED 6 | #define EASYHTTPCPP_DB_DBEXPORTS_H_INCLUDED 7 | 8 | #ifdef EASYHTTPCPP_API_EXPORTS 9 | #include "easyhttpcpp/common/CoreExports.h" 10 | #endif 11 | 12 | namespace easyhttpcpp { 13 | namespace db { 14 | 15 | #if defined(_WIN32) && defined(EASYHTTPCPP_DLL) 16 | #ifdef EASYHTTPCPP_DB_API_EXPORTS 17 | #define EASYHTTPCPP_DB_API __declspec(dllexport) 18 | #else 19 | #define EASYHTTPCPP_DB_API __declspec(dllimport) 20 | #endif 21 | #endif 22 | 23 | #ifndef EASYHTTPCPP_DB_API 24 | #define EASYHTTPCPP_DB_API 25 | #endif 26 | 27 | } /* namespace db */ 28 | } /* namespace easyhttpcpp */ 29 | 30 | #endif /* EASYHTTPCPP_DB_DBEXPORTS_H_INCLUDED */ 31 | 32 | -------------------------------------------------------------------------------- /include/easyhttpcpp/db/SqlException.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_DB_SQLEXCEPTION_H_INCLUDED 6 | #define EASYHTTPCPP_DB_SQLEXCEPTION_H_INCLUDED 7 | 8 | #include "easyhttpcpp/common/CoreException.h" 9 | #include "easyhttpcpp/db/DbExports.h" 10 | 11 | namespace easyhttpcpp { 12 | namespace db { 13 | 14 | EASYHTTPCPP_DECLARE_EXCEPTION_SUB_GROUP(EASYHTTPCPP_DB_API, SqlException, easyhttpcpp::common::CoreException) 15 | 16 | EASYHTTPCPP_DECLARE_EXCEPTION(EASYHTTPCPP_DB_API, SqlExecutionException, SqlException) 17 | 18 | EASYHTTPCPP_DECLARE_EXCEPTION(EASYHTTPCPP_DB_API, SqlIllegalArgumentException, SqlException) 19 | 20 | EASYHTTPCPP_DECLARE_EXCEPTION(EASYHTTPCPP_DB_API, SqlIllegalStateException, SqlException) 21 | 22 | EASYHTTPCPP_DECLARE_EXCEPTION(EASYHTTPCPP_DB_API, SqlDatabaseCorruptException, SqlException) 23 | 24 | } /* namespace db */ 25 | } /* namespace easyhttpcpp */ 26 | 27 | #endif /* EASYHTTPCPP_DB_SQLEXCEPTION_H_INCLUDED */ 28 | -------------------------------------------------------------------------------- /include/easyhttpcpp/db/SqliteConflictAlgorithm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_DB_SQLITECONFLICTALGORITHM_H_INCLUDED 6 | #define EASYHTTPCPP_DB_SQLITECONFLICTALGORITHM_H_INCLUDED 7 | 8 | namespace easyhttpcpp { 9 | namespace db { 10 | 11 | enum SqliteConflictAlgorithm { 12 | SqliteConflictAlgorithmNone, 13 | SqliteConflictAlgorithmRollback, 14 | SqliteConflictAlgorithmAbort, 15 | SqliteConflictAlgorithmFail, 16 | SqliteConflictAlgorithmIgnore, 17 | SqliteConflictAlgorithmReplace 18 | }; 19 | 20 | } /* namespace db */ 21 | } /* namespace easyhttpcpp */ 22 | 23 | #endif /* EASYHTTPCPP_DB_SQLITECONFLICTALGORITHM_H_INCLUDED */ 24 | -------------------------------------------------------------------------------- /include/easyhttpcpp/db/SqliteQueryBuilder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_DB_SQLITEQUERYBUILDER_H_INCLUDED 6 | #define EASYHTTPCPP_DB_SQLITEQUERYBUILDER_H_INCLUDED 7 | 8 | #include 9 | #include 10 | 11 | #include "easyhttpcpp/db/ContentValues.h" 12 | #include "easyhttpcpp/db/DbExports.h" 13 | #include "easyhttpcpp/db/SqliteConflictAlgorithm.h" 14 | 15 | namespace easyhttpcpp { 16 | namespace db { 17 | 18 | class ContentValues; 19 | 20 | class EASYHTTPCPP_DB_API SqliteQueryBuilder { 21 | public: 22 | static std::string buildQueryString(const std::string& table, const std::vector* columns, 23 | const std::string* where, const std::string* groupBy, const std::string* having, const std::string* orderBy, 24 | const std::string* limit, const bool distinct); 25 | 26 | static std::string buildInsertString(const std::string& table, const ContentValues& values, 27 | SqliteConflictAlgorithm conflictAlgorithm); 28 | 29 | static std::string buildUpdateString(const std::string& table, const ContentValues& values, 30 | const std::string* whereClause, SqliteConflictAlgorithm conflictAlgorithm); 31 | 32 | static std::string buildDeleteString(const std::string& table, const std::string* whereClause); 33 | }; 34 | 35 | } /* namespace db */ 36 | } /* namespace easyhttpcpp */ 37 | 38 | #endif /* EASYHTTPCPP_DB_SQLITEQURERYBUILDER_H_INCLUDED */ 39 | -------------------------------------------------------------------------------- /include/easyhttpcpp/executorservice/BlockingQueue.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_EXECUTORSERVICE_BLOCKINGQUEUE_H_INCLUDED 6 | #define EASYHTTPCPP_EXECUTORSERVICE_BLOCKINGQUEUE_H_INCLUDED 7 | 8 | #include "Poco/AutoPtr.h" 9 | #include "Poco/RefCountedObject.h" 10 | 11 | #include "easyhttpcpp/common/RefCountedRunnable.h" 12 | 13 | namespace easyhttpcpp { 14 | namespace executorservice { 15 | 16 | class BlockingQueue : public Poco::RefCountedObject { 17 | public: 18 | typedef Poco::AutoPtr Ptr; 19 | 20 | virtual ~BlockingQueue() 21 | { 22 | } 23 | 24 | virtual bool push(easyhttpcpp::common::RefCountedRunnable::Ptr pTask) = 0; 25 | virtual easyhttpcpp::common::RefCountedRunnable::Ptr pop() = 0; 26 | virtual bool isEmpty() = 0; 27 | virtual void clear() = 0; 28 | protected: 29 | Poco::FastMutex m_mutex; 30 | }; 31 | 32 | } /* namespace executorservice */ 33 | } /* namespace easyhttpcpp */ 34 | 35 | #endif /* EASYHTTPCPP_EXECUTORSERVICE_BLOCKINGQUEUE_H_INCLUDED */ 36 | -------------------------------------------------------------------------------- /include/easyhttpcpp/executorservice/BoundBlockingQueue.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_EXECUTORSERVICE_BOUNDBLOCKINGQUEUE_H_INCLUDED 6 | #define EASYHTTPCPP_EXECUTORSERVICE_BOUNDBLOCKINGQUEUE_H_INCLUDED 7 | 8 | #include "easyhttpcpp/executorservice/ExecutorServiceExports.h" 9 | #include "easyhttpcpp/executorservice/UnboundBlockingQueue.h" 10 | 11 | namespace easyhttpcpp { 12 | namespace executorservice { 13 | 14 | class EASYHTTPCPP_EXECUTORSERVICE_API BoundBlockingQueue : public UnboundBlockingQueue { 15 | public: 16 | static const unsigned int DefaultMaxQueueSize; 17 | 18 | BoundBlockingQueue(); 19 | BoundBlockingQueue(unsigned int maxQueueSize); 20 | virtual ~BoundBlockingQueue(); 21 | 22 | protected: 23 | unsigned int m_maxQueueSize; 24 | virtual bool push(easyhttpcpp::common::RefCountedRunnable::Ptr pTask); 25 | }; 26 | 27 | } /* namespace executorservice */ 28 | } /* namespace easyhttpcpp */ 29 | 30 | #endif /* EASYHTTPCPP_EXECUTORSERVICE_BOUNDBLOCKINGQUEUE_H_INCLUDED */ 31 | -------------------------------------------------------------------------------- /include/easyhttpcpp/executorservice/ExecutorServiceException.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_EXECUTORSERVICE_EXECUTORSERVICEEXCEPTION_H_INCLUDED 6 | #define EASYHTTPCPP_EXECUTORSERVICE_EXECUTORSERVICEEXCEPTION_H_INCLUDED 7 | 8 | #include "easyhttpcpp/common/CoreException.h" 9 | #include "easyhttpcpp/executorservice/ExecutorServiceExports.h" 10 | 11 | namespace easyhttpcpp { 12 | namespace executorservice { 13 | 14 | EASYHTTPCPP_DECLARE_EXCEPTION_SUB_GROUP(EASYHTTPCPP_EXECUTORSERVICE_API, ExecutorServiceException, easyhttpcpp::common::CoreException) 15 | 16 | EASYHTTPCPP_DECLARE_EXCEPTION(EASYHTTPCPP_EXECUTORSERVICE_API, ExecutorServiceIllegalArgumentException, ExecutorServiceException) 17 | EASYHTTPCPP_DECLARE_EXCEPTION(EASYHTTPCPP_EXECUTORSERVICE_API, ExecutorServiceIllegalStateException, ExecutorServiceException) 18 | EASYHTTPCPP_DECLARE_EXCEPTION(EASYHTTPCPP_EXECUTORSERVICE_API, ExecutorServiceExecutionException, ExecutorServiceException) 19 | EASYHTTPCPP_DECLARE_EXCEPTION(EASYHTTPCPP_EXECUTORSERVICE_API, ExecutorServiceTooManyRequestsException, ExecutorServiceException) 20 | 21 | } /* namespace executorservice */ 22 | } /* namespace easyhttpcpp */ 23 | 24 | #endif /* EASYHTTPCPP_EXECUTORSERVICE_EXECUTORSERVICEEXCEPTION_H_INCLUDED */ 25 | -------------------------------------------------------------------------------- /include/easyhttpcpp/executorservice/ExecutorServiceExports.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_EXECUTORSERVICE_EXECUTORSERVICEEXPORTS_H_INCLUDED 6 | #define EASYHTTPCPP_EXECUTORSERVICE_EXECUTORSERVICEEXPORTS_H_INCLUDED 7 | 8 | #ifdef EASYHTTPCPP_API_EXPORTS 9 | #include "easyhttpcpp/common/CoreExports.h" 10 | #endif 11 | 12 | namespace easyhttpcpp { 13 | namespace executorservice { 14 | 15 | #if defined(_WIN32) && defined(EASYHTTPCPP_DLL) 16 | #ifdef EASYHTTPCPP_EXECUTORSERVICE_API_EXPORTS 17 | #define EASYHTTPCPP_EXECUTORSERVICE_API __declspec(dllexport) 18 | #else 19 | #define EASYHTTPCPP_EXECUTORSERVICE_API __declspec(dllimport) 20 | #endif 21 | #endif 22 | 23 | #ifndef EASYHTTPCPP_EXECUTORSERVICE_API 24 | #define EASYHTTPCPP_EXECUTORSERVICE_API 25 | #endif 26 | 27 | } /* namespace executorservice */ 28 | } /* namespace easyhttpcpp */ 29 | 30 | #endif /* EASYHTTPCPP_EXECUTORSERVICE_EXECUTORSERVICEEXPORTS_H_INCLUDED */ 31 | 32 | -------------------------------------------------------------------------------- /include/easyhttpcpp/executorservice/Task.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_EXECUTORSERVICE_TASK_H_INCLUDED 6 | #define EASYHTTPCPP_EXECUTORSERVICE_TASK_H_INCLUDED 7 | 8 | #include "easyhttpcpp/common/AtomicBool.h" 9 | #include "easyhttpcpp/common/RefCountedRunnable.h" 10 | #include "easyhttpcpp/executorservice/ExecutorServiceExports.h" 11 | 12 | namespace easyhttpcpp { 13 | namespace executorservice { 14 | 15 | class EASYHTTPCPP_EXECUTORSERVICE_API Task : public easyhttpcpp::common::RefCountedRunnable { 16 | public: 17 | Task(); 18 | 19 | virtual void runTask() = 0; 20 | 21 | virtual bool cancel(bool mayInterruptIfRunning); 22 | virtual bool isCancelled() const; 23 | virtual bool isDone() const; 24 | 25 | protected: 26 | virtual ~Task(); 27 | 28 | virtual void run(); 29 | 30 | private: 31 | Task(const Task&); 32 | Task& operator=(const Task&); 33 | 34 | easyhttpcpp::common::AtomicBool m_cancelled; 35 | easyhttpcpp::common::AtomicBool m_finished; 36 | }; 37 | 38 | } /* namespace executorservice */ 39 | } /* namespace easyhttpcpp */ 40 | 41 | #endif /* EASYHTTPCPP_EXECUTORSERVICE_TASK_H_INCLUDED */ 42 | -------------------------------------------------------------------------------- /include/easyhttpcpp/executorservice/UnboundBlockingQueue.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_EXECUTORSERVICE_UNBOUNDBLOCKINGQUEUE_H_INCLUDED 6 | #define EASYHTTPCPP_EXECUTORSERVICE_UNBOUNDBLOCKINGQUEUE_H_INCLUDED 7 | 8 | #include 9 | 10 | #include "easyhttpcpp/executorservice/BlockingQueue.h" 11 | #include "easyhttpcpp/executorservice/ExecutorServiceExports.h" 12 | 13 | namespace easyhttpcpp { 14 | namespace executorservice { 15 | 16 | class EASYHTTPCPP_EXECUTORSERVICE_API UnboundBlockingQueue : public BlockingQueue { 17 | public: 18 | UnboundBlockingQueue(); 19 | virtual ~UnboundBlockingQueue(); 20 | 21 | virtual bool push(easyhttpcpp::common::RefCountedRunnable::Ptr pTask); 22 | virtual easyhttpcpp::common::RefCountedRunnable::Ptr pop(); 23 | virtual bool isEmpty(); 24 | virtual void clear(); 25 | 26 | protected: 27 | std::queue m_workerQueue; 28 | Poco::FastMutex m_mutex; 29 | }; 30 | 31 | } /* namespace executorservice */ 32 | } /* namespace easyhttpcpp */ 33 | 34 | #endif /* EASYHTTPCPP_EXECUTORSERVICE_UNBOUNDBLOCKINGQUEUE_H_INCLUDED */ 35 | -------------------------------------------------------------------------------- /include/easyhttpcpp/messagedigest/DigestConstants.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_MESSAGEDIGEST_DIGESTCONSTANTS_H_INCLUDED 6 | #define EASYHTTPCPP_MESSAGEDIGEST_DIGESTCONSTANTS_H_INCLUDED 7 | 8 | #include 9 | 10 | #include "easyhttpcpp/messagedigest/MessageDigestExports.h" 11 | 12 | namespace easyhttpcpp { 13 | namespace messagedigest { 14 | 15 | class EASYHTTPCPP_MESSAGEDIGEST_API DigestConstants { 16 | public: 17 | static const std::string MessageDigestAlgorithmSha256; 18 | static const std::string MessageDigestAlgorithmSha1; 19 | static const std::string MessageDigestAlgorithmMd5; 20 | }; 21 | 22 | } /* namespace messagedigest */ 23 | } /* namespace easyhttpcpp */ 24 | 25 | #endif /* EASYHTTPCPP_MESSAGEDIGEST_DIGESTCONSTANTS_H_INCLUDED */ 26 | -------------------------------------------------------------------------------- /include/easyhttpcpp/messagedigest/DigestEngine.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_MESSAGEDIGEST_DIGESTENGINE_H_INCLUDED 6 | #define EASYHTTPCPP_MESSAGEDIGEST_DIGESTENGINE_H_INCLUDED 7 | 8 | #include 9 | #include 10 | 11 | #include "Poco/AutoPtr.h" 12 | #include "Poco/SharedPtr.h" 13 | #include "Poco/RefCountedObject.h" 14 | 15 | #include "easyhttpcpp/common/Typedef.h" 16 | #include "easyhttpcpp/messagedigest/MessageDigestExports.h" 17 | 18 | namespace easyhttpcpp { 19 | namespace messagedigest { 20 | 21 | class DigestEngineImpl; 22 | 23 | class EASYHTTPCPP_MESSAGEDIGEST_API DigestEngine : public Poco::RefCountedObject { 24 | public: 25 | typedef Poco::AutoPtr Ptr; 26 | 27 | DigestEngine(const std::string& algorithm); 28 | virtual ~DigestEngine(); 29 | 30 | static std::string digestToHex(const std::vector& digest); 31 | virtual void update(const easyhttpcpp::common::Byte* data, size_t length); 32 | virtual std::vector digest(); 33 | virtual void reset(); 34 | 35 | private: 36 | Poco::SharedPtr m_pImpl; 37 | }; 38 | 39 | } /* namespace messagedigest */ 40 | } /* namespace easyhttpcpp */ 41 | 42 | #endif /* EASYHTTPCPP_MESSAGEDIGEST_DIGESTENGINE_H_INCLUDED */ 43 | -------------------------------------------------------------------------------- /include/easyhttpcpp/messagedigest/DigestUtil.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_MESSAGEDIGEST_DIGESTUTIL_H_INCLUDED 6 | #define EASYHTTPCPP_MESSAGEDIGEST_DIGESTUTIL_H_INCLUDED 7 | 8 | #include 9 | 10 | #include "Poco/Mutex.h" 11 | 12 | #include "easyhttpcpp/common/ByteArrayBuffer.h" 13 | #include "easyhttpcpp/messagedigest/DigestEngine.h" 14 | #include "easyhttpcpp/messagedigest/MessageDigestExports.h" 15 | 16 | namespace easyhttpcpp { 17 | namespace messagedigest { 18 | 19 | class EASYHTTPCPP_MESSAGEDIGEST_API DigestUtil { 20 | public: 21 | static std::string sha256Hex(const easyhttpcpp::common::ByteArrayBuffer& data); 22 | static std::string sha256Hex(const std::string& data); 23 | 24 | static std::string sha1Hex(const easyhttpcpp::common::ByteArrayBuffer& data); 25 | static std::string sha1Hex(const std::string& data); 26 | 27 | static std::string createHashedFileName(const std::string& key); 28 | 29 | private: 30 | DigestUtil(); 31 | virtual ~DigestUtil(); 32 | }; 33 | 34 | } /* namespace messagedigest */ 35 | } /* namespace easyhttpcpp */ 36 | 37 | #endif /* EASYHTTPCPP_MESSAGEDIGEST_DIGESTUTIL_H_INCLUDED */ 38 | -------------------------------------------------------------------------------- /include/easyhttpcpp/messagedigest/MessageDigestExports.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_MESSAGEDIGEST_MESSAGEDIGESTEXPORTS_H_INCLUDED 6 | #define EASYHTTPCPP_MESSAGEDIGEST_MESSAGEDIGESTEXPORTS_H_INCLUDED 7 | 8 | #ifdef EASYHTTPCPP_API_EXPORTS 9 | #include "easyhttpcpp/common/CoreExports.h" 10 | #endif 11 | 12 | namespace easyhttpcpp { 13 | namespace messagedigest { 14 | 15 | #if defined(_WIN32) && defined(EASYHTTPCPP_DLL) 16 | #ifdef EASYHTTPCPP_MESSAGEDIGEST_API_EXPORTS 17 | #define EASYHTTPCPP_MESSAGEDIGEST_API __declspec(dllexport) 18 | #else 19 | #define EASYHTTPCPP_MESSAGEDIGEST_API __declspec(dllimport) 20 | #endif 21 | #endif 22 | 23 | #ifndef EASYHTTPCPP_MESSAGEDIGEST_API 24 | #define EASYHTTPCPP_MESSAGEDIGEST_API 25 | #endif 26 | 27 | } /* namespace messagedigest */ 28 | } /* namespace easyhttpcpp */ 29 | 30 | #endif /* EASYHTTPCPP_MESSAGEDIGEST_MESSAGEDIGESTEXPORTS_H_INCLUDED */ 31 | 32 | -------------------------------------------------------------------------------- /libversion: -------------------------------------------------------------------------------- 1 | 2 2 | -------------------------------------------------------------------------------- /rocro.yml: -------------------------------------------------------------------------------- 1 | inspecode: 2 | thresholds: 3 | num-issues: 4 | critical: 0 5 | error: 0 6 | cppcheck: 7 | ignore: 8 | - "tests*" 9 | options: 10 | --enable: all 11 | -I: include 12 | -------------------------------------------------------------------------------- /samples/AsyncHttpClient/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SAMPLE_NAME "${CMAKE_PROJECT_NAME}-AsyncHttpClient") 2 | 3 | set(SAMPLE_SRCS "AsyncHttpClient.cpp") 4 | 5 | # dependent libraries 6 | find_package(Poco REQUIRED Foundation Data DataSQLite Net NetSSL Crypto CONFIG) 7 | find_package(easyhttpcpp REQUIRED CONFIG) 8 | 9 | add_executable(${SAMPLE_NAME} ${SAMPLE_SRCS}) 10 | target_link_libraries(${SAMPLE_NAME} 11 | easyhttpcpp::easyhttp 12 | Poco::Foundation 13 | Poco::Data Poco::DataSQLite 14 | Poco::Net Poco::NetSSL Poco::Crypto 15 | OpenSSL::SSL OpenSSL::Crypto 16 | ) 17 | -------------------------------------------------------------------------------- /samples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | project(easyhttpcpp-samples) 4 | 5 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 6 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 7 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) 8 | 9 | ############################################################# 10 | # build sample targets 11 | 12 | find_package(OpenSSL REQUIRED) 13 | 14 | add_subdirectory(SimpleHttpClient) 15 | add_subdirectory(AsyncHttpClient) 16 | -------------------------------------------------------------------------------- /samples/README.md: -------------------------------------------------------------------------------- 1 | Samples 2 | ========= 3 | The library comes with the following sample programs. 4 | 5 | ### SimpleHttpClient 6 | This demonstrates a very basic http client to download and print fetched data. 7 | 8 | Also shows how to configure response cache and connection pool. 9 | 10 | ### AsyncHttpClient 11 | This demonstrates an http client which downloads data asynchronously and print fetched data. 12 | 13 | Also shows how to configure response cache and connection pool. 14 | 15 | Building samples 16 | ------------------- 17 | See [wiki](https://github.com/sony/easyhttpcpp/wiki/Building-samples) for instructions. 18 | -------------------------------------------------------------------------------- /samples/SimpleHttpClient/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SAMPLE_NAME "${CMAKE_PROJECT_NAME}-SimpleHttpClient") 2 | 3 | set(SAMPLE_SRCS "SimpleHttpClient.cpp") 4 | 5 | # dependent libraries 6 | find_package(Poco REQUIRED Foundation Data DataSQLite Net NetSSL Crypto CONFIG) 7 | find_package(easyhttpcpp REQUIRED CONFIG) 8 | 9 | add_executable(${SAMPLE_NAME} ${SAMPLE_SRCS}) 10 | target_link_libraries(${SAMPLE_NAME} 11 | easyhttpcpp::easyhttp 12 | Poco::Foundation 13 | Poco::Data Poco::DataSQLite 14 | Poco::Net Poco::NetSSL Poco::Crypto 15 | OpenSSL::SSL OpenSSL::Crypto 16 | ) 17 | -------------------------------------------------------------------------------- /scripts/02_run_alltests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | CWD=`pwd` 6 | 7 | rm -rf _build && mkdir _build 8 | cd _build 9 | 10 | CMAKE_TOOLCHAIN_FILE_ARG="" 11 | if [[ "`uname`" == "Darwin" ]]; then 12 | # workaround to find_package(OpenSSL) 13 | CMAKE_TOOLCHAIN_FILE_ARG="-DCMAKE_TOOLCHAIN_FILE=${CWD}/cmake/AppleToolchain.cmake" 14 | fi 15 | 16 | # build easyhttpcpp in Release mode 17 | cmake -DCMAKE_BUILD_TYPE=Release -DEASYHTTPCPP_VERBOSE_MESSAGES=ON -DCMAKE_CXX_STANDARD=11 -DCMAKE_CXX_STANDARD_REQUIRED=ON -DCMAKE_PREFIX_PATH=${CWD}/_install -DCMAKE_INSTALL_PREFIX=${CWD}/_install -DENABLE_TESTS=ON ${CMAKE_TOOLCHAIN_FILE_ARG} ../ >/dev/null 18 | make -j4 install >/dev/null 19 | 20 | # run tests 21 | ./bin/easyhttp-UnitTestRunner 22 | ./bin/easyhttp-IntegrationTestRunner 23 | 24 | cd ${CWD} 25 | -------------------------------------------------------------------------------- /scripts/03_run_samples.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | CWD=`pwd` 6 | 7 | cd samples 8 | 9 | rm -rf _build && mkdir _build 10 | cd _build 11 | 12 | CMAKE_TOOLCHAIN_FILE_ARG="" 13 | if [[ "`uname`" == "Darwin" ]]; then 14 | # workaround to find_package(OpenSSL) 15 | CMAKE_TOOLCHAIN_FILE_ARG="-DCMAKE_TOOLCHAIN_FILE=${CWD}/cmake/AppleToolchain.cmake" 16 | fi 17 | 18 | # build all samples with Debug lib 19 | cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_STANDARD=11 -DCMAKE_CXX_STANDARD_REQUIRED=ON -DCMAKE_PREFIX_PATH=${CWD}/_install ${CMAKE_TOOLCHAIN_FILE_ARG} ../ 20 | make >/dev/null 21 | 22 | # run all samples 23 | ./bin/easyhttpcpp-samples-SimpleHttpClient https://github.com/sony/easyhttpcpp >/dev/null 2>&1 24 | 25 | # build all samples with Release lib 26 | cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=11 -DCMAKE_CXX_STANDARD_REQUIRED=ON -DCMAKE_PREFIX_PATH=${CWD}/_install ${CMAKE_TOOLCHAIN_FILE_ARG} ../ 27 | make >/dev/null 28 | 29 | # run all samples 30 | ./bin/easyhttpcpp-samples-SimpleHttpClient https://github.com/sony/easyhttpcpp >/dev/null 2>&1 31 | ./bin/easyhttpcpp-samples-AsyncHttpClient https://github.com/sony/easyhttpcpp >/dev/null 2>&1 32 | 33 | cd ${CWD} 34 | -------------------------------------------------------------------------------- /src/CallInterceptorChain.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "CallInterceptorChain.h" 6 | 7 | namespace easyhttpcpp { 8 | 9 | CallInterceptorChain::CallInterceptorChain(HttpRequestExecutor::Ptr pRequestExecutor, Request::Ptr pRequest, 10 | EasyHttpContext::InterceptorList::iterator& currentIterator, 11 | EasyHttpContext::InterceptorList::const_iterator& endIterator) : 12 | m_pRequestExecutor(pRequestExecutor), m_pRequest(pRequest), m_currentIterator(currentIterator), 13 | m_endIterator(endIterator) 14 | { 15 | } 16 | 17 | CallInterceptorChain::~CallInterceptorChain() 18 | { 19 | } 20 | 21 | Request::Ptr CallInterceptorChain::getRequest() const 22 | { 23 | return m_pRequest; 24 | } 25 | 26 | Connection::Ptr CallInterceptorChain::getConnection() const 27 | { 28 | return NULL; 29 | } 30 | 31 | Response::Ptr CallInterceptorChain::proceed(Request::Ptr pRequest) 32 | { 33 | m_currentIterator++; 34 | if (m_currentIterator != m_endIterator) { 35 | CallInterceptorChain::Ptr chain(new CallInterceptorChain(m_pRequestExecutor, pRequest, m_currentIterator, 36 | m_endIterator)); 37 | return (*m_currentIterator)->intercept(*chain); 38 | } else { 39 | return m_pRequestExecutor->executeAfterIntercept(pRequest); 40 | } 41 | } 42 | 43 | } /* namespace easyhttpcpp */ 44 | -------------------------------------------------------------------------------- /src/CallInterceptorChain.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "easyhttpcpp/Interceptor.h" 6 | 7 | #include "EasyHttpContext.h" 8 | #include "HttpRequestExecutor.h" 9 | 10 | #ifndef EASYHTTPCPP_APPLICATIONINTERCEPTORCHAIN_H_INCLUDED 11 | #define EASYHTTPCPP_APPLICATIONINTERCEPTORCHAIN_H_INCLUDED 12 | 13 | namespace easyhttpcpp { 14 | 15 | class CallInterceptorChain : public Interceptor::Chain { 16 | public: 17 | CallInterceptorChain(HttpRequestExecutor::Ptr pRequestExecutior, Request::Ptr pRequest, 18 | EasyHttpContext::InterceptorList::iterator& currentIterator, 19 | EasyHttpContext::InterceptorList::const_iterator& endIterator); 20 | virtual ~CallInterceptorChain(); 21 | virtual Request::Ptr getRequest() const; 22 | virtual Connection::Ptr getConnection() const; 23 | virtual Response::Ptr proceed(Request::Ptr pRequest); 24 | 25 | private: 26 | HttpRequestExecutor::Ptr m_pRequestExecutor; 27 | Request::Ptr m_pRequest; 28 | EasyHttpContext::InterceptorList::iterator& m_currentIterator; 29 | EasyHttpContext::InterceptorList::const_iterator& m_endIterator; 30 | }; 31 | 32 | } /* namespace easyhttpcpp */ 33 | 34 | #endif /* EASYHTTPCPP_APPLICATIONINTERCEPTORCHAIN_H_INCLUDED */ 35 | -------------------------------------------------------------------------------- /src/CallInternal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_CALLINTERNAL_H_INCLUDED 6 | #define EASYHTTPCPP_CALLINTERNAL_H_INCLUDED 7 | 8 | #include "Poco/AutoPtr.h" 9 | #include "Poco/Mutex.h" 10 | #include "Poco/RefCountedObject.h" 11 | 12 | #include "easyhttpcpp/Call.h" 13 | #include "easyhttpcpp/HttpExports.h" 14 | #include "easyhttpcpp/Request.h" 15 | #include "easyhttpcpp/Response.h" 16 | 17 | #include "EasyHttpContext.h" 18 | #include "HttpRequestExecutor.h" 19 | 20 | namespace easyhttpcpp { 21 | 22 | class EASYHTTPCPP_HTTP_INTERNAL_API CallInternal : public Call { 23 | public: 24 | 25 | CallInternal(EasyHttpContext::Ptr pContext, Request::Ptr pRequest); 26 | virtual ~CallInternal(); 27 | virtual Response::Ptr execute(); 28 | virtual void executeAsync(ResponseCallback::Ptr pResponseCallback); 29 | #ifdef _WIN32 30 | _declspec(deprecated) virtual bool isExecuted() const; 31 | #else 32 | __attribute__ ((deprecated)) virtual bool isExecuted() const; 33 | #endif 34 | virtual Request::Ptr getRequest() const; 35 | virtual bool cancel(); 36 | virtual bool isCancelled() const; 37 | 38 | HttpEngine::Ptr getHttpEngine(); 39 | private: 40 | EasyHttpContext::Ptr m_pContext; 41 | Request::Ptr m_pUserRequest; 42 | mutable Poco::FastMutex m_instanceMutex; 43 | bool m_executed; 44 | bool m_cancelled; 45 | HttpRequestExecutor::Ptr m_pRequestExecutor; 46 | }; 47 | 48 | } /* namespace easyhttpcpp */ 49 | 50 | #endif /* EASYHTTPCPP_CALLINTERNAL_H_INCLUDED */ 51 | -------------------------------------------------------------------------------- /src/CallLoggingInterceptor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_CALLLOGGINGINTERCEPTOR_H_INCLUDED 6 | #define EASYHTTPCPP_CALLLOGGINGINTERCEPTOR_H_INCLUDED 7 | 8 | #include "easyhttpcpp/LoggingInterceptor.h" 9 | 10 | namespace easyhttpcpp { 11 | 12 | class CallLoggingInterceptor : public LoggingInterceptor { 13 | public: 14 | CallLoggingInterceptor(); 15 | virtual ~CallLoggingInterceptor(); 16 | 17 | virtual Response::Ptr intercept(Chain& chain); 18 | }; 19 | 20 | } /* namespace easyhttpcpp */ 21 | 22 | #endif /* EASYHTTPCPP_CALLLOGGINGINTERCEPTOR_H_INCLUDED */ 23 | -------------------------------------------------------------------------------- /src/ConnectionPool.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "easyhttpcpp/ConnectionPool.h" 6 | 7 | #include "ConnectionPoolInternal.h" 8 | 9 | namespace easyhttpcpp { 10 | 11 | static const unsigned int DefaultMaxKeepAliveIdleCount = 10; 12 | static const unsigned long DefaultKeepAliveTimeoutSec = 60; 13 | 14 | ConnectionPool::Ptr ConnectionPool::createConnectionPool() 15 | { 16 | return new ConnectionPoolInternal(DefaultMaxKeepAliveIdleCount, DefaultKeepAliveTimeoutSec); 17 | } 18 | 19 | ConnectionPool::Ptr ConnectionPool::createConnectionPool(unsigned int maxKeepAliveIdleCount, 20 | unsigned long keepAliveTimeoutSec) 21 | { 22 | return new ConnectionPoolInternal(maxKeepAliveIdleCount, keepAliveTimeoutSec); 23 | } 24 | 25 | } /* namespace easyhttpcpp */ 26 | -------------------------------------------------------------------------------- /src/ConnectionStatusListener.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_CONNECTIONSTATUSLISTENER_H_INCLUDED 6 | #define EASYHTTPCPP_CONNECTIONSTATUSLISTENER_H_INCLUDED 7 | 8 | namespace easyhttpcpp { 9 | 10 | class ConnectionInternal; 11 | 12 | class ConnectionStatusListener { 13 | public: 14 | virtual ~ConnectionStatusListener() 15 | { 16 | } 17 | 18 | virtual void onIdle(ConnectionInternal* pConnectionInternal, bool& listenerInvalidated) = 0; 19 | }; 20 | 21 | } /* namespace easyhttpcpp */ 22 | 23 | #endif /* EASYHTTPCPP_CONNECTIONSTATUSLISTENER_H_INCLUDED */ 24 | -------------------------------------------------------------------------------- /src/HttpAsyncExecutionTask.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_HTTPASYNCEXECUTIONTASK_H_INCLUDED 6 | #define EASYHTTPCPP_HTTPASYNCEXECUTIONTASK_H_INCLUDED 7 | 8 | #include "easyhttpcpp/Response.h" 9 | #include "easyhttpcpp/ResponseCallback.h" 10 | 11 | #include "EasyHttpContext.h" 12 | #include "HttpExecutionTask.h" 13 | #include "HttpRequestExecutor.h" 14 | 15 | namespace easyhttpcpp { 16 | 17 | class HttpAsyncExecutionTask : public HttpExecutionTask { 18 | public: 19 | typedef Poco::AutoPtr Ptr; 20 | HttpAsyncExecutionTask(EasyHttpContext::Ptr pContext, HttpRequestExecutor::Ptr pRequestExecutor, 21 | ResponseCallback::Ptr pResponseCallback); 22 | virtual ~HttpAsyncExecutionTask(); 23 | 24 | virtual void runTask(); 25 | virtual bool cancel(bool mayInterruptIfRunning); 26 | virtual bool isCancelled() const; 27 | 28 | private: 29 | HttpAsyncExecutionTask(); 30 | void notifyCompletion(HttpException::Ptr pWhat, Response::Ptr pResponse); 31 | 32 | EasyHttpContext::Ptr m_pContext; 33 | HttpRequestExecutor::Ptr m_pRequestExecutor; 34 | ResponseCallback::Ptr m_pResponseCallback; 35 | }; 36 | 37 | } /* namespace easyhttpcpp */ 38 | 39 | #endif /* EASYHTTPCPP_HTTPASYNCEXECUTIONTASK_H_INCLUDED */ 40 | -------------------------------------------------------------------------------- /src/HttpCache.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "easyhttpcpp/HttpCache.h" 6 | 7 | #include "HttpCacheInternal.h" 8 | 9 | namespace easyhttpcpp { 10 | 11 | HttpCache::~HttpCache() 12 | { 13 | } 14 | 15 | HttpCache::Ptr HttpCache::createCache(const Poco::Path& path, size_t maxSize) 16 | { 17 | return new HttpCacheInternal(path, maxSize); 18 | } 19 | 20 | } /* namespace easyhttpcpp */ 21 | 22 | -------------------------------------------------------------------------------- /src/HttpCacheDatabaseOpenHelper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_HTTPCACHEDATABASEOPENHELPER_H_INCLUDED 6 | #define EASYHTTPCPP_HTTPCACHEDATABASEOPENHELPER_H_INCLUDED 7 | 8 | #include "Poco/AutoPtr.h" 9 | #include "Poco/RefCountedObject.h" 10 | #include "Poco/Path.h" 11 | 12 | #include "easyhttpcpp/db/SqliteOpenHelper.h" 13 | #include "easyhttpcpp/HttpExports.h" 14 | 15 | namespace easyhttpcpp { 16 | 17 | class EASYHTTPCPP_HTTP_INTERNAL_API HttpCacheDatabaseOpenHelper : public easyhttpcpp::db::SqliteOpenHelper, 18 | public Poco::RefCountedObject { 19 | public: 20 | typedef Poco::AutoPtr Ptr; 21 | 22 | HttpCacheDatabaseOpenHelper(const Poco::Path& databaseFile); 23 | virtual ~HttpCacheDatabaseOpenHelper(); 24 | 25 | void onCreate(easyhttpcpp::db::SqliteDatabase& db); 26 | void onUpgrade(easyhttpcpp::db::SqliteDatabase& db, unsigned int oldVersion, unsigned int newVersion); 27 | }; 28 | 29 | } /* namespace easyhttpcpp */ 30 | 31 | #endif /* EASYHTTPCPP_HTTPCACHEDATABASEOPENHELPER_H_INCLUDED */ 32 | -------------------------------------------------------------------------------- /src/HttpCacheEnumerationListener.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_HTTPCACHEENUMERATIONLISTENER_H_INCLUDED 6 | #define EASYHTTPCPP_HTTPCACHEENUMERATIONLISTENER_H_INCLUDED 7 | 8 | namespace easyhttpcpp { 9 | 10 | class HttpCacheEnumerationListener { 11 | public: 12 | struct EnumerationParam; 13 | 14 | virtual ~HttpCacheEnumerationListener() 15 | { 16 | } 17 | virtual bool onEnumerate(const EnumerationParam& param) = 0; 18 | 19 | public: 20 | 21 | struct EnumerationParam { 22 | std::string m_key; 23 | size_t m_responseBodySize; 24 | }; 25 | }; 26 | 27 | } /* namespace easyhttpcpp */ 28 | 29 | #endif /* EASYHTTPCPP_HTTPCACHEENUMERATIONLISTENER_H_INCLUDED */ 30 | -------------------------------------------------------------------------------- /src/HttpCacheInfo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_HTTPCACHEINFO_H_INCLUDED 6 | #define EASYHTTPCPP_HTTPCACHEINFO_H_INCLUDED 7 | 8 | #include "easyhttpcpp/common/CacheInfoWithDataSize.h" 9 | #include "easyhttpcpp/HttpExports.h" 10 | 11 | namespace easyhttpcpp { 12 | 13 | class EASYHTTPCPP_HTTP_INTERNAL_API HttpCacheInfo : public easyhttpcpp::common::CacheInfoWithDataSize { 14 | public: 15 | HttpCacheInfo(const std::string& key, size_t dataSize = 0); 16 | HttpCacheInfo(const HttpCacheInfo& original); 17 | virtual ~HttpCacheInfo(); 18 | 19 | HttpCacheInfo& operator = (const HttpCacheInfo& original); 20 | bool operator == (const HttpCacheInfo& target) const; 21 | 22 | void setReservedRemove(bool reservedRemove); 23 | bool isReservedRemove() const; 24 | void addDataRef(); 25 | void releaseDataRef(); 26 | unsigned int getDataRefCount() const; 27 | 28 | private: 29 | bool m_reservedRemove; 30 | unsigned int m_dataRefCount; 31 | }; 32 | 33 | } /* namespace easyhttpcpp */ 34 | 35 | #endif /* EASYHTTPCPP_HTTPCACHEINFO_H_INCLUDED */ 36 | -------------------------------------------------------------------------------- /src/HttpException.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "easyhttpcpp/common/ExceptionConstants.h" 6 | #include "easyhttpcpp/common/StringUtil.h" 7 | #include "easyhttpcpp/HttpException.h" 8 | 9 | namespace easyhttpcpp { 10 | 11 | using easyhttpcpp::common::ExceptionConstants; 12 | 13 | EASYHTTPCPP_IMPLEMENT_EXCEPTION_SUB_GROUP(HttpException, CoreException, ExceptionConstants::SubGroupCode::Http) 14 | 15 | EASYHTTPCPP_IMPLEMENT_EXCEPTION(HttpIllegalArgumentException, HttpException, 0) 16 | EASYHTTPCPP_IMPLEMENT_EXCEPTION(HttpIllegalStateException, HttpException, 1) 17 | EASYHTTPCPP_IMPLEMENT_EXCEPTION(HttpExecutionException, HttpException, 2) 18 | EASYHTTPCPP_IMPLEMENT_EXCEPTION(HttpTimeoutException, HttpException, 3) 19 | EASYHTTPCPP_IMPLEMENT_EXCEPTION(HttpSslException, HttpException, 4) 20 | EASYHTTPCPP_IMPLEMENT_EXCEPTION(HttpConnectionRetryException, HttpException, 5) 21 | 22 | } /* namespace easyhttpcpp */ 23 | -------------------------------------------------------------------------------- /src/HttpExecutionTask.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_HTTPEXECUTIONTASK_H_INCLUDED 6 | #define EASYHTTPCPP_HTTPEXECUTIONTASK_H_INCLUDED 7 | 8 | #include "Poco/Void.h" 9 | 10 | #include "easyhttpcpp/executorservice/FutureTask.h" 11 | 12 | namespace easyhttpcpp { 13 | 14 | class HttpExecutionTaskListener; 15 | 16 | class HttpExecutionTask : public easyhttpcpp::executorservice::FutureTask { 17 | public: 18 | typedef Poco::AutoPtr Ptr; 19 | 20 | virtual ~HttpExecutionTask() 21 | { 22 | } 23 | }; 24 | 25 | } /* namespace easyhttpcpp */ 26 | 27 | #endif /* EASYHTTPCPP_HTTPEXECUTIONTASK_H_INCLUDED */ 28 | -------------------------------------------------------------------------------- /src/HttpExecutionTaskManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_HTTPEXECUTIONTASKMANAGER_H_INCLUDED 6 | #define EASYHTTPCPP_HTTPEXECUTIONTASKMANAGER_H_INCLUDED 7 | 8 | #include 9 | 10 | #include "Poco/AutoPtr.h" 11 | #include "Poco/Mutex.h" 12 | #include "Poco/RefCountedObject.h" 13 | 14 | #include "easyhttpcpp/executorservice/QueuedThreadPool.h" 15 | 16 | #include "HttpExecutionTask.h" 17 | 18 | namespace easyhttpcpp { 19 | 20 | class HttpExecutionTaskManager : public Poco::RefCountedObject { 21 | public: 22 | typedef Poco::AutoPtr Ptr; 23 | 24 | HttpExecutionTaskManager(unsigned int corePoolSizeOfAsyncThreadPool, unsigned int maximumPoolSizeOfAsyncThreadPool); 25 | virtual ~HttpExecutionTaskManager(); 26 | virtual void start(HttpExecutionTask::Ptr pExecutionTask); 27 | virtual void gracefulShutdown(); 28 | 29 | void onComplete(HttpExecutionTask::Ptr pExecutionTask); 30 | 31 | private: 32 | HttpExecutionTaskManager(); 33 | void removeTask(HttpExecutionTask::Ptr pExecutionTask); 34 | 35 | easyhttpcpp::executorservice::QueuedThreadPool::Ptr m_pAsyncThreadPool; 36 | Poco::FastMutex m_instanceMutex; 37 | typedef std::list ExecutionList; 38 | ExecutionList m_executionTaskList; 39 | bool m_terminated; 40 | }; 41 | 42 | } /* namespace easyhttpcpp */ 43 | 44 | #endif /* EASYHTTPCPP_HTTPEXECUTIONTASKMANAGER_H_INCLUDED */ 45 | -------------------------------------------------------------------------------- /src/HttpLruCacheStrategy.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_HTTPLRUCACHESTRATEGY_H_INCLUDED 6 | #define EASYHTTPCPP_HTTPLRUCACHESTRATEGY_H_INCLUDED 7 | 8 | #include "easyhttpcpp/common/LruCacheByDataSizeStrategy.h" 9 | #include "easyhttpcpp/HttpExports.h" 10 | 11 | namespace easyhttpcpp { 12 | 13 | class EASYHTTPCPP_HTTP_INTERNAL_API HttpLruCacheStrategy : public easyhttpcpp::common::LruCacheByDataSizeStrategy { 14 | public: 15 | HttpLruCacheStrategy(size_t maxSize); 16 | virtual ~HttpLruCacheStrategy(); 17 | 18 | virtual bool update(const std::string& key, easyhttpcpp::common::CacheInfoWithDataSize::Ptr pValue); 19 | virtual bool remove(const std::string& key); 20 | virtual bool clear(bool mayDeleteIfBusy); 21 | 22 | protected: 23 | virtual bool createRemoveList(LruKeyList& keys, bool mayDeleteIfBusy); 24 | virtual bool createRemoveLruDataList(LruKeyList& keys, size_t removeSize); 25 | virtual easyhttpcpp::common::CacheInfoWithDataSize::Ptr newCacheInfo( 26 | easyhttpcpp::common::CacheInfoWithDataSize::Ptr pCacheInfo); 27 | 28 | private: 29 | HttpLruCacheStrategy(); 30 | 31 | }; 32 | 33 | } /* namespace easyhttpcpp */ 34 | 35 | #endif /* EASYHTTPCPP_HTTPLRUCACHESTRATEGY_H_INCLUDED */ 36 | -------------------------------------------------------------------------------- /src/HttpRequestExecutor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_HTTPREQUESTEXECUTOR_H_INCLUDED 6 | #define EASYHTTPCPP_HTTPREQUESTEXECUTOR_H_INCLUDED 7 | 8 | #include "Poco/AutoPtr.h" 9 | #include "Poco/Mutex.h" 10 | #include "Poco/RefCountedObject.h" 11 | 12 | #include "easyhttpcpp/Request.h" 13 | #include "easyhttpcpp/Response.h" 14 | 15 | #include "EasyHttpContext.h" 16 | #include "HttpEngine.h" 17 | 18 | namespace easyhttpcpp { 19 | 20 | class HttpRequestExecutor : public Poco::RefCountedObject { 21 | public: 22 | typedef Poco::AutoPtr Ptr; 23 | 24 | HttpRequestExecutor(EasyHttpContext::Ptr pContext, Request::Ptr pRequest); 25 | virtual ~HttpRequestExecutor(); 26 | 27 | Response::Ptr execute(); 28 | Response::Ptr executeAfterIntercept(Request::Ptr pRequest); 29 | bool cancel(); 30 | bool isCancelled() const; 31 | HttpEngine::Ptr getHttpEngine(); 32 | 33 | private: 34 | HttpRequestExecutor(); 35 | Response::Ptr executeWithRetry(Request::Ptr pRequest); 36 | 37 | EasyHttpContext::Ptr m_pContext; 38 | Request::Ptr m_pUserRequest; 39 | Response::Ptr m_pUserResponse; 40 | HttpEngine::Ptr m_pHttpEngine; 41 | bool m_cancelled; 42 | Poco::FastMutex m_cancelMutex; 43 | }; 44 | 45 | } /* namespace easyhttpcpp */ 46 | 47 | #endif /* EASYHTTPCPP_HTTPREQUESTEXECUTOR_H_INCLUDED */ 48 | -------------------------------------------------------------------------------- /src/HttpTypedefs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_HTTPTYPEDEFS_H_INCLUDED 6 | #define EASYHTTPCPP_HTTPTYPEDEFS_H_INCLUDED 7 | 8 | #include "Poco/AutoPtr.h" 9 | #include "Poco/RefCountedObject.h" 10 | #include "Poco/Net/HTTPClientSession.h" 11 | 12 | namespace easyhttpcpp { 13 | 14 | typedef Poco::SharedPtr PocoHttpClientSessionPtr; 15 | 16 | } /* namespace easyhttpcpp */ 17 | 18 | #endif /* EASYHTTPCPP_HTTPTYPEDEFS_H_INCLUDED */ 19 | -------------------------------------------------------------------------------- /src/HttpUtil.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_HTTPUTIL_H_INCLUDED 6 | #define EASYHTTPCPP_HTTPUTIL_H_INCLUDED 7 | 8 | #include 9 | 10 | #include "Poco/Path.h" 11 | #include "Poco/Timestamp.h" 12 | 13 | #include "easyhttpcpp/Headers.h" 14 | #include "easyhttpcpp/HttpExports.h" 15 | #include "easyhttpcpp/Request.h" 16 | 17 | namespace easyhttpcpp { 18 | 19 | class EASYHTTPCPP_HTTP_INTERNAL_API HttpUtil { 20 | public: 21 | static const std::string& httpMethodToString(Request::HttpMethod httpMethod); 22 | static bool tryParseDate(const std::string& value, Poco::Timestamp& timeStamp); 23 | static std::string makeCacheKey(Request::Ptr pRequest); 24 | static std::string makeCacheKey(Request::HttpMethod httpMethod, const std::string& url); 25 | static std::string makeCachedResponseBodyFilename(const Poco::Path& cacheRootDir, const std::string& key); 26 | static Headers::Ptr exchangeJsonStrToHeaders(const std::string& headerJsonStr); 27 | static std::string exchangeHeadersToJsonStr(Headers::Ptr pHeaders); 28 | private: 29 | HttpUtil(); 30 | }; 31 | 32 | } /* namespace easyhttpcpp */ 33 | 34 | #endif /* EASYHTTPCPP_HTTPUTIL_H_INCLUDED */ 35 | -------------------------------------------------------------------------------- /src/KeepAliveTimeoutListener.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_KEEPALIVETIMEOUTLISTENER_H_INCLUDED 6 | #define EASYHTTPCPP_KEEPALIVETIMEOUTLISTENER_H_INCLUDED 7 | 8 | namespace easyhttpcpp { 9 | 10 | class KeepAliveTimeoutTask; 11 | 12 | class KeepAliveTimeoutListener { 13 | public: 14 | virtual ~KeepAliveTimeoutListener() 15 | { 16 | } 17 | 18 | virtual void onKeepAliveTimeoutExpired(const KeepAliveTimeoutTask* pKeepAliveTimeoutTask) = 0; 19 | }; 20 | 21 | } /* namespace easyhttpcpp */ 22 | 23 | #endif /* EASYHTTPCPP_KEEPALIVETIMEOUTLISTENER_H_INCLUDED */ 24 | -------------------------------------------------------------------------------- /src/KeepAliveTimeoutTask.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "easyhttpcpp/common/CoreLogger.h" 6 | 7 | #include "ConnectionInternal.h" 8 | #include "KeepAliveTimeoutListener.h" 9 | #include "KeepAliveTimeoutTask.h" 10 | 11 | namespace easyhttpcpp { 12 | 13 | static const std::string Tag = "KeepAliveTimeoutTask"; 14 | 15 | KeepAliveTimeoutTask::KeepAliveTimeoutTask(Poco::Timestamp& expirationTime, 16 | KeepAliveTimeoutListener* pKeepAliveTimeoutListener) 17 | : m_keepAliveTimeoutExpirationTime(expirationTime), m_pKeepAliveTimeoutListener(pKeepAliveTimeoutListener) 18 | { 19 | EASYHTTPCPP_LOG_D(Tag, "create this=[%p]", this); 20 | } 21 | 22 | KeepAliveTimeoutTask::~KeepAliveTimeoutTask() 23 | { 24 | } 25 | 26 | void KeepAliveTimeoutTask::run() 27 | { 28 | if (m_pKeepAliveTimeoutListener) { 29 | m_pKeepAliveTimeoutListener->onKeepAliveTimeoutExpired(this); 30 | } 31 | } 32 | 33 | Poco::Timestamp& KeepAliveTimeoutTask::getKeepAliveTimeoutExpirationTime() 34 | { 35 | return m_keepAliveTimeoutExpirationTime; 36 | } 37 | 38 | } /* namespace easyhttpcpp */ 39 | -------------------------------------------------------------------------------- /src/KeepAliveTimeoutTask.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_KEEPALIVETIMEOUTTASK_H_INCLUDED 6 | #define EASYHTTPCPP_KEEPALIVETIMEOUTTASK_H_INCLUDED 7 | 8 | #include "Poco/AutoPtr.h" 9 | #include "Poco/RefCountedObject.h" 10 | #include "Poco/Timestamp.h" 11 | #include "Poco/Util/TimerTask.h" 12 | 13 | #include "easyhttpcpp/HttpExports.h" 14 | 15 | namespace easyhttpcpp { 16 | 17 | class KeepAliveTimeoutListener; 18 | 19 | class EASYHTTPCPP_HTTP_INTERNAL_API KeepAliveTimeoutTask : public Poco::Util::TimerTask { 20 | public: 21 | typedef Poco::AutoPtr Ptr; 22 | 23 | KeepAliveTimeoutTask(Poco::Timestamp& expirationTime, KeepAliveTimeoutListener* pKeepAliveTimeoutListener); 24 | virtual ~KeepAliveTimeoutTask(); 25 | 26 | virtual void run(); 27 | 28 | virtual Poco::Timestamp& getKeepAliveTimeoutExpirationTime(); 29 | 30 | private: 31 | Poco::Timestamp m_keepAliveTimeoutExpirationTime; 32 | KeepAliveTimeoutListener* m_pKeepAliveTimeoutListener; 33 | }; 34 | 35 | } /* namespace easyhttpcpp */ 36 | 37 | #endif /* EASYHTTPCPP_KEEPALIVETIMEOUTTASK_H_INCLUDED */ 38 | -------------------------------------------------------------------------------- /src/LoggingInterceptorFactory.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "easyhttpcpp/common/StringUtil.h" 6 | #include "easyhttpcpp/HttpException.h" 7 | #include "easyhttpcpp/LoggingInterceptorFactory.h" 8 | 9 | #include "CallLoggingInterceptor.h" 10 | #include "NetworkLoggingInterceptor.h" 11 | 12 | using easyhttpcpp::common::StringUtil; 13 | 14 | namespace easyhttpcpp { 15 | 16 | LoggingInterceptorFactory::LoggingInterceptorFactory() 17 | { 18 | } 19 | 20 | LoggingInterceptorFactory::~LoggingInterceptorFactory() 21 | { 22 | } 23 | 24 | LoggingInterceptor::Ptr LoggingInterceptorFactory::interceptor(LoggingInterceptorType interceptorType) 25 | { 26 | switch (interceptorType) { 27 | case LoggingInterceptorTypeCall: 28 | return new CallLoggingInterceptor(); 29 | case LoggingInterceptorTypeNetwork: 30 | return new NetworkLoggingInterceptor(); 31 | default: 32 | throw HttpIllegalArgumentException(StringUtil::format("Unknown logging interceptor type: [%d]", 33 | interceptorType)); 34 | } 35 | } 36 | 37 | } /* namespace easyhttpcpp */ 38 | 39 | -------------------------------------------------------------------------------- /src/MediaType.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "easyhttpcpp/common/CoreLogger.h" 6 | #include "easyhttpcpp/HttpException.h" 7 | #include "easyhttpcpp/MediaType.h" 8 | 9 | namespace easyhttpcpp { 10 | 11 | static const std::string Tag = "MediaType"; 12 | 13 | MediaType::MediaType(const std::string& contentType) 14 | { 15 | m_contentType = contentType; 16 | } 17 | 18 | MediaType::~MediaType() 19 | { 20 | } 21 | 22 | std::string MediaType::toString() 23 | { 24 | return m_contentType; 25 | } 26 | 27 | } /* namespace easyhttpcpp */ 28 | -------------------------------------------------------------------------------- /src/NetworkInterceptorChain.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "NetworkInterceptorChain.h" 6 | 7 | namespace easyhttpcpp { 8 | 9 | NetworkInterceptorChain::NetworkInterceptorChain(HttpEngine& httpEngine, Request::Ptr pRequest, 10 | EasyHttpContext::InterceptorList::iterator& currentIterator, 11 | EasyHttpContext::InterceptorList::const_iterator& endIterator) : 12 | m_httpEngine(httpEngine), m_pRequest(pRequest), m_currentIterator(currentIterator), m_endIterator(endIterator) 13 | { 14 | } 15 | 16 | NetworkInterceptorChain::~NetworkInterceptorChain() 17 | { 18 | } 19 | 20 | Request::Ptr NetworkInterceptorChain::getRequest() const 21 | { 22 | return m_pRequest; 23 | } 24 | 25 | Connection::Ptr NetworkInterceptorChain::getConnection() const 26 | { 27 | return m_httpEngine.getConnection(); 28 | } 29 | 30 | Response::Ptr NetworkInterceptorChain::proceed(Request::Ptr pRequest) 31 | { 32 | Response::Ptr pResponse; 33 | m_currentIterator++; 34 | if (m_currentIterator != m_endIterator) { 35 | NetworkInterceptorChain* pNetworkInterpectorChain = new NetworkInterceptorChain(m_httpEngine, pRequest, 36 | m_currentIterator, m_endIterator); 37 | Interceptor::Chain::Ptr pChain = pNetworkInterpectorChain; 38 | pResponse = (*m_currentIterator)->intercept(*pNetworkInterpectorChain); 39 | } else { 40 | pResponse = m_httpEngine.sendRequestAndReceiveResponseWithRetryByConnection(pRequest); 41 | } 42 | return pResponse; 43 | } 44 | 45 | } /* namespace easyhttpcpp */ 46 | -------------------------------------------------------------------------------- /src/NetworkInterceptorChain.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_NETWORKINTERCEPTORCHAIN_H_INCLUDED 6 | #define EASYHTTPCPP_NETWORKINTERCEPTORCHAIN_H_INCLUDED 7 | 8 | #include "easyhttpcpp/Interceptor.h" 9 | 10 | #include "EasyHttpContext.h" 11 | #include "HttpEngine.h" 12 | 13 | namespace easyhttpcpp { 14 | 15 | class NetworkInterceptorChain : public Interceptor::Chain { 16 | public: 17 | NetworkInterceptorChain(HttpEngine& httpEngine, Request::Ptr pRequest, 18 | EasyHttpContext::InterceptorList::iterator& currentIterator, 19 | EasyHttpContext::InterceptorList::const_iterator& endIterator); 20 | virtual ~NetworkInterceptorChain(); 21 | virtual Request::Ptr getRequest() const; 22 | virtual Connection::Ptr getConnection() const; 23 | virtual Response::Ptr proceed(Request::Ptr pRequest); 24 | 25 | private: 26 | HttpEngine& m_httpEngine; 27 | Request::Ptr m_pRequest; 28 | EasyHttpContext::InterceptorList::iterator& m_currentIterator; 29 | EasyHttpContext::InterceptorList::const_iterator& m_endIterator; 30 | }; 31 | 32 | } /* namespace easyhttpcpp */ 33 | 34 | #endif /* EASYHTTPCPP_NETWORKINTERCEPTORCHAIN_H_INCLUDED */ 35 | -------------------------------------------------------------------------------- /src/NetworkLoggingInterceptor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_NETWORKLOGGINGINTERCEPTOR_H_INCLUDED 6 | #define EASYHTTPCPP_NETWORKLOGGINGINTERCEPTOR_H_INCLUDED 7 | 8 | #include "easyhttpcpp/LoggingInterceptor.h" 9 | 10 | namespace easyhttpcpp { 11 | 12 | class NetworkLoggingInterceptor : public LoggingInterceptor { 13 | public: 14 | NetworkLoggingInterceptor(); 15 | virtual ~NetworkLoggingInterceptor(); 16 | 17 | virtual Response::Ptr intercept(Chain& chain); 18 | }; 19 | 20 | } /* namespace easyhttpcpp */ 21 | 22 | #endif /* EASYHTTPCPP_NETWORKLOGGINGINTERCEPTOR_H_INCLUDED */ 23 | -------------------------------------------------------------------------------- /src/Proxy.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "easyhttpcpp/common/StringUtil.h" 6 | #include "easyhttpcpp/Proxy.h" 7 | 8 | using easyhttpcpp::common::StringUtil; 9 | 10 | namespace easyhttpcpp { 11 | 12 | Proxy::Proxy(const std::string& host, unsigned short port) : m_host(host), m_port(port) 13 | { 14 | } 15 | 16 | Proxy::~Proxy() 17 | { 18 | } 19 | 20 | const std::string& Proxy::getHost() const 21 | { 22 | return m_host; 23 | } 24 | 25 | unsigned short Proxy::getPort() const 26 | { 27 | return m_port; 28 | } 29 | 30 | std::string Proxy::toString() 31 | { 32 | return StringUtil::format("%s:%d", m_host.c_str(), m_port); 33 | } 34 | 35 | bool Proxy::operator == (const Proxy& proxy) const 36 | { 37 | return equals(proxy); 38 | } 39 | 40 | bool Proxy::operator != (const Proxy& proxy) const 41 | { 42 | return !equals(proxy); 43 | } 44 | 45 | bool Proxy::equals(const Proxy& proxy) const 46 | { 47 | return (m_host == proxy.m_host && m_port == proxy.m_port); 48 | } 49 | 50 | } /* namespace easyhttpcpp */ 51 | -------------------------------------------------------------------------------- /src/RequestBodyForByteBuffer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include 6 | 7 | #include "Poco/Exception.h" 8 | 9 | #include "easyhttpcpp/common/CoreLogger.h" 10 | #include "easyhttpcpp/HttpException.h" 11 | 12 | #include "RequestBodyForByteBuffer.h" 13 | #include "RequestBodyUtil.h" 14 | 15 | #if defined(_WIN64) 16 | #define SSIZE_MAX _I64_MAX 17 | #elif defined(_WIN32) 18 | #define SSIZE_MAX LONG_MAX 19 | #endif 20 | 21 | namespace easyhttpcpp { 22 | 23 | static const std::string Tag = "RequestBodyForByteBuffer"; 24 | 25 | RequestBodyForByteBuffer::RequestBodyForByteBuffer(MediaType::Ptr pMediaType, 26 | const easyhttpcpp::common::ByteArrayBuffer& content) : RequestBody(pMediaType), m_content(content) 27 | { 28 | if (m_content.getWrittenDataSize() > SSIZE_MAX) { 29 | EASYHTTPCPP_LOG_D(Tag, "Buffer size: [%zu] is too long.", m_content.getWrittenDataSize()); 30 | throw HttpIllegalArgumentException("Buffer size is too long."); 31 | } 32 | } 33 | 34 | RequestBodyForByteBuffer::~RequestBodyForByteBuffer() 35 | { 36 | } 37 | 38 | void RequestBodyForByteBuffer::writeTo(std::ostream& outStream) 39 | { 40 | RequestBodyUtil::write(m_content, outStream); 41 | } 42 | 43 | bool RequestBodyForByteBuffer::hasContentLength() const 44 | { 45 | return true; 46 | } 47 | 48 | ssize_t RequestBodyForByteBuffer::getContentLength() const 49 | { 50 | return m_content.getWrittenDataSize(); 51 | } 52 | 53 | bool RequestBodyForByteBuffer::reset() 54 | { 55 | return true; 56 | } 57 | 58 | } /* namespace easyhttpcpp */ 59 | -------------------------------------------------------------------------------- /src/RequestBodyForByteBuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_REQUESTBODYFORBYTEBUFFER_H_INCLUDED 6 | #define EASYHTTPCPP_REQUESTBODYFORBYTEBUFFER_H_INCLUDED 7 | 8 | #include "easyhttpcpp/HttpExports.h" 9 | #include "easyhttpcpp/RequestBody.h" 10 | 11 | namespace easyhttpcpp { 12 | 13 | class EASYHTTPCPP_HTTP_INTERNAL_API RequestBodyForByteBuffer : public RequestBody { 14 | public: 15 | RequestBodyForByteBuffer(MediaType::Ptr pMediaType, const easyhttpcpp::common::ByteArrayBuffer& content); 16 | virtual ~RequestBodyForByteBuffer(); 17 | virtual void writeTo(std::ostream& outStream); 18 | virtual bool hasContentLength() const; 19 | virtual ssize_t getContentLength() const; 20 | virtual bool reset(); 21 | private: 22 | const easyhttpcpp::common::ByteArrayBuffer& m_content; 23 | }; 24 | 25 | } /* namespace easyhttpcpp */ 26 | 27 | #endif /* EASYHTTPCPP_REQUESTBODYFORBYTEBUFFER_H_INCLUDED */ 28 | -------------------------------------------------------------------------------- /src/RequestBodyForSharedPtrByteBuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_REQUESTBODYFORSHAREDPTRBYTEBUFFER_H_INCLUDED 6 | #define EASYHTTPCPP_REQUESTBODYFORSHAREDPTRBYTEBUFFER_H_INCLUDED 7 | 8 | #include "Poco/SharedPtr.h" 9 | 10 | #include "easyhttpcpp/HttpExports.h" 11 | #include "easyhttpcpp/RequestBody.h" 12 | 13 | namespace easyhttpcpp { 14 | 15 | class EASYHTTPCPP_HTTP_INTERNAL_API RequestBodyForSharedPtrByteBuffer : public RequestBody { 16 | public: 17 | RequestBodyForSharedPtrByteBuffer(MediaType::Ptr pMediaType, 18 | Poco::SharedPtr pContent); 19 | virtual ~RequestBodyForSharedPtrByteBuffer(); 20 | virtual void writeTo(std::ostream& outStream); 21 | virtual bool hasContentLength() const; 22 | virtual ssize_t getContentLength() const; 23 | virtual bool reset(); 24 | private: 25 | Poco::SharedPtr m_pContent; 26 | }; 27 | 28 | } /* namespace easyhttpcpp */ 29 | 30 | #endif /* EASYHTTPCPP_REQUESTBODYFORSHAREDPTRBYTEBUFFER_H_INCLUDED */ 31 | -------------------------------------------------------------------------------- /src/RequestBodyForSharedPtrStream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_REQUESTBODYFORSHAREDPTRSTREAM_H_INCLUDED 6 | #define EASYHTTPCPP_REQUESTBODYFORSHAREDPTRSTREAM_H_INCLUDED 7 | 8 | #include 9 | 10 | #include "Poco/SharedPtr.h" 11 | 12 | #include "easyhttpcpp/HttpExports.h" 13 | #include "easyhttpcpp/RequestBody.h" 14 | 15 | namespace easyhttpcpp { 16 | 17 | class EASYHTTPCPP_HTTP_INTERNAL_API RequestBodyForSharedPtrStream : public RequestBody { 18 | public: 19 | RequestBodyForSharedPtrStream(MediaType::Ptr pMediaType, Poco::SharedPtr pContent); 20 | virtual ~RequestBodyForSharedPtrStream(); 21 | virtual void writeTo(std::ostream& outStream); 22 | virtual bool hasContentLength() const; 23 | virtual ssize_t getContentLength() const; 24 | virtual bool reset(); 25 | private: 26 | Poco::SharedPtr m_pContent; 27 | }; 28 | 29 | } /* namespace easyhttpcpp */ 30 | 31 | #endif /* EASYHTTPCPP_REQUESTBODYFORSHAREDPTRSTREAM_H_INCLUDED */ 32 | -------------------------------------------------------------------------------- /src/RequestBodyForSharedPtrString.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Sony Corporation 3 | */ 4 | 5 | #include "Poco/Exception.h" 6 | 7 | #include "easyhttpcpp/common/CoreLogger.h" 8 | #include "easyhttpcpp/HttpException.h" 9 | 10 | #include "RequestBodyForSharedPtrString.h" 11 | #include "RequestBodyUtil.h" 12 | 13 | namespace easyhttpcpp { 14 | 15 | static const std::string Tag = "RequestBodyForSharedPtrString"; 16 | 17 | RequestBodyForSharedPtrString::RequestBodyForSharedPtrString(MediaType::Ptr pMediaType, 18 | Poco::SharedPtr pContent) : RequestBody(pMediaType), m_pContent(pContent) 19 | { 20 | if (!m_pContent) { 21 | EASYHTTPCPP_LOG_D(Tag, "pContent cannot be NULL."); 22 | throw HttpIllegalArgumentException("pContent cannot be NULL."); 23 | } 24 | } 25 | 26 | RequestBodyForSharedPtrString::~RequestBodyForSharedPtrString() 27 | { 28 | } 29 | 30 | void RequestBodyForSharedPtrString::writeTo(std::ostream& outStream) 31 | { 32 | RequestBodyUtil::write(*m_pContent, outStream); 33 | } 34 | 35 | bool RequestBodyForSharedPtrString::hasContentLength() const 36 | { 37 | return true; 38 | } 39 | 40 | ssize_t RequestBodyForSharedPtrString::getContentLength() const 41 | { 42 | return m_pContent->size(); 43 | } 44 | 45 | bool RequestBodyForSharedPtrString::reset() 46 | { 47 | return true; 48 | } 49 | 50 | } /* namespace easyhttpcpp */ 51 | -------------------------------------------------------------------------------- /src/RequestBodyForSharedPtrString.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_REQUESTBODYFORSHAREDPTRSTRING_H_INCLUDED 6 | #define EASYHTTPCPP_REQUESTBODYFORSHAREDPTRSTRING_H_INCLUDED 7 | 8 | #include 9 | 10 | #include "Poco/SharedPtr.h" 11 | 12 | #include "easyhttpcpp/HttpExports.h" 13 | #include "easyhttpcpp/RequestBody.h" 14 | 15 | namespace easyhttpcpp { 16 | 17 | class EASYHTTPCPP_HTTP_INTERNAL_API RequestBodyForSharedPtrString : public RequestBody { 18 | public: 19 | RequestBodyForSharedPtrString(MediaType::Ptr pMediaType, Poco::SharedPtr pContent); 20 | virtual ~RequestBodyForSharedPtrString(); 21 | virtual void writeTo(std::ostream& outStream); 22 | virtual bool hasContentLength() const; 23 | virtual ssize_t getContentLength() const; 24 | virtual bool reset(); 25 | private: 26 | Poco::SharedPtr m_pContent; 27 | }; 28 | 29 | } /* namespace easyhttpcpp */ 30 | 31 | #endif /* EASYHTTPCPP_REQUESTBODYFORSHAREDPTRSTRING_H_INCLUDED */ 32 | -------------------------------------------------------------------------------- /src/RequestBodyForStream.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "Poco/Exception.h" 6 | 7 | #include "easyhttpcpp/common/CoreLogger.h" 8 | #include "easyhttpcpp/HttpException.h" 9 | 10 | #include "RequestBodyForStream.h" 11 | #include "RequestBodyUtil.h" 12 | 13 | namespace easyhttpcpp { 14 | 15 | static const std::string Tag = "RequestBodyForStream"; 16 | 17 | RequestBodyForStream::RequestBodyForStream(MediaType::Ptr pMediaType, std::istream& content) : 18 | RequestBody(pMediaType), m_pContent(&content) 19 | { 20 | } 21 | 22 | RequestBodyForStream::~RequestBodyForStream() 23 | { 24 | } 25 | 26 | void RequestBodyForStream::writeTo(std::ostream& outStream) 27 | { 28 | RequestBodyUtil::write(*m_pContent, outStream); 29 | } 30 | 31 | bool RequestBodyForStream::hasContentLength() const 32 | { 33 | return false; 34 | } 35 | 36 | ssize_t RequestBodyForStream::getContentLength() const 37 | { 38 | return -1; 39 | } 40 | 41 | bool RequestBodyForStream::reset() 42 | { 43 | if (m_pContent->seekg(0, std::istream::beg).fail()) { 44 | EASYHTTPCPP_LOG_D(Tag, "reset: failed to reset."); 45 | return false; 46 | } else { 47 | EASYHTTPCPP_LOG_D(Tag, "reset: succeeded to reset."); 48 | return true; 49 | } 50 | } 51 | 52 | } /* namespace easyhttpcpp */ 53 | -------------------------------------------------------------------------------- /src/RequestBodyForStream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_REQUESTBODYFORSTREAM_H_INCLUDED 6 | #define EASYHTTPCPP_REQUESTBODYFORSTREAM_H_INCLUDED 7 | 8 | #include 9 | 10 | #include "easyhttpcpp/HttpExports.h" 11 | #include "easyhttpcpp/RequestBody.h" 12 | 13 | namespace easyhttpcpp { 14 | 15 | class EASYHTTPCPP_HTTP_INTERNAL_API RequestBodyForStream : public RequestBody { 16 | public: 17 | RequestBodyForStream(MediaType::Ptr pMediaType, std::istream& content); 18 | virtual ~RequestBodyForStream(); 19 | virtual void writeTo(std::ostream& outStream); 20 | virtual bool hasContentLength() const; 21 | virtual ssize_t getContentLength() const; 22 | virtual bool reset(); 23 | private: 24 | std::istream* m_pContent; 25 | }; 26 | 27 | } /* namespace easyhttpcpp */ 28 | 29 | #endif /* EASYHTTPCPP_REQUESTBODYFORSTREAM_H_INCLUDED */ 30 | -------------------------------------------------------------------------------- /src/RequestBodyForString.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "Poco/Exception.h" 6 | 7 | #include "easyhttpcpp/common/CoreLogger.h" 8 | #include "easyhttpcpp/HttpException.h" 9 | 10 | #include "RequestBodyForString.h" 11 | #include "RequestBodyUtil.h" 12 | 13 | namespace easyhttpcpp { 14 | 15 | static const std::string Tag = "RequestBodyForString"; 16 | 17 | RequestBodyForString::RequestBodyForString(MediaType::Ptr pMediaType, const std::string& content) : 18 | RequestBody(pMediaType), m_pContent(&content) 19 | { 20 | } 21 | 22 | RequestBodyForString::~RequestBodyForString() 23 | { 24 | } 25 | 26 | void RequestBodyForString::writeTo(std::ostream& outStream) 27 | { 28 | RequestBodyUtil::write(*m_pContent, outStream); 29 | } 30 | 31 | bool RequestBodyForString::hasContentLength() const 32 | { 33 | return true; 34 | } 35 | 36 | ssize_t RequestBodyForString::getContentLength() const 37 | { 38 | return m_pContent->size(); 39 | } 40 | 41 | bool RequestBodyForString::reset() 42 | { 43 | return true; 44 | } 45 | 46 | } /* namespace easyhttpcpp */ 47 | -------------------------------------------------------------------------------- /src/RequestBodyForString.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_REQUESTBODYFORSTRING_H_INCLUDED 6 | #define EASYHTTPCPP_REQUESTBODYFORSTRING_H_INCLUDED 7 | 8 | #include 9 | 10 | #include "easyhttpcpp/HttpExports.h" 11 | #include "easyhttpcpp/RequestBody.h" 12 | 13 | namespace easyhttpcpp { 14 | 15 | class EASYHTTPCPP_HTTP_INTERNAL_API RequestBodyForString : public RequestBody { 16 | public: 17 | RequestBodyForString(MediaType::Ptr pMediaType, const std::string& content); 18 | virtual ~RequestBodyForString(); 19 | virtual void writeTo(std::ostream& outStream); 20 | virtual bool hasContentLength() const; 21 | virtual ssize_t getContentLength() const; 22 | virtual bool reset(); 23 | private: 24 | const std::string* m_pContent; 25 | }; 26 | 27 | } /* namespace easyhttpcpp */ 28 | 29 | #endif /* EASYHTTPCPP_REQUESTBODYFORSTRING_H_INCLUDED */ 30 | -------------------------------------------------------------------------------- /src/RequestBodyUtil.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_REQUESTBODYUTIL_H_INCLUDED 6 | #define EASYHTTPCPP_REQUESTBODYUTIL_H_INCLUDED 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #ifdef _WIN32 13 | #include 14 | typedef SSIZE_T ssize_t; 15 | #endif 16 | 17 | #include "easyhttpcpp/common/ByteArrayBuffer.h" 18 | 19 | namespace easyhttpcpp { 20 | 21 | class RequestBodyUtil { 22 | public: 23 | static void write(const easyhttpcpp::common::ByteArrayBuffer& inBuffer, std::ostream& outStream); 24 | static void write(std::istream& inStream, std::ostream& outStream); 25 | static void write(const std::string& inBuffer, std::ostream& outStream); 26 | 27 | private: 28 | RequestBodyUtil(); 29 | }; 30 | 31 | } /* namespace easyhttpcpp */ 32 | 33 | #endif /* EASYHTTPCPP_REQUESTBODYUTIL_H_INCLUDED */ 34 | -------------------------------------------------------------------------------- /src/ResponseBodyStreamFromCache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_RESPONSEBODYSTREAMFROMCACHE_H_INCLUDED 6 | #define EASYHTTPCPP_RESPONSEBODYSTREAMFROMCACHE_H_INCLUDED 7 | 8 | #include "easyhttpcpp/HttpCache.h" 9 | #include "easyhttpcpp/HttpExports.h" 10 | #include "easyhttpcpp/Response.h" 11 | 12 | #include "ResponseBodyStreamInternal.h" 13 | 14 | namespace easyhttpcpp { 15 | 16 | class EASYHTTPCPP_HTTP_INTERNAL_API ResponseBodyStreamFromCache : public ResponseBodyStreamInternal { 17 | public: 18 | ResponseBodyStreamFromCache(std::istream* pContent, Response::Ptr pResponse, HttpCache::Ptr pHttpCache); 19 | virtual ~ResponseBodyStreamFromCache(); 20 | virtual void close(); 21 | private: 22 | std::istream* m_pContent; 23 | Response::Ptr m_pResponse; 24 | HttpCache::Ptr m_pHttpCache; 25 | }; 26 | 27 | } /* namespace easyhttpcpp */ 28 | 29 | #endif /* EASYHTTPCPP_RESPONSEBODYSTREAMFROMCACHE_H_INCLUDED */ 30 | -------------------------------------------------------------------------------- /src/ResponseBodyStreamInternal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_RESPONSEBODYSTREAMINTERNAL_H_INCLUDED 6 | #define EASYHTTPCPP_RESPONSEBODYSTREAMINTERNAL_H_INCLUDED 7 | 8 | #include 9 | 10 | #include "Poco/Mutex.h" 11 | 12 | #include "easyhttpcpp/HttpExports.h" 13 | #include "easyhttpcpp/ResponseBodyStream.h" 14 | 15 | #include "HttpTypedefs.h" 16 | 17 | namespace easyhttpcpp { 18 | 19 | class EASYHTTPCPP_HTTP_INTERNAL_API ResponseBodyStreamInternal : public ResponseBodyStream { 20 | public: 21 | ResponseBodyStreamInternal(std::istream& content); 22 | virtual ~ResponseBodyStreamInternal(); 23 | 24 | virtual ssize_t read(char* pBuffer, size_t readBytes); 25 | virtual bool isEof(); 26 | virtual void close(); 27 | 28 | protected: 29 | virtual bool skipAll(PocoHttpClientSessionPtr pPocoHttpClientSession); 30 | 31 | Poco::Mutex m_instanceMutex; 32 | bool m_closed; 33 | std::istream& m_content; 34 | }; 35 | 36 | } /* namespace easyhttpcpp */ 37 | 38 | #endif /* EASYHTTPCPP_RESPONSEBODYSTREAMINTERNAL_H_INCLUDED */ 39 | -------------------------------------------------------------------------------- /src/ResponseBodyStreamWithoutCaching.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_RESPONSEBODYSTREAMWITHOURCACHING_H_INCLUDED 6 | #define EASYHTTPCPP_RESPONSEBODYSTREAMWITHOURCACHING_H_INCLUDED 7 | 8 | #include "easyhttpcpp/HttpExports.h" 9 | 10 | #include "ConnectionInternal.h" 11 | #include "ConnectionPoolInternal.h" 12 | #include "HttpEngine.h" 13 | #include "ResponseBodyStreamInternal.h" 14 | 15 | namespace easyhttpcpp { 16 | 17 | class EASYHTTPCPP_HTTP_INTERNAL_API ResponseBodyStreamWithoutCaching : public ResponseBodyStreamInternal { 18 | public: 19 | ResponseBodyStreamWithoutCaching(std::istream& content, ConnectionInternal::Ptr pConnectionInternal, 20 | ConnectionPoolInternal::Ptr pConnectionPoolInternal); 21 | virtual ~ResponseBodyStreamWithoutCaching(); 22 | virtual void close(); 23 | 24 | ResponseBodyStream::Ptr exchangeToResponseBodyStreamWithCaching(Response::Ptr pResponse, HttpCache::Ptr pHttpCache); 25 | Connection::Ptr getConnection(); // for test 26 | 27 | private: 28 | ConnectionInternal::Ptr m_pConnectionInternal; 29 | ConnectionPoolInternal::Ptr m_pConnectionPoolInternal; 30 | }; 31 | 32 | } /* namespace easyhttpcpp */ 33 | 34 | #endif /* EASYHTTPCPP_RESPONSEBODYSTREAMWITHOURCACHING_H_INCLUDED */ 35 | -------------------------------------------------------------------------------- /src/SslContextCreator.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "SslContextCreator.h" 6 | #include "SslContextCreatorImpl.h" 7 | 8 | namespace easyhttpcpp { 9 | 10 | Poco::Net::Context::Ptr SslContextCreator::createContext(EasyHttpContext::Ptr pContext) 11 | { 12 | return SslContextCreatorImpl::createContext(pContext); 13 | } 14 | 15 | } /* namespace easyhttpcpp */ 16 | -------------------------------------------------------------------------------- /src/SslContextCreator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_SSLCONTEXTCREATOR_H_INCLUDED 6 | #define EASYHTTPCPP_SSLCONTEXTCREATOR_H_INCLUDED 7 | 8 | #include "Poco/Net/Context.h" 9 | 10 | #include "EasyHttpContext.h" 11 | 12 | namespace easyhttpcpp { 13 | 14 | class SslContextCreator { 15 | public: 16 | static Poco::Net::Context::Ptr createContext(EasyHttpContext::Ptr pContext); 17 | private: 18 | SslContextCreator(); 19 | }; 20 | 21 | } /* namespace easyhttpcpp */ 22 | 23 | #endif /* EASYHTTPCPP_SSLCONTEXTCREATOR_H_INCLUDED */ 24 | -------------------------------------------------------------------------------- /src/common/AtomicBool.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "easyhttpcpp/common/AtomicBool.h" 6 | 7 | namespace easyhttpcpp { 8 | namespace common { 9 | 10 | AtomicBool::AtomicBool(bool initValue) : m_value(initValue) 11 | { 12 | } 13 | 14 | AtomicBool::~AtomicBool() 15 | { 16 | } 17 | 18 | void AtomicBool::set(bool newValue) 19 | { 20 | Poco::FastMutex::ScopedLock lock(m_instanceMutex); 21 | 22 | m_value = newValue; 23 | } 24 | 25 | bool AtomicBool::get() const 26 | { 27 | Poco::FastMutex::ScopedLock lock(m_instanceMutex); 28 | 29 | return m_value; 30 | } 31 | 32 | bool AtomicBool::compareAndSet(bool expect, bool update) 33 | { 34 | Poco::FastMutex::ScopedLock lock(m_instanceMutex); 35 | 36 | if (m_value != expect) { 37 | return false; 38 | } 39 | 40 | m_value = update; 41 | return true; 42 | } 43 | 44 | } /* namespace common */ 45 | } /* namespace easyhttpcpp */ 46 | -------------------------------------------------------------------------------- /src/common/CacheMetadata.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "easyhttpcpp/common/CacheMetadata.h" 6 | 7 | namespace easyhttpcpp { 8 | namespace common { 9 | 10 | CacheMetadata::CacheMetadata() 11 | { 12 | } 13 | 14 | CacheMetadata::~CacheMetadata() 15 | { 16 | } 17 | 18 | void CacheMetadata::setKey(const std::string& key) 19 | { 20 | m_key = key; 21 | } 22 | 23 | const std::string& CacheMetadata::getKey() const 24 | { 25 | return m_key; 26 | } 27 | 28 | } /* namespace common */ 29 | } /* namespace easyhttpcpp */ 30 | -------------------------------------------------------------------------------- /src/common/ColorConsoleChannelCreator.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "Poco/AutoPtr.h" 6 | 7 | #include "ColorConsoleChannelCreator.h" 8 | #include "ColorConsoleChannelCreatorImpl.h" 9 | 10 | namespace easyhttpcpp { 11 | namespace common { 12 | 13 | Poco::AutoPtr ColorConsoleChannelCreator::create() 14 | { 15 | return ColorConsoleChannelCreatorImpl::create(); 16 | } 17 | 18 | } /* namespace common */ 19 | } /* namespace easyhttpcpp */ 20 | -------------------------------------------------------------------------------- /src/common/ColorConsoleChannelCreator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_COMMON_COLORCONSOLECHANNELCREATOR_H_INCLUDED 6 | #define EASYHTTPCPP_COMMON_COLORCONSOLECHANNELCREATOR_H_INCLUDED 7 | 8 | #include "Poco/AutoPtr.h" 9 | #include "Poco/Channel.h" 10 | 11 | namespace easyhttpcpp { 12 | namespace common { 13 | 14 | class ColorConsoleChannelCreator { 15 | public: 16 | static Poco::AutoPtr create(); 17 | private: 18 | ColorConsoleChannelCreator(); 19 | }; 20 | 21 | } /* namespace common */ 22 | } /* namespace easyhttpcpp */ 23 | 24 | #endif /* EASYHTTPCPP_COMMON_COLORCONSOLECHANNELCREATOR_H_INCLUDED */ 25 | -------------------------------------------------------------------------------- /src/common/CommonException.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "easyhttpcpp/common/CommonException.h" 6 | #include "easyhttpcpp/common/ExceptionConstants.h" 7 | #include "easyhttpcpp/common/StringUtil.h" 8 | 9 | namespace easyhttpcpp { 10 | namespace common { 11 | 12 | EASYHTTPCPP_IMPLEMENT_EXCEPTION_SUB_GROUP(CommonException, CoreException, ExceptionConstants::SubGroupCode::Common) 13 | 14 | EASYHTTPCPP_IMPLEMENT_EXCEPTION(PocoException, CommonException, 0) 15 | EASYHTTPCPP_IMPLEMENT_EXCEPTION(StdException, CommonException, 1) 16 | EASYHTTPCPP_IMPLEMENT_EXCEPTION(FutureIllegalStateException, CommonException, 2) 17 | EASYHTTPCPP_IMPLEMENT_EXCEPTION(FutureCancellationException, CommonException, 3) 18 | EASYHTTPCPP_IMPLEMENT_EXCEPTION(FutureExecutionException, CommonException, 4) 19 | EASYHTTPCPP_IMPLEMENT_EXCEPTION(FutureTimeoutException, CommonException, 5) 20 | 21 | } /* namespace common */ 22 | } /* namespace easyhttpcpp */ 23 | -------------------------------------------------------------------------------- /src/common/CoreException.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "easyhttpcpp/common/CoreException.h" 6 | #include "easyhttpcpp/common/ExceptionConstants.h" 7 | 8 | namespace easyhttpcpp { 9 | namespace common { 10 | 11 | EASYHTTPCPP_IMPLEMENT_EXCEPTION_GROUP(CoreException, ExceptionConstants::GroupCode::Core) 12 | 13 | } /* namespace common */ 14 | } /* namespace easyhttpcpp */ 15 | -------------------------------------------------------------------------------- /src/common/CoreLogger.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "easyhttpcpp/common/CoreLogger.h" 6 | 7 | namespace easyhttpcpp { 8 | namespace common { 9 | 10 | bool CoreLogger::s_terminated = false; 11 | 12 | CoreLogger::CoreLogger() 13 | { 14 | } 15 | 16 | CoreLogger::~CoreLogger() 17 | { 18 | s_terminated = true; 19 | } 20 | 21 | CoreLogger* CoreLogger::getInstance() 22 | { 23 | static Poco::SingletonHolder s_singleton; 24 | 25 | if (s_terminated) { 26 | return NULL; 27 | } else { 28 | return s_singleton.get(); 29 | } 30 | } 31 | 32 | } /* namespace common */ 33 | } /* namespace easyhttpcpp */ 34 | -------------------------------------------------------------------------------- /src/common/ExceptionConstants.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "easyhttpcpp/common/ExceptionConstants.h" 6 | 7 | namespace easyhttpcpp { 8 | namespace common { 9 | 10 | const std::string ExceptionConstants::ErrorCodePrefix = "EASYHTTPCPP-ERR-"; 11 | 12 | /** 13 | * Exception group codes 14 | */ 15 | const unsigned int ExceptionConstants::GroupCode::Core = 10; 16 | 17 | /** 18 | * Exception subgroup codes 19 | */ 20 | const unsigned int ExceptionConstants::SubGroupCode::Common = 0; 21 | const unsigned int ExceptionConstants::SubGroupCode::Db = 2; 22 | const unsigned int ExceptionConstants::SubGroupCode::MessageDigest = 3; 23 | const unsigned int ExceptionConstants::SubGroupCode::ExecutorService = 6; 24 | const unsigned int ExceptionConstants::SubGroupCode::Http = 7; 25 | 26 | } /* namespace common */ 27 | } /* namespace easyhttpcpp */ 28 | -------------------------------------------------------------------------------- /src/common/ProjectVersion.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "easyhttpcpp/common/CommonMacros.h" 6 | #include "easyhttpcpp/common/ProjectVersion.h" 7 | #include "easyhttpcpp/common/StringUtil.h" 8 | 9 | namespace easyhttpcpp { 10 | namespace common { 11 | 12 | ProjectVersion::ProjectVersion() 13 | { 14 | } 15 | 16 | std::string ProjectVersion::getMajor() 17 | { 18 | return EASYHTTPCPP_STRINGIFY_MACRO(PACKAGE_VERSION_MAJOR); 19 | } 20 | 21 | std::string ProjectVersion::getMinor() 22 | { 23 | return EASYHTTPCPP_STRINGIFY_MACRO(PACKAGE_VERSION_MINOR); 24 | } 25 | 26 | std::string ProjectVersion::getPatch() 27 | { 28 | return EASYHTTPCPP_STRINGIFY_MACRO(PACKAGE_VERSION_PATCH); 29 | } 30 | 31 | std::string ProjectVersion::getExtension() 32 | { 33 | return EASYHTTPCPP_STRINGIFY_MACRO(PACKAGE_VERSION_EXT); 34 | } 35 | 36 | std::string ProjectVersion::asString() 37 | { 38 | return StringUtil::formatVersion(getMajor(), getMinor(), getPatch(), getExtension()); 39 | } 40 | 41 | } /* namespace common */ 42 | } /* namespace easyhttpcpp */ 43 | -------------------------------------------------------------------------------- /src/common/unix/ColorConsoleChannelCreatorImpl.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "Poco/ConsoleChannel.h" 6 | 7 | #include "ColorConsoleChannelCreatorImpl.h" 8 | 9 | namespace easyhttpcpp { 10 | namespace common { 11 | 12 | Poco::AutoPtr ColorConsoleChannelCreatorImpl::create() 13 | { 14 | return new Poco::ColorConsoleChannel(); 15 | } 16 | 17 | } /* namespace common */ 18 | } /* namespace easyhttpcpp */ 19 | -------------------------------------------------------------------------------- /src/common/unix/ColorConsoleChannelCreatorImpl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_COMMON_COLORCONSOLECHANNELCREATORIMPL_H_INCLUDED 6 | #define EASYHTTPCPP_COMMON_COLORCONSOLECHANNELCREATORIMPL_H_INCLUDED 7 | 8 | #include "Poco/AutoPtr.h" 9 | #include "Poco/Channel.h" 10 | 11 | namespace easyhttpcpp { 12 | namespace common { 13 | 14 | class ColorConsoleChannelCreatorImpl { 15 | public: 16 | static Poco::AutoPtr create(); 17 | private: 18 | ColorConsoleChannelCreatorImpl(); 19 | }; 20 | 21 | } /* namespace common */ 22 | } /* namespace easyhttpcpp */ 23 | 24 | #endif /* EASYHTTPCPP_COMMON_COLORCONSOLECHANNELCREATORIMPL_H_INCLUDED */ 25 | -------------------------------------------------------------------------------- /src/common/unix/FileUtilImpl.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Sony Corporation 3 | */ 4 | 5 | #include "Poco/Path.h" 6 | 7 | #include "FileUtilImpl.h" 8 | 9 | namespace easyhttpcpp { 10 | namespace common { 11 | 12 | std::string FileUtilImpl::convertToAbsolutePathString(const std::string& path, bool extendedPrefix) 13 | { 14 | // Linux returns absolute path. 15 | return Poco::Path(path).absolute().toString(); 16 | } 17 | 18 | } /* namespace common */ 19 | } /* namespace easyhttpcpp */ 20 | -------------------------------------------------------------------------------- /src/common/unix/FileUtilImpl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_COMMON_FILEUTILIMPL_H_INCLUDED 6 | #define EASYHTTPCPP_COMMON_FILEUTILIMPL_H_INCLUDED 7 | 8 | namespace easyhttpcpp { 9 | namespace common { 10 | 11 | class FileUtilImpl { 12 | public: 13 | static std::string convertToAbsolutePathString(const std::string& path, bool extendedPrefix); 14 | private: 15 | FileUtilImpl(); 16 | }; 17 | 18 | } /* namespace common */ 19 | } /* namespace easyhttpcpp */ 20 | 21 | #endif /* EASYHTTPCPP_COMMON_FILEUTILIMPL_H_INCLUDED */ 22 | 23 | -------------------------------------------------------------------------------- /src/common/windows/ColorConsoleChannelCreatorImpl.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "Poco/WindowsConsoleChannel.h" 6 | 7 | #include "ColorConsoleChannelCreatorImpl.h" 8 | 9 | namespace easyhttpcpp { 10 | namespace common { 11 | 12 | Poco::AutoPtr ColorConsoleChannelCreatorImpl::create() 13 | { 14 | return new Poco::WindowsColorConsoleChannel(); 15 | } 16 | 17 | } /* namespace common */ 18 | } /* namespace easyhttpcpp */ 19 | -------------------------------------------------------------------------------- /src/common/windows/ColorConsoleChannelCreatorImpl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_COMMON_COLORCONSOLECHANNELCREATORIMPL_H_INCLUDED 6 | #define EASYHTTPCPP_COMMON_COLORCONSOLECHANNELCREATORIMPL_H_INCLUDED 7 | 8 | #include "Poco/AutoPtr.h" 9 | #include "Poco/Channel.h" 10 | 11 | namespace easyhttpcpp { 12 | namespace common { 13 | 14 | class ColorConsoleChannelCreatorImpl { 15 | public: 16 | static Poco::AutoPtr create(); 17 | private: 18 | ColorConsoleChannelCreatorImpl(); 19 | }; 20 | 21 | } /* namespace common */ 22 | } /* namespace easyhttpcpp */ 23 | 24 | #endif /* EASYHTTPCPP_COMMON_COLORCONSOLECHANNELCREATORIMPL_H_INCLUDED */ 25 | -------------------------------------------------------------------------------- /src/common/windows/FileUtilImpl.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Sony Corporation 3 | */ 4 | 5 | #include "Poco/Path.h" 6 | 7 | #include "FileUtilImpl.h" 8 | 9 | namespace easyhttpcpp { 10 | namespace common { 11 | 12 | namespace { 13 | 14 | const std::string ExtendedPathPrefix = "\\\\?\\"; 15 | 16 | } /* namespace */ 17 | 18 | std::string FileUtilImpl::convertToAbsolutePathString(const std::string& path, bool extendedPrefix) 19 | { 20 | // Windows returns absolute path with extended prefix. See Windows long path info: 21 | // https://docs.microsoft.com/ja-jp/windows/win32/fileio/naming-a-file#maximum-path-length-limitation 22 | if (extendedPrefix) { 23 | return ExtendedPathPrefix + Poco::Path(path).absolute().toString(); 24 | } else { 25 | return Poco::Path(path).absolute().toString(); 26 | } 27 | } 28 | 29 | } /* namespace common */ 30 | } /* namespace easyhttpcpp */ 31 | -------------------------------------------------------------------------------- /src/common/windows/FileUtilImpl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_COMMON_FILEUTILIMPL_H_INCLUDED 6 | #define EASYHTTPCPP_COMMON_FILEUTILIMPL_H_INCLUDED 7 | 8 | namespace easyhttpcpp { 9 | namespace common { 10 | 11 | class FileUtilImpl { 12 | public: 13 | static std::string convertToAbsolutePathString(const std::string& path, bool extendedPrefix); 14 | private: 15 | FileUtilImpl(); 16 | }; 17 | 18 | } /* namespace common */ 19 | } /* namespace easyhttpcpp */ 20 | 21 | #endif /* EASYHTTPCPP_COMMON_FILEUTILIMPL_H_INCLUDED */ 22 | 23 | -------------------------------------------------------------------------------- /src/db/SqlException.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "easyhttpcpp/common/ExceptionConstants.h" 6 | #include "easyhttpcpp/common/StringUtil.h" 7 | #include "easyhttpcpp/db/SqlException.h" 8 | 9 | namespace easyhttpcpp { 10 | namespace db { 11 | 12 | using easyhttpcpp::common::ExceptionConstants; 13 | 14 | EASYHTTPCPP_IMPLEMENT_EXCEPTION_SUB_GROUP(SqlException, CoreException, ExceptionConstants::SubGroupCode::Db) 15 | 16 | EASYHTTPCPP_IMPLEMENT_EXCEPTION(SqlIllegalArgumentException, SqlException, 0) 17 | EASYHTTPCPP_IMPLEMENT_EXCEPTION(SqlIllegalStateException, SqlException, 1) 18 | EASYHTTPCPP_IMPLEMENT_EXCEPTION(SqlExecutionException, SqlException, 2) 19 | EASYHTTPCPP_IMPLEMENT_EXCEPTION(SqlDatabaseCorruptException, SqlException, 3) 20 | 21 | } /* namespace db */ 22 | } /* namespace easyhttpcpp */ 23 | -------------------------------------------------------------------------------- /src/executorservice/ExecutorServiceException.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "easyhttpcpp/common/ExceptionConstants.h" 6 | #include "easyhttpcpp/common/StringUtil.h" 7 | #include "easyhttpcpp/executorservice/ExecutorServiceException.h" 8 | 9 | namespace easyhttpcpp { 10 | namespace executorservice { 11 | 12 | using easyhttpcpp::common::ExceptionConstants; 13 | 14 | EASYHTTPCPP_IMPLEMENT_EXCEPTION_SUB_GROUP(ExecutorServiceException, CoreException, 15 | ExceptionConstants::SubGroupCode::ExecutorService) 16 | 17 | EASYHTTPCPP_IMPLEMENT_EXCEPTION(ExecutorServiceIllegalArgumentException, ExecutorServiceException, 0) 18 | EASYHTTPCPP_IMPLEMENT_EXCEPTION(ExecutorServiceIllegalStateException, ExecutorServiceException, 1) 19 | EASYHTTPCPP_IMPLEMENT_EXCEPTION(ExecutorServiceExecutionException, ExecutorServiceException, 2) 20 | EASYHTTPCPP_IMPLEMENT_EXCEPTION(ExecutorServiceTooManyRequestsException, ExecutorServiceException, 3) 21 | 22 | } /* namespace executorservice */ 23 | } /* namespace easyhttpcpp */ 24 | 25 | -------------------------------------------------------------------------------- /src/executorservice/RunnableWorker.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "easyhttpcpp/common/CoreLogger.h" 6 | #include "easyhttpcpp/executorservice/BlockingQueue.h" 7 | #include "easyhttpcpp/executorservice/QueuedThreadPool.h" 8 | 9 | #include "RunnableWorker.h" 10 | 11 | namespace easyhttpcpp { 12 | namespace executorservice { 13 | 14 | using easyhttpcpp::common::RefCountedRunnable; 15 | 16 | static const std::string Tag = "RunnableWorker"; 17 | 18 | RunnableWorker::RunnableWorker(RefCountedRunnable::Ptr pTask, QueuedThreadPool* pQueuedThreadPool) 19 | { 20 | m_pTask = pTask; 21 | m_pQueuedThreadPool = pQueuedThreadPool; 22 | } 23 | 24 | RunnableWorker::~RunnableWorker() 25 | { 26 | } 27 | 28 | void RunnableWorker::run() 29 | { 30 | EASYHTTPCPP_LOG_D(Tag, "run start"); 31 | // run Runnable of this RunnableWorker 32 | m_pTask->run(); 33 | 34 | // run Runnable of BlockingQueue 35 | while (true) { 36 | RefCountedRunnable::Ptr pTask = m_pQueuedThreadPool->getNextTask(); 37 | if (!pTask) { 38 | break; 39 | } 40 | pTask->run(); 41 | } 42 | delete this; 43 | EASYHTTPCPP_LOG_D(Tag, "run end"); 44 | } 45 | 46 | } /* namespace executorservice */ 47 | } /* namespace easyhttpcpp */ 48 | -------------------------------------------------------------------------------- /src/executorservice/RunnableWorker.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_EXECUTORSERVICE_RUNNABLEWORKER_H_INCLUDED 6 | #define EASYHTTPCPP_EXECUTORSERVICE_RUNNABLEWORKER_H_INCLUDED 7 | 8 | #include "Poco/AutoPtr.h" 9 | #include "Poco/RefCountedObject.h" 10 | #include "Poco/Runnable.h" 11 | 12 | namespace easyhttpcpp { 13 | namespace executorservice { 14 | 15 | class QueuedThreadPool; 16 | 17 | class RunnableWorker : public Poco::Runnable { 18 | public: 19 | 20 | RunnableWorker(easyhttpcpp::common::RefCountedRunnable::Ptr pTask, QueuedThreadPool* pQueuedThreadPool); 21 | virtual ~RunnableWorker(); 22 | 23 | virtual void run(); 24 | private: 25 | easyhttpcpp::common::RefCountedRunnable::Ptr m_pTask; 26 | QueuedThreadPool* m_pQueuedThreadPool; 27 | }; 28 | 29 | } /* namespace executorservice */ 30 | } /* namespace easyhttpcpp */ 31 | 32 | #endif /* EASYHTTPCPP_EXECUTORSERVICE_RUNNABLEWORKER_H_INCLUDED */ 33 | -------------------------------------------------------------------------------- /src/executorservice/UnboundBlockingQueue.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include 6 | 7 | #include "Poco/Mutex.h" 8 | #include "Poco/ScopedLock.h" 9 | 10 | #include "easyhttpcpp/executorservice/UnboundBlockingQueue.h" 11 | 12 | namespace easyhttpcpp { 13 | namespace executorservice { 14 | 15 | using easyhttpcpp::common::RefCountedRunnable; 16 | 17 | static const std::string Tag = "UnboundBlockingQueue"; 18 | 19 | UnboundBlockingQueue::UnboundBlockingQueue() 20 | { 21 | } 22 | 23 | UnboundBlockingQueue::~UnboundBlockingQueue() 24 | { 25 | clear(); 26 | } 27 | 28 | bool UnboundBlockingQueue::push(RefCountedRunnable::Ptr pTask) 29 | { 30 | Poco::FastMutex::ScopedLock lock(m_mutex); 31 | m_workerQueue.push(pTask); 32 | return true; 33 | } 34 | 35 | RefCountedRunnable::Ptr UnboundBlockingQueue::pop() 36 | { 37 | Poco::FastMutex::ScopedLock lock(m_mutex); 38 | if (m_workerQueue.empty()) { 39 | return NULL; 40 | } 41 | RefCountedRunnable::Ptr pTask = m_workerQueue.front(); 42 | m_workerQueue.pop(); 43 | return pTask; 44 | } 45 | 46 | bool UnboundBlockingQueue::isEmpty() 47 | { 48 | Poco::FastMutex::ScopedLock lock(m_mutex); 49 | return m_workerQueue.empty(); 50 | } 51 | 52 | void UnboundBlockingQueue::clear() 53 | { 54 | Poco::FastMutex::ScopedLock lock(m_mutex); 55 | while (!m_workerQueue.empty()) { 56 | m_workerQueue.pop(); 57 | } 58 | } 59 | 60 | } /* namespace executorservice */ 61 | } /* namespace easyhttpcpp */ 62 | -------------------------------------------------------------------------------- /src/messagedigest/DigestConstants.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "easyhttpcpp/messagedigest/DigestConstants.h" 6 | 7 | namespace easyhttpcpp { 8 | namespace messagedigest { 9 | 10 | const std::string DigestConstants::MessageDigestAlgorithmSha256 = "SHA256"; 11 | const std::string DigestConstants::MessageDigestAlgorithmSha1 = "SHA1"; 12 | const std::string DigestConstants::MessageDigestAlgorithmMd5 = "MD5"; 13 | 14 | } /* namespace messagedigest */ 15 | } /* namespace easyhttpcpp */ 16 | -------------------------------------------------------------------------------- /src/messagedigest/MessageDigestException.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "easyhttpcpp/common/ExceptionConstants.h" 6 | #include "easyhttpcpp/common/StringUtil.h" 7 | #include "easyhttpcpp/messagedigest/MessageDigestException.h" 8 | 9 | using easyhttpcpp::common::CoreException; 10 | using easyhttpcpp::common::ExceptionConstants; 11 | 12 | namespace easyhttpcpp { 13 | namespace messagedigest { 14 | 15 | EASYHTTPCPP_IMPLEMENT_EXCEPTION_SUB_GROUP(MessageDigestException, CoreException, ExceptionConstants::SubGroupCode::MessageDigest) 16 | 17 | EASYHTTPCPP_IMPLEMENT_EXCEPTION(MessageDigestIllegalArgumentException, MessageDigestException, 0) 18 | EASYHTTPCPP_IMPLEMENT_EXCEPTION(MessageDigestIllegalStateException, MessageDigestException, 1) 19 | EASYHTTPCPP_IMPLEMENT_EXCEPTION(MessageDigestExecutionException, MessageDigestException, 2) 20 | 21 | } /* namespace messagedigest */ 22 | } /* namespace easyhttpcpp */ 23 | -------------------------------------------------------------------------------- /src/messagedigest/unix/DigestEngineImpl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_MESSAGEDIGEST_DIGESTENGINEIMPL_H_INCLUDED 6 | #define EASYHTTPCPP_MESSAGEDIGEST_DIGESTENGINEIMPL_H_INCLUDED 7 | 8 | #include 9 | #include 10 | 11 | #include "Poco/Crypto/DigestEngine.h" 12 | #include "Poco/SharedPtr.h" 13 | 14 | #include "easyhttpcpp/common/Typedef.h" 15 | 16 | namespace easyhttpcpp { 17 | namespace messagedigest { 18 | 19 | class DigestEngineImpl { 20 | public: 21 | DigestEngineImpl(const std::string& algorithm); 22 | virtual ~DigestEngineImpl(); 23 | 24 | static std::string digestToHex(const std::vector& digest); 25 | virtual void update(const easyhttpcpp::common::Byte* data, size_t length); 26 | std::vector digest(); 27 | virtual void reset(); 28 | private: 29 | 30 | Poco::SharedPtr m_pDigestEngine; 31 | 32 | }; 33 | 34 | } /* namespace messagedigest */ 35 | } /* namespace easyhttpcpp */ 36 | 37 | #endif /* EASYHTTPCPP_MESSAGEDIGEST_DIGESTENGINEIMPL_H_INCLUDED */ 38 | -------------------------------------------------------------------------------- /src/messagedigest/unix/DigestUtilImpl.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "easyhttpcpp/messagedigest/DigestUtil.h" 6 | 7 | #include "DigestUtilImpl.h" 8 | 9 | namespace easyhttpcpp { 10 | namespace messagedigest { 11 | 12 | std::string DigestUtilImpl::createHashedFileName(const std::string& key) 13 | { 14 | return DigestUtil::sha256Hex(key); 15 | } 16 | 17 | } /* namespace messagedigest */ 18 | } /* namespace easyhttpcpp */ 19 | -------------------------------------------------------------------------------- /src/messagedigest/unix/DigestUtilImpl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_MESSAGEDIGEST_DIGESTUTILIMPL_H_INCLUDED 6 | #define EASYHTTPCPP_MESSAGEDIGEST_DIGESTUTILIMPL_H_INCLUDED 7 | 8 | #include 9 | 10 | namespace easyhttpcpp { 11 | namespace messagedigest { 12 | 13 | class DigestUtilImpl { 14 | public: 15 | static std::string createHashedFileName(const std::string& key); 16 | private: 17 | DigestUtilImpl(); 18 | }; 19 | 20 | } /* namespace messagedigest */ 21 | } /* namespace easyhttpcpp */ 22 | 23 | #endif /* EASYHTTPCPP_MESSAGEDIGEST_DIGESTUTILIMPL_H_INCLUDED */ 24 | -------------------------------------------------------------------------------- /src/messagedigest/windows/DigestEngineImpl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_MESSAGEDIGEST_DIGESTENGINEIMPL_H_INCLUDED 6 | #define EASYHTTPCPP_MESSAGEDIGEST_DIGESTENGINEIMPL_H_INCLUDED 7 | 8 | #include 9 | #include 10 | 11 | #include "Windows.h" 12 | #include "wincrypt.h" 13 | 14 | namespace easyhttpcpp { 15 | namespace messagedigest { 16 | 17 | class DigestEngineImpl{ 18 | public: 19 | DigestEngineImpl(const std::string& algorithm); 20 | virtual ~DigestEngineImpl(); 21 | 22 | virtual void update(const easyhttpcpp::common::Byte* data, size_t length); 23 | virtual void reset(); 24 | virtual std::vector digest(); 25 | static std::string digestToHex(const std::vector& digest); 26 | private: 27 | unsigned int getAlgorithmIdFromString(const std::string algorithm); 28 | 29 | unsigned int m_algorithmId; 30 | 31 | // handle to a CSP 32 | HCRYPTPROV m_cspHandle; 33 | // handle to the new hash object 34 | HCRYPTHASH m_hashHandle; 35 | }; 36 | 37 | } /* namespace messagedigest */ 38 | } /* namespace easyhttpcpp */ 39 | 40 | #endif /* EASYHTTPCPP_MESSAGEDIGEST_DIGESTENGINEIMPL_H_INCLUDED */ 41 | -------------------------------------------------------------------------------- /src/messagedigest/windows/DigestUtilImpl.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "easyhttpcpp/messagedigest/DigestUtil.h" 6 | 7 | #include "DigestUtilImpl.h" 8 | 9 | namespace easyhttpcpp { 10 | namespace messagedigest { 11 | 12 | std::string DigestUtilImpl::createHashedFileName(const std::string& key) 13 | { 14 | return DigestUtil::sha1Hex(key); 15 | } 16 | 17 | } /* namespace messagedigest */ 18 | } /* namespace easyhttpcpp */ 19 | -------------------------------------------------------------------------------- /src/messagedigest/windows/DigestUtilImpl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_MESSAGEDIGEST_DIGESTUTILIMPL_H_INCLUDED 6 | #define EASYHTTPCPP_MESSAGEDIGEST_DIGESTUTILIMPL_H_INCLUDED 7 | 8 | #include 9 | 10 | namespace easyhttpcpp { 11 | namespace messagedigest { 12 | 13 | class DigestUtilImpl { 14 | public: 15 | static std::string createHashedFileName(const std::string& key); 16 | private: 17 | DigestUtilImpl(); 18 | }; 19 | 20 | } /* namespace messagedigest */ 21 | } /* namespace easyhttpcpp */ 22 | 23 | #endif /* EASYHTTPCPP_MESSAGEDIGEST_DIGESTUTILIMPL_H_INCLUDED */ 24 | -------------------------------------------------------------------------------- /src/unix/SslContextCreatorImpl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_SSLCONTEXTCREATORIMPL_H_INCLUDED 6 | #define EASYHTTPCPP_SSLCONTEXTCREATORIMPL_H_INCLUDED 7 | 8 | #include "Poco/Net/Context.h" 9 | 10 | #include "EasyHttpContext.h" 11 | 12 | namespace easyhttpcpp { 13 | 14 | class SslContextCreatorImpl { 15 | public: 16 | static Poco::Net::Context::Ptr createContext(EasyHttpContext::Ptr pContext); 17 | private: 18 | SslContextCreatorImpl(); 19 | }; 20 | 21 | } /* namespace easyhttpcpp */ 22 | 23 | #endif /* EASYHTTPCPP_SSLCONTEXTCREATORIMPL_H_INCLUDED */ 24 | -------------------------------------------------------------------------------- /src/windows/SslContextCreatorImpl.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "Poco/Net/SSLException.h" 6 | 7 | #include "easyhttpcpp/common/CoreLogger.h" 8 | #include "easyhttpcpp/common/StringUtil.h" 9 | #include "easyhttpcpp/HttpException.h" 10 | 11 | #include "SslContextCreatorImpl.h" 12 | 13 | using easyhttpcpp::common::StringUtil; 14 | 15 | namespace easyhttpcpp { 16 | 17 | static const std::string Tag = "SslContextCreatorImpl"; 18 | 19 | Poco::Net::Context::Ptr SslContextCreatorImpl::createContext(EasyHttpContext::Ptr pContext) 20 | { 21 | try { 22 | // Always use Windows default Certificate Store 23 | Poco::Net::Context::Ptr pPocoContext = new Poco::Net::Context(Poco::Net::Context::CLIENT_USE, "", 24 | Poco::Net::Context::VERIFY_RELAXED, Poco::Net::Context::OPT_TRUST_ROOTS_WIN_CERT_STORE); 25 | return pPocoContext; 26 | } catch (const Poco::Exception& e) { 27 | EASYHTTPCPP_LOG_D(Tag, "createPocoContext: Poco::Exception occurred. message=[%s]", e.message().c_str()); 28 | throw HttpExecutionException(StringUtil::format("Poco context initialization error occurred. message=[%s]", 29 | e.message().c_str()), e); 30 | } 31 | } 32 | 33 | } /* namespace easyhttpcpp */ 34 | -------------------------------------------------------------------------------- /src/windows/SslContextCreatorImpl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_SSLCONTEXTCREATORIMPL_H_INCLUDED 6 | #define EASYHTTPCPP_SSLCONTEXTCREATORIMPL_H_INCLUDED 7 | 8 | #include "Poco/Net/Context.h" 9 | 10 | #include "EasyHttpContext.h" 11 | 12 | namespace easyhttpcpp { 13 | 14 | class SslContextCreatorImpl { 15 | public: 16 | static Poco::Net::Context::Ptr createContext(EasyHttpContext::Ptr pContext); 17 | private: 18 | SslContextCreatorImpl(); 19 | }; 20 | 21 | } /* namespace easyhttpcpp */ 22 | 23 | #endif /* EASYHTTPCPP_SSLCONTEXTCREATORIMPL_H_INCLUDED */ 24 | -------------------------------------------------------------------------------- /tests/CMakeLists-integrationtests.txt: -------------------------------------------------------------------------------- 1 | set(TESTTYPE "Integration") 2 | 3 | set(TESTRUNNER "${LIBRARY_TARGET_NAME}-${TESTTYPE}TestRunner") 4 | 5 | set(TESTDATA_ROOTDIR "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Data/Test/${LIBRARY_TARGET_NAME}/${TESTTYPE}") 6 | 7 | # sources 8 | file(GLOB_RECURSE TEST_SRCS "integrationtests/*.cpp") 9 | 10 | add_executable(${TESTRUNNER} ${TEST_SRCS}) 11 | 12 | # allow tests to know their runtime data root location 13 | target_compile_definitions(${TESTRUNNER} PRIVATE 14 | RUNTIME_DATA_ROOT=${TESTDATA_ROOTDIR} 15 | ) 16 | 17 | target_link_libraries(${TESTRUNNER} 18 | easyhttp-testutil 19 | easyhttp 20 | GMock::main 21 | ${Poco_LIBRARIES} 22 | ${OPENSSL_SSL_LIBRARY} 23 | ${OPENSSL_CRYPTO_LIBRARY}) 24 | 25 | # add private headers to include search path as well 26 | target_include_directories(${TESTRUNNER} 27 | PRIVATE 28 | ${PROJECT_SOURCE_DIR}/src 29 | ${CMAKE_CURRENT_SOURCE_DIR}/integrationtests 30 | ) 31 | 32 | # test is run in the runtime directory. So the test data is copied there too 33 | add_custom_command(TARGET ${TESTRUNNER} POST_BUILD 34 | COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/Data ${TESTDATA_ROOTDIR}) 35 | -------------------------------------------------------------------------------- /tests/CMakeLists-unittests.txt: -------------------------------------------------------------------------------- 1 | set(TESTTYPE "Unit") 2 | 3 | set(TESTRUNNER "${LIBRARY_TARGET_NAME}-${TESTTYPE}TestRunner") 4 | 5 | set(TESTDATA_ROOTDIR "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Data/Test/${LIBRARY_TARGET_NAME}/${TESTTYPE}") 6 | 7 | # sources 8 | file(GLOB_RECURSE TEST_SRCS "unittests/*.cpp") 9 | 10 | add_executable(${TESTRUNNER} ${TEST_SRCS}) 11 | 12 | # allow tests to know their runtime data root location 13 | target_compile_definitions(${TESTRUNNER} PRIVATE 14 | RUNTIME_DATA_ROOT=${TESTDATA_ROOTDIR} 15 | ) 16 | 17 | target_link_libraries(${TESTRUNNER} 18 | easyhttp-testutil 19 | easyhttp 20 | GMock::main 21 | ${Poco_LIBRARIES} 22 | ${OPENSSL_SSL_LIBRARY} 23 | ${OPENSSL_CRYPTO_LIBRARY}) 24 | 25 | # add private headers to include search path as well 26 | target_include_directories(${TESTRUNNER} 27 | PRIVATE 28 | ${PROJECT_SOURCE_DIR}/src 29 | ${CMAKE_CURRENT_SOURCE_DIR}/unittests 30 | ) 31 | 32 | # test is run in the runtime directory. So the test data is copied there too 33 | add_custom_command(TARGET ${TESTRUNNER} POST_BUILD 34 | COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/Data ${TESTDATA_ROOTDIR}) 35 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ############################################################# 2 | # build & install testutil utility library 3 | 4 | set(TESTUTIL_TARGET_NAME ${LIBRARY_TARGET_NAME}-testutil) 5 | 6 | # dependent libraries 7 | find_package(GMock CONFIG REQUIRED) 8 | 9 | # sources 10 | file(GLOB SRCS_G "testutil/*.cpp") 11 | file(GLOB SRCS_PLAT_G "testutil/${PLATFORM_SPECIFIC_SRC_DIR_NAME}/*.cpp") 12 | list(APPEND TESTUTIL_SRCS ${SRCS_G} ${SRCS_PLAT_G}) 13 | 14 | add_library(${TESTUTIL_TARGET_NAME} ${LIB_MODE} ${TESTUTIL_SRCS}) 15 | set_target_properties("${TESTUTIL_TARGET_NAME}" 16 | PROPERTIES 17 | VERSION ${PROJECT_VERSION} SOVERSION ${SHARED_LIBRARY_VERSION} 18 | OUTPUT_NAME ${TESTUTIL_TARGET_NAME} 19 | DEFINE_SYMBOL EASYHTTPCPP_TESTUTIL_API_EXPORTS 20 | ) 21 | 22 | target_link_libraries(${TESTUTIL_TARGET_NAME} 23 | easyhttp 24 | GMock::main 25 | ${Poco_LIBRARIES} 26 | ${OPENSSL_SSL_LIBRARY} 27 | ${OPENSSL_CRYPTO_LIBRARY}) 28 | 29 | target_include_directories(${TESTUTIL_TARGET_NAME} 30 | PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/testutil 31 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/testutil/${PLATFORM_SPECIFIC_SRC_DIR_NAME} 32 | ) 33 | 34 | ############################################################# 35 | # build & install test targets 36 | 37 | include(CMakeLists-unittests.txt) 38 | include(CMakeLists-integrationtests.txt) 39 | -------------------------------------------------------------------------------- /tests/Data/HttpIntegrationTest/01_cache_from_db/HttpCache/unix/cache/9548bfe183836899d66681fe4e6b0f7896aef2d0260ddcdf7e8b0697e8bd8977.data: -------------------------------------------------------------------------------- 1 | test=46789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 -------------------------------------------------------------------------------- /tests/Data/HttpIntegrationTest/01_cache_from_db/HttpCache/unix/cache/9f69b9b8c5cc8bec1aac9a61f850c6ce9c98eb135fcf3cedb70b27459f2a641e.data: -------------------------------------------------------------------------------- 1 | test=16789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 -------------------------------------------------------------------------------- /tests/Data/HttpIntegrationTest/01_cache_from_db/HttpCache/unix/cache/cache_metadata.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sony/easyhttpcpp/ef7dca78f76877d51b329464c322e87eef54195f/tests/Data/HttpIntegrationTest/01_cache_from_db/HttpCache/unix/cache/cache_metadata.db -------------------------------------------------------------------------------- /tests/Data/HttpIntegrationTest/01_cache_from_db/HttpCache/unix/cache/d45fcd30cc134d7613dba07456a2ea845d2e0ff145466acace03b0ed5abafef6.data: -------------------------------------------------------------------------------- 1 | test=36789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 -------------------------------------------------------------------------------- /tests/Data/HttpIntegrationTest/01_cache_from_db/HttpCache/windows/cache/0c898621f37be5bb75f090362d28769dd8f5c020.data: -------------------------------------------------------------------------------- 1 | test=36789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 -------------------------------------------------------------------------------- /tests/Data/HttpIntegrationTest/01_cache_from_db/HttpCache/windows/cache/32e5eea70b79d340a52212871a1bdea48ca09a57.data: -------------------------------------------------------------------------------- 1 | test=16789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 -------------------------------------------------------------------------------- /tests/Data/HttpIntegrationTest/01_cache_from_db/HttpCache/windows/cache/86451cfc298fc6a03ea8067a483fc020fc9501cd.data: -------------------------------------------------------------------------------- 1 | test=46789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 -------------------------------------------------------------------------------- /tests/Data/HttpIntegrationTest/01_cache_from_db/HttpCache/windows/cache/cache_metadata.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sony/easyhttpcpp/ef7dca78f76877d51b329464c322e87eef54195f/tests/Data/HttpIntegrationTest/01_cache_from_db/HttpCache/windows/cache/cache_metadata.db -------------------------------------------------------------------------------- /tests/Data/HttpIntegrationTest/02_https_localhost_cert/cert/client/invalid_rootCa.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sony/easyhttpcpp/ef7dca78f76877d51b329464c322e87eef54195f/tests/Data/HttpIntegrationTest/02_https_localhost_cert/cert/client/invalid_rootCa.txt -------------------------------------------------------------------------------- /tests/Data/HttpIntegrationTest/02_https_localhost_cert/cert/client/rootCa-invalid-common/64b0d652.0: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIICpTCCAg6gAwIBAgIJAKTjGMGDAeeiMA0GCSqGSIb3DQEBCwUAMGIxCzAJBgNV 3 | BAYTAkpQMQ4wDAYDVQQIDAVUb2t5bzESMBAGA1UEBwwJU2hpbmFnYXdhMQ0wCwYD 4 | VQQKDARTb255MQ8wDQYDVQQLDAZHcm91cDExDzANBgNVBAMMBnRlc3QwMTAeFw0x 5 | NjA5MjMwODQwMjFaFw0xNjA5MjQwODQwMjFaMGIxCzAJBgNVBAYTAkpQMQ4wDAYD 6 | VQQIDAVUb2t5bzESMBAGA1UEBwwJU2hpbmFnYXdhMQ0wCwYDVQQKDARTb255MQ8w 7 | DQYDVQQLDAZHcm91cDExDzANBgNVBAMMBnRlc3QwMTCBnzANBgkqhkiG9w0BAQEF 8 | AAOBjQAwgYkCgYEA3o3lkItWopfJgVKFfvj0R7u5SwitgdxSCrs+YKxqWQ/+W4NG 9 | o3zBLYNIfTTX2lTaG6KwieR3XQMrKLyIOVUvWSoSFF3C4t7wZ3uGmYc8Usg8QUe/ 10 | DPmZu7cNS0Kl7gxMCZ7L1ywDxdtAS/StoaYDWN58ESwG/6HTsc0gmGjSHlkCAwEA 11 | AaNjMGEwHQYDVR0OBBYEFKVslcpYz3OlDzeF1NHF2Xe9USUbMB8GA1UdIwQYMBaA 12 | FKVslcpYz3OlDzeF1NHF2Xe9USUbMA8GA1UdEwEB/wQFMAMBAf8wDgYDVR0PAQH/ 13 | BAQDAgEGMA0GCSqGSIb3DQEBCwUAA4GBAFAsy2ucbkYyMNa74FZZMA0t+oeq0U2L 14 | dNcbh/X+LfQmQ0NReJ/STIP4tb8iSCMOkevRevPIHtpTvyO+1LpYYdDQWcGQ7ZnR 15 | 3gvAcKl/uetaKHtqDcbpwdgv4WA1MGrr/TtL/mk77j38HoVE9+EMnSxQVWM4SL3t 16 | iBxiC25VhyL+ 17 | -----END CERTIFICATE----- 18 | -------------------------------------------------------------------------------- /tests/Data/HttpIntegrationTest/02_https_localhost_cert/cert/client/rootCa-invalid-common/c37db6da.0: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIC7TCCAlagAwIBAgIBADANBgkqhkiG9w0BAQsFADBrMQswCQYDVQQGEwJKUDEO 3 | MAwGA1UECAwFVG9reW8xEjAQBgNVBAcMCVNoaW5hZ2F3YTENMAsGA1UECgwEU29u 4 | eTEPMA0GA1UECwwGR3JvdXAxMRgwFgYDVQQDDA9Mb2NhbGhvc3RSb290Q0EwHhcN 5 | MTYwODI1MDk0OTIxWhcNMjYwNzA0MDk0OTIxWjBrMQswCQYDVQQGEwJKUDEOMAwG 6 | A1UECAwFVG9reW8xEjAQBgNVBAcMCVNoaW5hZ2F3YTENMAsGA1UECgwEU29ueTEO 7 | MAwGA1UECwwFVGVhbTExGTAXBgNVBAMMEExvY2FsaG9zdEludGVyQ0EwgZ8wDQYJ 8 | KoZIhvcNAQEBBQADgY0AMIGJAoGBANXKboSURVfr7+vpiCdFWRWImUK/eClwMdbu 9 | ANDFpGK+NShcAycFuh/07qaZc1GwfkQl879W4xxeLVHG98xPFazixenWUj2NEeOM 10 | LeAYFPeYeCNxTYO1Le2L1dsO9SUDFIcsPkrsF8R3YaBYgz+881yyJMpmTfK7hlMj 11 | +wihm3cNAgMBAAGjgaAwgZ0wHQYDVR0OBBYEFDEUSstAp4l3ZDKenwSgpL+sM8ME 12 | MB8GA1UdIwQYMBaAFOUENZvcwmfXlJOSi1CGjzIb/Ul5MA8GA1UdEwEB/wQFMAMB 13 | Af8wDgYDVR0PAQH/BAQDAgEGMDoGA1UdHwQzMDEwL6AtoCuGKWh0dHA6Ly80My44 14 | LjIxOS4zMTo0OTU4MC90ZXN0X2NhL3Jvb3QuY3JsMA0GCSqGSIb3DQEBCwUAA4GB 15 | AGH8xzOTTovvVkGMOD6dVD9mf75Dd7KqhnOi4txpETEAtBXDBmrYARJTWTDNdB35 16 | bjcNvcL2HEXl1rZlgcR2yklx7ZU8KZVcvcq8wn5oQ/IOvgSfrHfVejuEyPRAOR/W 17 | Ek18M4xKyJ++DfPk0dqCQNXkd/hiHdmb1rCpa1te9Mb/ 18 | -----END CERTIFICATE----- 19 | -------------------------------------------------------------------------------- /tests/Data/HttpIntegrationTest/02_https_localhost_cert/cert/client/rootCa-invalid-common/localhost_demoCA.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIICpTCCAg6gAwIBAgIJAKTjGMGDAeeiMA0GCSqGSIb3DQEBCwUAMGIxCzAJBgNV 3 | BAYTAkpQMQ4wDAYDVQQIDAVUb2t5bzESMBAGA1UEBwwJU2hpbmFnYXdhMQ0wCwYD 4 | VQQKDARTb255MQ8wDQYDVQQLDAZHcm91cDExDzANBgNVBAMMBnRlc3QwMTAeFw0x 5 | NjA5MjMwODQwMjFaFw0xNjA5MjQwODQwMjFaMGIxCzAJBgNVBAYTAkpQMQ4wDAYD 6 | VQQIDAVUb2t5bzESMBAGA1UEBwwJU2hpbmFnYXdhMQ0wCwYDVQQKDARTb255MQ8w 7 | DQYDVQQLDAZHcm91cDExDzANBgNVBAMMBnRlc3QwMTCBnzANBgkqhkiG9w0BAQEF 8 | AAOBjQAwgYkCgYEA3o3lkItWopfJgVKFfvj0R7u5SwitgdxSCrs+YKxqWQ/+W4NG 9 | o3zBLYNIfTTX2lTaG6KwieR3XQMrKLyIOVUvWSoSFF3C4t7wZ3uGmYc8Usg8QUe/ 10 | DPmZu7cNS0Kl7gxMCZ7L1ywDxdtAS/StoaYDWN58ESwG/6HTsc0gmGjSHlkCAwEA 11 | AaNjMGEwHQYDVR0OBBYEFKVslcpYz3OlDzeF1NHF2Xe9USUbMB8GA1UdIwQYMBaA 12 | FKVslcpYz3OlDzeF1NHF2Xe9USUbMA8GA1UdEwEB/wQFMAMBAf8wDgYDVR0PAQH/ 13 | BAQDAgEGMA0GCSqGSIb3DQEBCwUAA4GBAFAsy2ucbkYyMNa74FZZMA0t+oeq0U2L 14 | dNcbh/X+LfQmQ0NReJ/STIP4tb8iSCMOkevRevPIHtpTvyO+1LpYYdDQWcGQ7ZnR 15 | 3gvAcKl/uetaKHtqDcbpwdgv4WA1MGrr/TtL/mk77j38HoVE9+EMnSxQVWM4SL3t 16 | iBxiC25VhyL+ 17 | -----END CERTIFICATE----- 18 | -------------------------------------------------------------------------------- /tests/Data/HttpIntegrationTest/02_https_localhost_cert/cert/client/rootCa-invalid-common/localhost_interCA.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIC7TCCAlagAwIBAgIBADANBgkqhkiG9w0BAQsFADBrMQswCQYDVQQGEwJKUDEO 3 | MAwGA1UECAwFVG9reW8xEjAQBgNVBAcMCVNoaW5hZ2F3YTENMAsGA1UECgwEU29u 4 | eTEPMA0GA1UECwwGR3JvdXAxMRgwFgYDVQQDDA9Mb2NhbGhvc3RSb290Q0EwHhcN 5 | MTYwODI1MDk0OTIxWhcNMjYwNzA0MDk0OTIxWjBrMQswCQYDVQQGEwJKUDEOMAwG 6 | A1UECAwFVG9reW8xEjAQBgNVBAcMCVNoaW5hZ2F3YTENMAsGA1UECgwEU29ueTEO 7 | MAwGA1UECwwFVGVhbTExGTAXBgNVBAMMEExvY2FsaG9zdEludGVyQ0EwgZ8wDQYJ 8 | KoZIhvcNAQEBBQADgY0AMIGJAoGBANXKboSURVfr7+vpiCdFWRWImUK/eClwMdbu 9 | ANDFpGK+NShcAycFuh/07qaZc1GwfkQl879W4xxeLVHG98xPFazixenWUj2NEeOM 10 | LeAYFPeYeCNxTYO1Le2L1dsO9SUDFIcsPkrsF8R3YaBYgz+881yyJMpmTfK7hlMj 11 | +wihm3cNAgMBAAGjgaAwgZ0wHQYDVR0OBBYEFDEUSstAp4l3ZDKenwSgpL+sM8ME 12 | MB8GA1UdIwQYMBaAFOUENZvcwmfXlJOSi1CGjzIb/Ul5MA8GA1UdEwEB/wQFMAMB 13 | Af8wDgYDVR0PAQH/BAQDAgEGMDoGA1UdHwQzMDEwL6AtoCuGKWh0dHA6Ly80My44 14 | LjIxOS4zMTo0OTU4MC90ZXN0X2NhL3Jvb3QuY3JsMA0GCSqGSIb3DQEBCwUAA4GB 15 | AGH8xzOTTovvVkGMOD6dVD9mf75Dd7KqhnOi4txpETEAtBXDBmrYARJTWTDNdB35 16 | bjcNvcL2HEXl1rZlgcR2yklx7ZU8KZVcvcq8wn5oQ/IOvgSfrHfVejuEyPRAOR/W 17 | Ek18M4xKyJ++DfPk0dqCQNXkd/hiHdmb1rCpa1te9Mb/ 18 | -----END CERTIFICATE----- 19 | -------------------------------------------------------------------------------- /tests/Data/HttpIntegrationTest/02_https_localhost_cert/cert/client/rootCa/2eec780c.0: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIICtzCCAiCgAwIBAgIJAJTAcemT4ALhMA0GCSqGSIb3DQEBCwUAMGsxCzAJBgNV 3 | BAYTAkpQMQ4wDAYDVQQIDAVUb2t5bzESMBAGA1UEBwwJU2hpbmFnYXdhMQ0wCwYD 4 | VQQKDARTb255MQ8wDQYDVQQLDAZHcm91cDExGDAWBgNVBAMMD0xvY2FsaG9zdFJv 5 | b3RDQTAeFw0xNjA4MjUwOTQzMDVaFw0yNjA3MDQwOTQzMDVaMGsxCzAJBgNVBAYT 6 | AkpQMQ4wDAYDVQQIDAVUb2t5bzESMBAGA1UEBwwJU2hpbmFnYXdhMQ0wCwYDVQQK 7 | DARTb255MQ8wDQYDVQQLDAZHcm91cDExGDAWBgNVBAMMD0xvY2FsaG9zdFJvb3RD 8 | QTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAoAObp9RDTtsjy2LWNipnNGO1 9 | jfwA3/kDOCVKJP/AUX4EJMW4Y0FLmW6/0AH+Vk1bm0sevcS+Bhz9aR+KEFgczPO6 10 | Y+m0yyopXMAnBb0Kzts3hYk1YYtVVZspStEkzc6QTIEgZth/7TquzXTUXRplHZAa 11 | dH7eYJHQNsNLCzyK8KkCAwEAAaNjMGEwHQYDVR0OBBYEFOUENZvcwmfXlJOSi1CG 12 | jzIb/Ul5MB8GA1UdIwQYMBaAFOUENZvcwmfXlJOSi1CGjzIb/Ul5MA8GA1UdEwEB 13 | /wQFMAMBAf8wDgYDVR0PAQH/BAQDAgEGMA0GCSqGSIb3DQEBCwUAA4GBAI5LqqPE 14 | HoM9paAsNQLeqceYG7QJ5kP1HSRKXffuKf/2DZs52cS+1WlQ+gJMM2ffOdVRDZsT 15 | hI4D44282gL2QBZQYmDrZ472VU1Zho6CWpeuTQJLMHZ8NxuNGCQcZhC8HudwKSbX 16 | jGoyQJzE6xiBEHWzrlwSnVWfNh3al9gdtQue 17 | -----END CERTIFICATE----- 18 | -------------------------------------------------------------------------------- /tests/Data/HttpIntegrationTest/02_https_localhost_cert/cert/client/rootCa/c37db6da.0: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIC7TCCAlagAwIBAgIBADANBgkqhkiG9w0BAQsFADBrMQswCQYDVQQGEwJKUDEO 3 | MAwGA1UECAwFVG9reW8xEjAQBgNVBAcMCVNoaW5hZ2F3YTENMAsGA1UECgwEU29u 4 | eTEPMA0GA1UECwwGR3JvdXAxMRgwFgYDVQQDDA9Mb2NhbGhvc3RSb290Q0EwHhcN 5 | MTYwODI1MDk0OTIxWhcNMjYwNzA0MDk0OTIxWjBrMQswCQYDVQQGEwJKUDEOMAwG 6 | A1UECAwFVG9reW8xEjAQBgNVBAcMCVNoaW5hZ2F3YTENMAsGA1UECgwEU29ueTEO 7 | MAwGA1UECwwFVGVhbTExGTAXBgNVBAMMEExvY2FsaG9zdEludGVyQ0EwgZ8wDQYJ 8 | KoZIhvcNAQEBBQADgY0AMIGJAoGBANXKboSURVfr7+vpiCdFWRWImUK/eClwMdbu 9 | ANDFpGK+NShcAycFuh/07qaZc1GwfkQl879W4xxeLVHG98xPFazixenWUj2NEeOM 10 | LeAYFPeYeCNxTYO1Le2L1dsO9SUDFIcsPkrsF8R3YaBYgz+881yyJMpmTfK7hlMj 11 | +wihm3cNAgMBAAGjgaAwgZ0wHQYDVR0OBBYEFDEUSstAp4l3ZDKenwSgpL+sM8ME 12 | MB8GA1UdIwQYMBaAFOUENZvcwmfXlJOSi1CGjzIb/Ul5MA8GA1UdEwEB/wQFMAMB 13 | Af8wDgYDVR0PAQH/BAQDAgEGMDoGA1UdHwQzMDEwL6AtoCuGKWh0dHA6Ly80My44 14 | LjIxOS4zMTo0OTU4MC90ZXN0X2NhL3Jvb3QuY3JsMA0GCSqGSIb3DQEBCwUAA4GB 15 | AGH8xzOTTovvVkGMOD6dVD9mf75Dd7KqhnOi4txpETEAtBXDBmrYARJTWTDNdB35 16 | bjcNvcL2HEXl1rZlgcR2yklx7ZU8KZVcvcq8wn5oQ/IOvgSfrHfVejuEyPRAOR/W 17 | Ek18M4xKyJ++DfPk0dqCQNXkd/hiHdmb1rCpa1te9Mb/ 18 | -----END CERTIFICATE----- 19 | -------------------------------------------------------------------------------- /tests/Data/HttpIntegrationTest/02_https_localhost_cert/cert/client/rootCa/localhost_demoCA.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIICtzCCAiCgAwIBAgIJAJTAcemT4ALhMA0GCSqGSIb3DQEBCwUAMGsxCzAJBgNV 3 | BAYTAkpQMQ4wDAYDVQQIDAVUb2t5bzESMBAGA1UEBwwJU2hpbmFnYXdhMQ0wCwYD 4 | VQQKDARTb255MQ8wDQYDVQQLDAZHcm91cDExGDAWBgNVBAMMD0xvY2FsaG9zdFJv 5 | b3RDQTAeFw0xNjA4MjUwOTQzMDVaFw0yNjA3MDQwOTQzMDVaMGsxCzAJBgNVBAYT 6 | AkpQMQ4wDAYDVQQIDAVUb2t5bzESMBAGA1UEBwwJU2hpbmFnYXdhMQ0wCwYDVQQK 7 | DARTb255MQ8wDQYDVQQLDAZHcm91cDExGDAWBgNVBAMMD0xvY2FsaG9zdFJvb3RD 8 | QTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAoAObp9RDTtsjy2LWNipnNGO1 9 | jfwA3/kDOCVKJP/AUX4EJMW4Y0FLmW6/0AH+Vk1bm0sevcS+Bhz9aR+KEFgczPO6 10 | Y+m0yyopXMAnBb0Kzts3hYk1YYtVVZspStEkzc6QTIEgZth/7TquzXTUXRplHZAa 11 | dH7eYJHQNsNLCzyK8KkCAwEAAaNjMGEwHQYDVR0OBBYEFOUENZvcwmfXlJOSi1CG 12 | jzIb/Ul5MB8GA1UdIwQYMBaAFOUENZvcwmfXlJOSi1CGjzIb/Ul5MA8GA1UdEwEB 13 | /wQFMAMBAf8wDgYDVR0PAQH/BAQDAgEGMA0GCSqGSIb3DQEBCwUAA4GBAI5LqqPE 14 | HoM9paAsNQLeqceYG7QJ5kP1HSRKXffuKf/2DZs52cS+1WlQ+gJMM2ffOdVRDZsT 15 | hI4D44282gL2QBZQYmDrZ472VU1Zho6CWpeuTQJLMHZ8NxuNGCQcZhC8HudwKSbX 16 | jGoyQJzE6xiBEHWzrlwSnVWfNh3al9gdtQue 17 | -----END CERTIFICATE----- 18 | -------------------------------------------------------------------------------- /tests/Data/HttpIntegrationTest/02_https_localhost_cert/cert/client/rootCa/localhost_interCA.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIC7TCCAlagAwIBAgIBADANBgkqhkiG9w0BAQsFADBrMQswCQYDVQQGEwJKUDEO 3 | MAwGA1UECAwFVG9reW8xEjAQBgNVBAcMCVNoaW5hZ2F3YTENMAsGA1UECgwEU29u 4 | eTEPMA0GA1UECwwGR3JvdXAxMRgwFgYDVQQDDA9Mb2NhbGhvc3RSb290Q0EwHhcN 5 | MTYwODI1MDk0OTIxWhcNMjYwNzA0MDk0OTIxWjBrMQswCQYDVQQGEwJKUDEOMAwG 6 | A1UECAwFVG9reW8xEjAQBgNVBAcMCVNoaW5hZ2F3YTENMAsGA1UECgwEU29ueTEO 7 | MAwGA1UECwwFVGVhbTExGTAXBgNVBAMMEExvY2FsaG9zdEludGVyQ0EwgZ8wDQYJ 8 | KoZIhvcNAQEBBQADgY0AMIGJAoGBANXKboSURVfr7+vpiCdFWRWImUK/eClwMdbu 9 | ANDFpGK+NShcAycFuh/07qaZc1GwfkQl879W4xxeLVHG98xPFazixenWUj2NEeOM 10 | LeAYFPeYeCNxTYO1Le2L1dsO9SUDFIcsPkrsF8R3YaBYgz+881yyJMpmTfK7hlMj 11 | +wihm3cNAgMBAAGjgaAwgZ0wHQYDVR0OBBYEFDEUSstAp4l3ZDKenwSgpL+sM8ME 12 | MB8GA1UdIwQYMBaAFOUENZvcwmfXlJOSi1CGjzIb/Ul5MA8GA1UdEwEB/wQFMAMB 13 | Af8wDgYDVR0PAQH/BAQDAgEGMDoGA1UdHwQzMDEwL6AtoCuGKWh0dHA6Ly80My44 14 | LjIxOS4zMTo0OTU4MC90ZXN0X2NhL3Jvb3QuY3JsMA0GCSqGSIb3DQEBCwUAA4GB 15 | AGH8xzOTTovvVkGMOD6dVD9mf75Dd7KqhnOi4txpETEAtBXDBmrYARJTWTDNdB35 16 | bjcNvcL2HEXl1rZlgcR2yklx7ZU8KZVcvcq8wn5oQ/IOvgSfrHfVejuEyPRAOR/W 17 | Ek18M4xKyJ++DfPk0dqCQNXkd/hiHdmb1rCpa1te9Mb/ 18 | -----END CERTIFICATE----- 19 | -------------------------------------------------------------------------------- /tests/Data/HttpIntegrationTest/02_https_localhost_cert/cert/client/rootCa_empty/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sony/easyhttpcpp/ef7dca78f76877d51b329464c322e87eef54195f/tests/Data/HttpIntegrationTest/02_https_localhost_cert/cert/client/rootCa_empty/.gitkeep -------------------------------------------------------------------------------- /tests/Data/HttpIntegrationTest/03_https_localhost_cert_expired/cert/client/rootCa/2eec780c.0: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIICtzCCAiCgAwIBAgIJAJ4AkCwd9zCCMA0GCSqGSIb3DQEBCwUAMGsxCzAJBgNV 3 | BAYTAkpQMQ4wDAYDVQQIDAVUb2t5bzESMBAGA1UEBwwJU2hpbmFnYXdhMQ0wCwYD 4 | VQQKDARTb255MQ8wDQYDVQQLDAZHcm91cDExGDAWBgNVBAMMD0xvY2FsaG9zdFJv 5 | b3RDQTAeFw0xNjA5MDIwNTQwMzZaFw0xNjA5MDMwNTQwMzZaMGsxCzAJBgNVBAYT 6 | AkpQMQ4wDAYDVQQIDAVUb2t5bzESMBAGA1UEBwwJU2hpbmFnYXdhMQ0wCwYDVQQK 7 | DARTb255MQ8wDQYDVQQLDAZHcm91cDExGDAWBgNVBAMMD0xvY2FsaG9zdFJvb3RD 8 | QTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEApqxXxB+LAEGNlU+u/WsFaG5i 9 | DHuqA0DVzLtuRmOf+KT0BhzYL8uYJwORjm5IOc9Jk+pLpl08I6Lcx0k7v7YUbKhP 10 | l2lS0dugpULy+dB1VDcqZYC2EJ/ysXVaes6KDtKfqnU4+Bk6do2fU8Y0aCcKkUqS 11 | w6EHGITDRN2zoDKYOHkCAwEAAaNjMGEwHQYDVR0OBBYEFG9f2X3ERf4Oq90veTY8 12 | VZ8yDp+4MB8GA1UdIwQYMBaAFG9f2X3ERf4Oq90veTY8VZ8yDp+4MA8GA1UdEwEB 13 | /wQFMAMBAf8wDgYDVR0PAQH/BAQDAgEGMA0GCSqGSIb3DQEBCwUAA4GBAEzzfOB9 14 | 5GVfxsz1/zV7suyPLa/mx8i7VCHj6asuIxTFmS++kRegi5/WQZ9K7CZT+NDN5Ruo 15 | +hXn5SoayC+3qf0SKsgGK+JQZIZ/F7O7foFReVcZqmvIYsaivXPmY7q809IkbMc7 16 | 3Jxvz++acuFvA/96gtfCexKuEzj8D04DJVf3 17 | -----END CERTIFICATE----- 18 | -------------------------------------------------------------------------------- /tests/Data/HttpIntegrationTest/03_https_localhost_cert_expired/cert/client/rootCa/c37db6da.0: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIC7TCCAlagAwIBAgIBADANBgkqhkiG9w0BAQsFADBrMQswCQYDVQQGEwJKUDEO 3 | MAwGA1UECAwFVG9reW8xEjAQBgNVBAcMCVNoaW5hZ2F3YTENMAsGA1UECgwEU29u 4 | eTEPMA0GA1UECwwGR3JvdXAxMRgwFgYDVQQDDA9Mb2NhbGhvc3RSb290Q0EwHhcN 5 | MTYwODI1MDk0OTIxWhcNMjYwNzA0MDk0OTIxWjBrMQswCQYDVQQGEwJKUDEOMAwG 6 | A1UECAwFVG9reW8xEjAQBgNVBAcMCVNoaW5hZ2F3YTENMAsGA1UECgwEU29ueTEO 7 | MAwGA1UECwwFVGVhbTExGTAXBgNVBAMMEExvY2FsaG9zdEludGVyQ0EwgZ8wDQYJ 8 | KoZIhvcNAQEBBQADgY0AMIGJAoGBANXKboSURVfr7+vpiCdFWRWImUK/eClwMdbu 9 | ANDFpGK+NShcAycFuh/07qaZc1GwfkQl879W4xxeLVHG98xPFazixenWUj2NEeOM 10 | LeAYFPeYeCNxTYO1Le2L1dsO9SUDFIcsPkrsF8R3YaBYgz+881yyJMpmTfK7hlMj 11 | +wihm3cNAgMBAAGjgaAwgZ0wHQYDVR0OBBYEFDEUSstAp4l3ZDKenwSgpL+sM8ME 12 | MB8GA1UdIwQYMBaAFOUENZvcwmfXlJOSi1CGjzIb/Ul5MA8GA1UdEwEB/wQFMAMB 13 | Af8wDgYDVR0PAQH/BAQDAgEGMDoGA1UdHwQzMDEwL6AtoCuGKWh0dHA6Ly80My44 14 | LjIxOS4zMTo0OTU4MC90ZXN0X2NhL3Jvb3QuY3JsMA0GCSqGSIb3DQEBCwUAA4GB 15 | AGH8xzOTTovvVkGMOD6dVD9mf75Dd7KqhnOi4txpETEAtBXDBmrYARJTWTDNdB35 16 | bjcNvcL2HEXl1rZlgcR2yklx7ZU8KZVcvcq8wn5oQ/IOvgSfrHfVejuEyPRAOR/W 17 | Ek18M4xKyJ++DfPk0dqCQNXkd/hiHdmb1rCpa1te9Mb/ 18 | -----END CERTIFICATE----- 19 | -------------------------------------------------------------------------------- /tests/Data/HttpIntegrationTest/03_https_localhost_cert_expired/cert/client/rootCa/localhost_demoCA_expired.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIICtzCCAiCgAwIBAgIJAJ4AkCwd9zCCMA0GCSqGSIb3DQEBCwUAMGsxCzAJBgNV 3 | BAYTAkpQMQ4wDAYDVQQIDAVUb2t5bzESMBAGA1UEBwwJU2hpbmFnYXdhMQ0wCwYD 4 | VQQKDARTb255MQ8wDQYDVQQLDAZHcm91cDExGDAWBgNVBAMMD0xvY2FsaG9zdFJv 5 | b3RDQTAeFw0xNjA5MDIwNTQwMzZaFw0xNjA5MDMwNTQwMzZaMGsxCzAJBgNVBAYT 6 | AkpQMQ4wDAYDVQQIDAVUb2t5bzESMBAGA1UEBwwJU2hpbmFnYXdhMQ0wCwYDVQQK 7 | DARTb255MQ8wDQYDVQQLDAZHcm91cDExGDAWBgNVBAMMD0xvY2FsaG9zdFJvb3RD 8 | QTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEApqxXxB+LAEGNlU+u/WsFaG5i 9 | DHuqA0DVzLtuRmOf+KT0BhzYL8uYJwORjm5IOc9Jk+pLpl08I6Lcx0k7v7YUbKhP 10 | l2lS0dugpULy+dB1VDcqZYC2EJ/ysXVaes6KDtKfqnU4+Bk6do2fU8Y0aCcKkUqS 11 | w6EHGITDRN2zoDKYOHkCAwEAAaNjMGEwHQYDVR0OBBYEFG9f2X3ERf4Oq90veTY8 12 | VZ8yDp+4MB8GA1UdIwQYMBaAFG9f2X3ERf4Oq90veTY8VZ8yDp+4MA8GA1UdEwEB 13 | /wQFMAMBAf8wDgYDVR0PAQH/BAQDAgEGMA0GCSqGSIb3DQEBCwUAA4GBAEzzfOB9 14 | 5GVfxsz1/zV7suyPLa/mx8i7VCHj6asuIxTFmS++kRegi5/WQZ9K7CZT+NDN5Ruo 15 | +hXn5SoayC+3qf0SKsgGK+JQZIZ/F7O7foFReVcZqmvIYsaivXPmY7q809IkbMc7 16 | 3Jxvz++acuFvA/96gtfCexKuEzj8D04DJVf3 17 | -----END CERTIFICATE----- 18 | -------------------------------------------------------------------------------- /tests/Data/HttpIntegrationTest/03_https_localhost_cert_expired/cert/client/rootCa/localhost_interCA.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIC7TCCAlagAwIBAgIBADANBgkqhkiG9w0BAQsFADBrMQswCQYDVQQGEwJKUDEO 3 | MAwGA1UECAwFVG9reW8xEjAQBgNVBAcMCVNoaW5hZ2F3YTENMAsGA1UECgwEU29u 4 | eTEPMA0GA1UECwwGR3JvdXAxMRgwFgYDVQQDDA9Mb2NhbGhvc3RSb290Q0EwHhcN 5 | MTYwODI1MDk0OTIxWhcNMjYwNzA0MDk0OTIxWjBrMQswCQYDVQQGEwJKUDEOMAwG 6 | A1UECAwFVG9reW8xEjAQBgNVBAcMCVNoaW5hZ2F3YTENMAsGA1UECgwEU29ueTEO 7 | MAwGA1UECwwFVGVhbTExGTAXBgNVBAMMEExvY2FsaG9zdEludGVyQ0EwgZ8wDQYJ 8 | KoZIhvcNAQEBBQADgY0AMIGJAoGBANXKboSURVfr7+vpiCdFWRWImUK/eClwMdbu 9 | ANDFpGK+NShcAycFuh/07qaZc1GwfkQl879W4xxeLVHG98xPFazixenWUj2NEeOM 10 | LeAYFPeYeCNxTYO1Le2L1dsO9SUDFIcsPkrsF8R3YaBYgz+881yyJMpmTfK7hlMj 11 | +wihm3cNAgMBAAGjgaAwgZ0wHQYDVR0OBBYEFDEUSstAp4l3ZDKenwSgpL+sM8ME 12 | MB8GA1UdIwQYMBaAFOUENZvcwmfXlJOSi1CGjzIb/Ul5MA8GA1UdEwEB/wQFMAMB 13 | Af8wDgYDVR0PAQH/BAQDAgEGMDoGA1UdHwQzMDEwL6AtoCuGKWh0dHA6Ly80My44 14 | LjIxOS4zMTo0OTU4MC90ZXN0X2NhL3Jvb3QuY3JsMA0GCSqGSIb3DQEBCwUAA4GB 15 | AGH8xzOTTovvVkGMOD6dVD9mf75Dd7KqhnOi4txpETEAtBXDBmrYARJTWTDNdB35 16 | bjcNvcL2HEXl1rZlgcR2yklx7ZU8KZVcvcq8wn5oQ/IOvgSfrHfVejuEyPRAOR/W 17 | Ek18M4xKyJ++DfPk0dqCQNXkd/hiHdmb1rCpa1te9Mb/ 18 | -----END CERTIFICATE----- 19 | -------------------------------------------------------------------------------- /tests/Data/HttpIntegrationTest/03_https_localhost_cert_expired/cert/server/server.pfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sony/easyhttpcpp/ef7dca78f76877d51b329464c322e87eef54195f/tests/Data/HttpIntegrationTest/03_https_localhost_cert_expired/cert/server/server.pfx -------------------------------------------------------------------------------- /tests/integrationtests/ConnectionConfirmationInterceptor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "ConnectionConfirmationInterceptor.h" 6 | 7 | namespace easyhttpcpp { 8 | namespace test { 9 | 10 | Response::Ptr ConnectionConfirmationInterceptor::intercept(Interceptor::Chain& chain) 11 | { 12 | Response::Ptr pResponse = chain.proceed(chain.getRequest()); 13 | m_pConnection = chain.getConnection(); 14 | return pResponse; 15 | } 16 | 17 | Connection::Ptr ConnectionConfirmationInterceptor::getConnection() 18 | { 19 | return m_pConnection; 20 | } 21 | 22 | void ConnectionConfirmationInterceptor::clearConnection() 23 | { 24 | m_pConnection = NULL; 25 | } 26 | 27 | } /* namespace test */ 28 | } /* namespace easyhttpcpp */ 29 | -------------------------------------------------------------------------------- /tests/integrationtests/ConnectionConfirmationInterceptor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_TEST_INTEGRATIONTEST_CONNECTIONCONFIRMATIONINTERCEPTOR_H_INCLUDED 6 | #define EASYHTTPCPP_TEST_INTEGRATIONTEST_CONNECTIONCONFIRMATIONINTERCEPTOR_H_INCLUDED 7 | 8 | #include "Poco/AutoPtr.h" 9 | 10 | #include "easyhttpcpp/Interceptor.h" 11 | #include "easyhttpcpp/Connection.h" 12 | 13 | namespace easyhttpcpp { 14 | namespace test { 15 | 16 | class ConnectionConfirmationInterceptor : public Interceptor { 17 | public: 18 | typedef Poco::AutoPtr Ptr; 19 | 20 | Response::Ptr intercept(Interceptor::Chain& chain); 21 | Connection::Ptr getConnection(); 22 | void clearConnection(); 23 | private: 24 | Connection::Ptr m_pConnection; 25 | }; 26 | 27 | } /* namespace test */ 28 | } /* namespace easyhttpcpp */ 29 | 30 | #endif /* EASYHTTPCPP_TEST_INTEGRATIONTEST_CONNECTIONCONFIRMATIONINTERCEPTOR_H_INCLUDED */ 31 | -------------------------------------------------------------------------------- /tests/integrationtests/HttpTestResponseCallback.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "HttpTestResponseCallback.h" 6 | 7 | namespace easyhttpcpp { 8 | namespace test { 9 | 10 | static const int TestFailureTimeout = 10 * 1000; // milliseconds 11 | 12 | HttpTestResponseCallback::HttpTestResponseCallback() 13 | { 14 | m_completionTime = Poco::Timestamp::TIMEVAL_MAX; 15 | } 16 | 17 | void HttpTestResponseCallback::onResponse(Response::Ptr pResponse) 18 | { 19 | m_pResponse = pResponse; 20 | m_completionTime.update(); 21 | m_completionEvent.set(); 22 | } 23 | 24 | void HttpTestResponseCallback::onFailure(HttpException::Ptr pWhat) 25 | { 26 | m_pWhat = pWhat; 27 | m_completionTime.update(); 28 | m_completionEvent.set(); 29 | } 30 | 31 | Response::Ptr HttpTestResponseCallback::getResponse() 32 | { 33 | return m_pResponse; 34 | } 35 | 36 | HttpException::Ptr HttpTestResponseCallback::getWhat() 37 | { 38 | return m_pWhat; 39 | } 40 | 41 | bool HttpTestResponseCallback::waitCompletion() 42 | { 43 | return m_completionEvent.tryWait(TestFailureTimeout); 44 | } 45 | 46 | bool HttpTestResponseCallback::waitCompletion(long timeoutMilliSec) 47 | { 48 | return m_completionEvent.tryWait(timeoutMilliSec); 49 | } 50 | 51 | Poco::Timestamp HttpTestResponseCallback::getCompletionTime() const 52 | { 53 | return m_completionTime; 54 | } 55 | 56 | } /* namespace test */ 57 | } /* namespace easyhttpcpp */ 58 | -------------------------------------------------------------------------------- /tests/integrationtests/HttpTestResponseCallback.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_TEST_INTEGRATIONTEST_HTTPTESTRESPONSECALLBACK_H_INCLUDED 6 | #define EASYHTTPCPP_TEST_INTEGRATIONTEST_HTTPTESTRESPONSECALLBACK_H_INCLUDED 7 | 8 | #include "Poco/AutoPtr.h" 9 | #include "Poco/Event.h" 10 | #include "Poco/Timestamp.h" 11 | 12 | #include "easyhttpcpp/ResponseCallback.h" 13 | 14 | namespace easyhttpcpp { 15 | namespace test { 16 | 17 | class HttpTestResponseCallback : public ResponseCallback { 18 | public: 19 | typedef Poco::AutoPtr Ptr; 20 | 21 | HttpTestResponseCallback(); 22 | virtual void onResponse(Response::Ptr pResponse); 23 | virtual void onFailure(HttpException::Ptr pWhat); 24 | Response::Ptr getResponse(); 25 | HttpException::Ptr getWhat(); 26 | bool waitCompletion(); 27 | bool waitCompletion(long timeoutMilliSec); 28 | Poco::Timestamp getCompletionTime() const; 29 | 30 | private: 31 | Response::Ptr m_pResponse; 32 | HttpException::Ptr m_pWhat; 33 | Poco::Event m_completionEvent; 34 | Poco::Timestamp m_completionTime; 35 | }; 36 | 37 | } /* namespace test */ 38 | } /* namespace easyhttpcpp */ 39 | 40 | #endif /* EASYHTTPCPP_TEST_INTEGRATIONTEST_HTTPTESTRESPONSECALLBACK_H_INCLUDED */ 41 | -------------------------------------------------------------------------------- /tests/integrationtests/MockHttpCacheEnumerationListener.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_TEST_MOCKHTTPCACHEENUMERATIONLISTENER_H_INCLUDED 6 | #define EASYHTTPCPP_TEST_MOCKHTTPCACHEENUMERATIONLISTENER_H_INCLUDED 7 | 8 | #include "gmock/gmock.h" 9 | 10 | #include "MockHttpCacheEnumerationListener.h" 11 | 12 | namespace easyhttpcpp { 13 | namespace test { 14 | 15 | class MockHttpCacheEnumerationListener : public HttpCacheEnumerationListener { 16 | public: 17 | MOCK_METHOD1(onEnumerate, bool(const EnumerationParam& param)); 18 | }; 19 | 20 | } /* namespace test */ 21 | } /* namespace easyhttpcpp */ 22 | 23 | #endif /* EASYHTTPCPP_TEST_MOCKHTTPCACHEENUMERATIONLISTENER_H_INCLUDED */ 24 | -------------------------------------------------------------------------------- /tests/integrationtests/SynchronizedExecutionRunner.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "Poco/Event.h" 6 | #include "Poco/RefCountedObject.h" 7 | #include "Poco/Runnable.h" 8 | 9 | #ifndef EASYHTTPCPP_TEST_INTEGRATIONTEST_SYNCHRONIZEDEXECUTIONRUNNER_H_INCLUDED 10 | #define EASYHTTPCPP_TEST_INTEGRATIONTEST_SYNCHRONIZEDEXECUTIONRUNNER_H_INCLUDED 11 | 12 | namespace easyhttpcpp { 13 | namespace test { 14 | 15 | class SynchronizedExecutionRunner : public Poco::Runnable, public Poco::RefCountedObject { 16 | public: 17 | SynchronizedExecutionRunner(); 18 | virtual ~SynchronizedExecutionRunner(); 19 | virtual void run(); 20 | virtual bool execute() = 0; 21 | bool isSuccess(); 22 | bool waitToReady(); 23 | void setToStart(); 24 | bool waitToFinish(); 25 | protected: 26 | void setToReady(); 27 | bool waitToStart(); 28 | void setToFinish(); 29 | private: 30 | bool m_succeeded; 31 | Poco::Event m_readyEvent; 32 | Poco::Event m_startEvent; 33 | Poco::Event m_finishEvent; 34 | }; 35 | 36 | } /* namespace test */ 37 | } /* namespace easyhttpcpp */ 38 | 39 | #endif /* EASYHTTPCPP_TEST_INTEGRATIONTEST_SYNCHRONIZEDEXECUTIONRUNNER_H_INCLUDED */ 40 | -------------------------------------------------------------------------------- /tests/integrationtests/db/SqliteDatabaseIntegrationTestConstants.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "easyhttpcpp/common/CommonMacros.h" 6 | 7 | #include "SqliteDatabaseIntegrationTestConstants.h" 8 | 9 | namespace easyhttpcpp { 10 | namespace db { 11 | namespace test { 12 | 13 | const char* const SqliteDatabaseIntegrationTestConstants::DatabaseDir = EASYHTTPCPP_STRINGIFY_MACRO(RUNTIME_DATA_ROOT); 14 | const char* const SqliteDatabaseIntegrationTestConstants::DatabaseFileName = "database_test.db"; 15 | const char* const SqliteDatabaseIntegrationTestConstants::DatabaseTableName = "table_for_test"; 16 | 17 | } /* namespace test */ 18 | } /* namespace db */ 19 | } /* namespace easyhttpcpp */ 20 | -------------------------------------------------------------------------------- /tests/integrationtests/db/SqliteDatabaseIntegrationTestConstants.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_DB_TEST_INTEGRATIONTEST_SQLITEDATABASEINTEGRATIONTESTCONSTANTS_H_INCLUDED 6 | #define EASYHTTPCPP_DB_TEST_INTEGRATIONTEST_SQLITEDATABASEINTEGRATIONTESTCONSTANTS_H_INCLUDED 7 | 8 | namespace easyhttpcpp { 9 | namespace db { 10 | namespace test { 11 | 12 | class SqliteDatabaseIntegrationTestConstants { 13 | public: 14 | static const char* const DatabaseDir; 15 | static const char* const DatabaseFileName; 16 | static const char* const DatabaseTableName; 17 | }; 18 | 19 | } /* namespace test */ 20 | } /* namespace db */ 21 | } /* namespace easyhttpcpp */ 22 | 23 | #endif /* EASYHTTPCPP_DB_TEST_INTEGRATIONTEST_SQLITEDATABASEINTEGRATIONTESTCONSTANTS_H_INCLUDED */ 24 | -------------------------------------------------------------------------------- /tests/testutil/FileContentsEqualMatcher.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_TESTUTIL_FILECONTENTSEQUALMATCHER_H_INCLUDED 6 | #define EASYHTTPCPP_TESTUTIL_FILECONTENTSEQUALMATCHER_H_INCLUDED 7 | 8 | #include 9 | #include "gmock/gmock.h" 10 | 11 | #include "Poco/File.h" 12 | 13 | #include "TestUtilExports.h" 14 | 15 | namespace easyhttpcpp { 16 | namespace testutil { 17 | 18 | class EASYHTTPCPP_TESTUTIL_API FileContentsEqualMatcher { 19 | public: 20 | FileContentsEqualMatcher(const char* pExpectedData, size_t expectedDataBytes); 21 | virtual ~FileContentsEqualMatcher(); 22 | 23 | bool MatchAndExplain(const std::string& filePath, testing::MatchResultListener* listener) const; 24 | 25 | void DescribeTo(std::ostream* os) const; 26 | void DescribeNegationTo(std::ostream* os) const; 27 | 28 | private: 29 | std::string exchangeDataToDisplayString(const char* pData, size_t dataBytes) const; 30 | 31 | const char* m_pExpectedData; 32 | const size_t m_expectedDataBytes; 33 | }; 34 | 35 | inline testing::PolymorphicMatcher equalsContentsOfFile(const char* pExpectedData, 36 | size_t expectedDataBytes) 37 | { 38 | return testing::MakePolymorphicMatcher(FileContentsEqualMatcher(pExpectedData, expectedDataBytes)); 39 | } 40 | 41 | } /* namespace testutil */ 42 | } /* namespace easyhttpcpp */ 43 | 44 | #endif /* EASYHTTPCPP_TESTUTIL_FILECONTENTSEQUALMATCHER_H_INCLUDED */ 45 | -------------------------------------------------------------------------------- /tests/testutil/HeaderContainMatcher.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_TESTUTIL_HEADERCONTAINMATCHER_H_INCLUDED 6 | #define EASYHTTPCPP_TESTUTIL_HEADERCONTAINMATCHER_H_INCLUDED 7 | 8 | #include 9 | #include "gmock/gmock.h" 10 | 11 | #include "easyhttpcpp/Headers.h" 12 | #include "TestUtilExports.h" 13 | 14 | namespace easyhttpcpp { 15 | namespace testutil { 16 | 17 | class EASYHTTPCPP_TESTUTIL_API HeaderContainMatcher { 18 | public: 19 | HeaderContainMatcher(const std::string& name, const std::string& value); 20 | HeaderContainMatcher(const std::string& name); 21 | virtual ~HeaderContainMatcher(); 22 | 23 | bool MatchAndExplain(easyhttpcpp::Headers::Ptr pActual, testing::MatchResultListener* listener) const; 24 | 25 | void DescribeTo(std::ostream* os) const; 26 | void DescribeNegationTo(std::ostream* os) const; 27 | 28 | private: 29 | std::string m_name; 30 | std::string m_value; 31 | bool m_keyOnly; 32 | }; 33 | 34 | inline testing::PolymorphicMatcher containsInHeader(const std::string& name, 35 | const std::string& value) 36 | { 37 | return testing::MakePolymorphicMatcher(HeaderContainMatcher(name, value)); 38 | } 39 | 40 | inline testing::PolymorphicMatcher hasKeyInHeader(const std::string& name) 41 | { 42 | return testing::MakePolymorphicMatcher(HeaderContainMatcher(name)); 43 | } 44 | 45 | } /* namespace testutil */ 46 | } /* namespace easyhttpcpp */ 47 | 48 | #endif /* EASYHTTPCPP_TESTUTIL_HEADERCONTAINMATCHER_H_INCLUDED */ 49 | -------------------------------------------------------------------------------- /tests/testutil/HeadersEqualMatcher.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_TESTUTIL_HEADERSEQUALMATCHER_H_INCLUDED 6 | #define EASYHTTPCPP_TESTUTIL_HEADERSEQUALMATCHER_H_INCLUDED 7 | 8 | #include 9 | #include "gmock/gmock.h" 10 | 11 | #include "easyhttpcpp/Headers.h" 12 | #include "TestUtilExports.h" 13 | 14 | namespace easyhttpcpp { 15 | namespace testutil { 16 | 17 | class EASYHTTPCPP_TESTUTIL_API HeadersEqualMatcher { 18 | public: 19 | HeadersEqualMatcher(easyhttpcpp::Headers::Ptr pHeaders); 20 | 21 | virtual ~HeadersEqualMatcher(); 22 | 23 | bool MatchAndExplain(easyhttpcpp::Headers::Ptr pActual, testing::MatchResultListener* listener) const; 24 | 25 | void DescribeTo(std::ostream* os) const; 26 | void DescribeNegationTo(std::ostream* os) const; 27 | 28 | private: 29 | easyhttpcpp::Headers::Ptr m_pExpectedHeaders; 30 | }; 31 | 32 | inline testing::PolymorphicMatcher equalHeaders(easyhttpcpp::Headers::Ptr pHeaders) 33 | { 34 | return testing::MakePolymorphicMatcher(HeadersEqualMatcher(pHeaders)); 35 | } 36 | 37 | } /* namespace testutil */ 38 | } /* namespace easyhttpcpp */ 39 | 40 | #endif /* EASYHTTPCPP_TESTUTIL_HEADERSEQUALMATCHER_H_INCLUDED */ 41 | -------------------------------------------------------------------------------- /tests/testutil/HttpTestServer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "Poco/Net/HTTPServerParams.h" 6 | #include "Poco/Net/ServerSocket.h" 7 | 8 | #include "easyhttpcpp/common/CoreLogger.h" 9 | #include "HttpTestServer.h" 10 | #include "HttpTestRequestHandlerFactory.h" 11 | 12 | namespace easyhttpcpp { 13 | namespace testutil { 14 | 15 | static const std::string Tag = "TestHttpServer"; 16 | 17 | HttpTestServer::HttpTestServer() 18 | { 19 | } 20 | 21 | HttpTestServer::~HttpTestServer() 22 | { 23 | } 24 | 25 | Poco::Net::ServerSocket* HttpTestServer::newSocket(unsigned short port) 26 | { 27 | return new Poco::Net::ServerSocket(port); 28 | } 29 | 30 | } /* namespace testutil */ 31 | } /* namespace easyhttpcpp */ 32 | -------------------------------------------------------------------------------- /tests/testutil/HttpTestServer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_TESTUTIL_HTTPTESTSERVER_H_INCLUDED 6 | #define EASYHTTPCPP_TESTUTIL_HTTPTESTSERVER_H_INCLUDED 7 | 8 | #include "TestServer.h" 9 | 10 | #include "TestUtilExports.h" 11 | 12 | namespace easyhttpcpp { 13 | namespace testutil { 14 | 15 | class EASYHTTPCPP_TESTUTIL_API HttpTestServer : public TestServer { 16 | public: 17 | HttpTestServer(); 18 | virtual ~HttpTestServer(); 19 | 20 | protected: 21 | virtual Poco::Net::ServerSocket* newSocket(unsigned short port); 22 | 23 | }; 24 | 25 | } /* namespace testutil */ 26 | } /* namespace easyhttpcpp */ 27 | 28 | #endif /* EASYHTTPCPP_TESTUTIL_HTTPTESTSERVER_H_INCLUDED */ 29 | -------------------------------------------------------------------------------- /tests/testutil/HttpsTestServer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_TESTUTIL_HTTPSTESTSERVER_H_INCLUDED 6 | #define EASYHTTPCPP_TESTUTIL_HTTPSTESTSERVER_H_INCLUDED 7 | 8 | #include "Poco/Path.h" 9 | 10 | #include "HttpTestServer.h" 11 | 12 | #include "TestUtilExports.h" 13 | 14 | namespace easyhttpcpp { 15 | namespace testutil { 16 | 17 | 18 | class EASYHTTPCPP_TESTUTIL_API HttpsTestServer : public TestServer { 19 | public: 20 | HttpsTestServer(); 21 | virtual ~HttpsTestServer(); 22 | void setPrivateKeyFile(const Poco::Path& privateKeyFile); 23 | void setCertificateFile(const Poco::Path& certificateFile); 24 | void setCaLocation(const Poco::Path& caLocation); 25 | void setCertUnitedFile(const Poco::Path& certUnitedFile); 26 | void useDefaultCa(bool defaultCaUsed); 27 | 28 | protected: 29 | virtual Poco::Net::ServerSocket* newSocket(unsigned short port); 30 | 31 | private: 32 | Poco::Path m_privateKeyFile; 33 | Poco::Path m_certificateFile; 34 | Poco::Path m_caLocation; 35 | bool m_defaultCaUsed; 36 | }; 37 | 38 | } /* namespace testutil */ 39 | } /* namespace easyhttpcpp */ 40 | 41 | #endif /* EASYHTTPCPP_TESTUTIL_HTTPSTESTSERVER_H_INCLUDED */ 42 | -------------------------------------------------------------------------------- /tests/testutil/MockCache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_TESTUTIL_MOCKCACHE_H_INCLUDED 6 | #define EASYHTTPCPP_TESTUTIL_MOCKCACHE_H_INCLUDED 7 | 8 | #include "gmock/gmock.h" 9 | 10 | #include "easyhttpcpp/common/Cache.h" 11 | 12 | namespace easyhttpcpp { 13 | namespace testutil { 14 | 15 | class MockCache : public easyhttpcpp::common::Cache { 16 | public: 17 | MOCK_METHOD2(getMetadata, bool(const std::string& key, easyhttpcpp::common::CacheMetadata::Ptr& pCacheMetadata)); 18 | MOCK_METHOD2(getData, bool(const std::string& key, std::istream*& pStream)); 19 | MOCK_METHOD3(get, bool(const std::string& key, easyhttpcpp::common::CacheMetadata::Ptr& pCacheMetadata, 20 | std::istream*& pStream)); 21 | MOCK_METHOD2(putMetadata, bool(const std::string& key, easyhttpcpp::common::CacheMetadata::Ptr pCacheMetadata)); 22 | MOCK_METHOD3(put, bool(const std::string& key, easyhttpcpp::common::CacheMetadata::Ptr pCacheMetadata, 23 | const std::string& path)); 24 | MOCK_METHOD3(put, bool(const std::string& key, easyhttpcpp::common::CacheMetadata::Ptr pCacheMetadata, 25 | Poco::SharedPtr pData)); 26 | MOCK_METHOD1(remove, bool(const std::string& key)); 27 | MOCK_METHOD1(releaseData, void(const std::string& key)); 28 | MOCK_METHOD1(purge, bool(bool mayDeleteIfBusy)); 29 | }; 30 | 31 | } /* namespace testutil */ 32 | } /* namespace easyhttpcpp */ 33 | 34 | #endif /* EASYHTTPCPP_TESTUTIL_MOCKCACHE_H_INCLUDED */ 35 | -------------------------------------------------------------------------------- /tests/testutil/MockCacheStrategyListener.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_TESTUTIL_MOCKCACHESTRATEGYLISTENER_H_INCLUDED 6 | #define EASYHTTPCPP_TESTUTIL_MOCKCACHESTRATEGYLISTENER_H_INCLUDED 7 | 8 | #include "easyhttpcpp/common/CacheInfoWithDataSize.h" 9 | #include "easyhttpcpp/common/CacheStrategyListener.h" 10 | 11 | namespace easyhttpcpp { 12 | namespace testutil { 13 | 14 | class MockCacheStrategyListener : 15 | public easyhttpcpp::common::CacheStrategyListener { 16 | public: 17 | MOCK_METHOD2(onAdd, bool(const std::string& key, easyhttpcpp::common::CacheInfoWithDataSize::Ptr value)); 18 | MOCK_METHOD2(onUpdate, bool(const std::string& key, easyhttpcpp::common::CacheInfoWithDataSize::Ptr value)); 19 | MOCK_METHOD1(onRemove, bool(const std::string& key)); 20 | MOCK_METHOD2(onGet, bool(const std::string& key, easyhttpcpp::common::CacheInfoWithDataSize::Ptr value)); 21 | }; 22 | 23 | } /* namespace testutil */ 24 | } /* namespace easyhttpcpp */ 25 | 26 | #endif /* EASYHTTPCPP_TESTUTIL_MOCKCACHESTRATEGYLISTENER_H_INCLUDED */ 27 | -------------------------------------------------------------------------------- /tests/testutil/MockFuture.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_TESTUTIL_MOCKFUTURE_H_INCLUDED 6 | #define EASYHTTPCPP_TESTUTIL_MOCKFUTURE_H_INCLUDED 7 | 8 | #include "gmock/gmock.h" 9 | 10 | #include "Poco/SharedPtr.h" 11 | 12 | #include "easyhttpcpp/common/Future.h" 13 | 14 | namespace easyhttpcpp { 15 | namespace testutil { 16 | 17 | template 18 | class MockFuture : public common::Future { 19 | public: 20 | typedef Poco::SharedPtr > Ptr; 21 | 22 | MOCK_METHOD1_T(cancel, bool(bool mayInterruptIfRunning)); 23 | MOCK_CONST_METHOD0_T(isCancelled, bool()); 24 | MOCK_CONST_METHOD0_T(isDone, bool()); 25 | MOCK_METHOD0_T(get, Result()); 26 | MOCK_METHOD1_T(get, Result(unsigned long timeoutMillis)); 27 | }; 28 | 29 | } /* namespace testutil */ 30 | } /* namespace easyhttpcpp */ 31 | 32 | #endif /* EASYHTTPCPP_TESTUTIL_MOCKFUTURE_H_INCLUDED */ 33 | -------------------------------------------------------------------------------- /tests/testutil/MockHttpCache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_TESTUTIL_MOCKHTTPCACHE_H_INCLUDED 6 | #define EASYHTTPCPP_TESTUTIL_MOCKHTTPCACHE_H_INCLUDED 7 | 8 | #include "gmock/gmock.h" 9 | 10 | #include "easyhttpcpp/HttpCache.h" 11 | 12 | namespace easyhttpcpp { 13 | namespace testutil { 14 | 15 | class MockHttpCache : public easyhttpcpp::HttpCache { 16 | public: 17 | typedef Poco::AutoPtr Ptr; 18 | 19 | virtual ~MockHttpCache() 20 | { 21 | } 22 | 23 | MOCK_CONST_METHOD0(getPath, const Poco::Path&()); 24 | MOCK_METHOD0(evictAll, void()); 25 | MOCK_CONST_METHOD0(getMaxSize, size_t()); 26 | MOCK_METHOD0(getSize, size_t()); 27 | }; 28 | 29 | } /* namespace testutil */ 30 | } /* namespace easyhttpcpp */ 31 | 32 | #endif /* EASYHTTPCPP_TESTUTIL_MOCKHTTPCACHE_H_INCLUDED */ 33 | -------------------------------------------------------------------------------- /tests/testutil/MockInterceptor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_TESTUTIL_MOCKINTERCEPTOR_H_INCLUDED 6 | #define EASYHTTPCPP_TESTUTIL_MOCKINTERCEPTOR_H_INCLUDED 7 | 8 | #include "gtest/gtest.h" 9 | #include "gmock/gmock.h" 10 | 11 | #include "easyhttpcpp/Interceptor.h" 12 | 13 | namespace easyhttpcpp { 14 | namespace testutil { 15 | 16 | class MockInterceptor : public easyhttpcpp::Interceptor { 17 | public: 18 | typedef Poco::AutoPtr Ptr; 19 | 20 | MOCK_METHOD1(intercept, easyhttpcpp::Response::Ptr(Interceptor::Chain& chain)); 21 | }; 22 | 23 | } /* namespace testutil */ 24 | } /* namespace easyhttpcpp */ 25 | 26 | #endif /* EASYHTTPCPP_TESTUTIL_MOCKINTERCEPTOR_H_INCLUDED */ 27 | -------------------------------------------------------------------------------- /tests/testutil/MockRequest.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_TESTUTIL_MOCKREQUEST_H_INCLUDED 6 | #define EASYHTTPCPP_TESTUTIL_MOCKREQUEST_H_INCLUDED 7 | 8 | #include "gtest/gtest.h" 9 | #include "gmock/gmock.h" 10 | 11 | #include "easyhttpcpp/Request.h" 12 | 13 | namespace easyhttpcpp { 14 | namespace testutil { 15 | 16 | class MockRequest : public easyhttpcpp::Request { 17 | public: 18 | MockRequest(easyhttpcpp::Request::Builder& builder) : easyhttpcpp::Request(builder) 19 | { 20 | } 21 | 22 | MOCK_CONST_METHOD0(getBody, easyhttpcpp::RequestBody::Ptr()); 23 | MOCK_CONST_METHOD0(getCacheControl, easyhttpcpp::CacheControl::Ptr()); 24 | MOCK_CONST_METHOD2(getHeaderValue, const std::string&(const std::string& name, const std::string& defaultValue)); 25 | MOCK_CONST_METHOD1(hasHeader, bool(const std::string& name)); 26 | MOCK_CONST_METHOD0(getHeaders, easyhttpcpp::Headers::Ptr()); 27 | MOCK_CONST_METHOD0(getMethod, easyhttpcpp::Request::HttpMethod()); 28 | MOCK_CONST_METHOD0(getTag, const void*()); 29 | MOCK_CONST_METHOD0(getUrl, const std::string&()); 30 | }; 31 | 32 | } /* namespace testutil */ 33 | } /* namespace easyhttpcpp */ 34 | 35 | #endif /* EASYHTTPCPP_TESTUTIL_MOCKREQUEST_H_INCLUDED */ 36 | -------------------------------------------------------------------------------- /tests/testutil/MockResponseBodyStream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_TESTUTIL_MOCKRESPONSEBODYSTREAM_H_INCLUDED 6 | #define EASYHTTPCPP_TESTUTIL_MOCKRESPONSEBODYSTREAM_H_INCLUDED 7 | 8 | #include "easyhttpcpp/ResponseBodyStream.h" 9 | 10 | namespace easyhttpcpp { 11 | namespace testutil { 12 | 13 | class MockResponseBodyStream : public easyhttpcpp::ResponseBodyStream { 14 | public: 15 | MOCK_METHOD2(read, ssize_t(char* pBuffer, size_t readBytes)); 16 | MOCK_METHOD0(isEof, bool()); 17 | MOCK_METHOD0(close, void()); 18 | }; 19 | 20 | } /* namespace testutil */ 21 | } /* namespace easyhttpcpp */ 22 | 23 | #endif /* EASYHTTPCPP_TESTUTIL_MOCKRESPONSEBODYSTREAM_H_INCLUDED */ 24 | -------------------------------------------------------------------------------- /tests/testutil/PartialMockFutureTask.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_TESTUTIL_PARTIALMOCKFUTURETASK_H_INCLUDED 6 | #define EASYHTTPCPP_TESTUTIL_PARTIALMOCKFUTURETASK_H_INCLUDED 7 | 8 | #include "gmock/gmock.h" 9 | 10 | #include "easyhttpcpp/executorservice/FutureTask.h" 11 | 12 | namespace easyhttpcpp { 13 | namespace testutil { 14 | 15 | template 16 | class PartialMockFutureTask : public executorservice::FutureTask { 17 | public: 18 | typedef Poco::AutoPtr > Ptr; 19 | 20 | MOCK_METHOD0(runTask, void()); 21 | }; 22 | 23 | } /* namespace testutil */ 24 | } /* namespace easyhttpcpp */ 25 | 26 | #endif /* EASYHTTPCPP_TESTUTIL_PARTIALMOCKFUTURETASK_H_INCLUDED */ 27 | -------------------------------------------------------------------------------- /tests/testutil/PartialMockScheduledFutureTask.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_TESTUTIL_PARTIALMOCKSCHEDULEDFUTURETASK_H_INCLUDED 6 | #define EASYHTTPCPP_TESTUTIL_PARTIALMOCKSCHEDULEDFUTURETASK_H_INCLUDED 7 | 8 | #include "gmock/gmock.h" 9 | 10 | #include "easyhttpcpp/executorservice/ScheduledFutureTask.h" 11 | 12 | namespace easyhttpcpp { 13 | namespace testutil { 14 | 15 | template 16 | class PartialMockScheduledFutureTask : public executorservice::ScheduledFutureTask { 17 | public: 18 | typedef Poco::AutoPtr > Ptr; 19 | 20 | MOCK_METHOD0(runTask, void()); 21 | }; 22 | 23 | } /* namespace testutil */ 24 | } /* namespace easyhttpcpp */ 25 | 26 | #endif /* EASYHTTPCPP_TESTUTIL_PARTIALMOCKSCHEDULEDFUTURETASK_H_INCLUDED */ 27 | -------------------------------------------------------------------------------- /tests/testutil/RandomUtil.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "Poco/Random.h" 6 | #include "Poco/Buffer.h" 7 | 8 | #include "easyhttpcpp/common/ByteArrayBuffer.h" 9 | #include "easyhttpcpp/common/Typedef.h" 10 | #include "RandomUtil.h" 11 | 12 | using easyhttpcpp::common::Byte; 13 | using easyhttpcpp::common::ByteArrayBuffer; 14 | 15 | namespace easyhttpcpp { 16 | namespace testutil { 17 | 18 | void RandomUtil::getRandomBytes(size_t size, ByteArrayBuffer& buffer) 19 | { 20 | Poco::Random random; 21 | Poco::Buffer bytes(size); 22 | for (size_t i = 0; i < size; i++) { 23 | bytes[i] = random.nextChar(); 24 | } 25 | buffer.write(bytes.begin(), bytes.size()); 26 | } 27 | 28 | } /* namespace testutil */ 29 | } /* namespace easyhttpcpp */ 30 | -------------------------------------------------------------------------------- /tests/testutil/RandomUtil.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_TESTUTIL_RANDOMUTIL_H_INCLUDED 6 | #define EASYHTTPCPP_TESTUTIL_RANDOMUTIL_H_INCLUDED 7 | 8 | #include "TestUtilExports.h" 9 | 10 | namespace easyhttpcpp { 11 | namespace testutil { 12 | 13 | class EASYHTTPCPP_TESTUTIL_API RandomUtil { 14 | public: 15 | static void getRandomBytes(size_t size, easyhttpcpp::common::ByteArrayBuffer& buffer); 16 | 17 | private: 18 | RandomUtil(); 19 | 20 | }; 21 | 22 | } /* namespace testutil */ 23 | } /* namespace easyhttpcpp */ 24 | 25 | #endif /* EASYHTTPCPP_TESTUTIL_RANDOMUTIL_H_INCLUDED */ 26 | -------------------------------------------------------------------------------- /tests/testutil/StdCLogCapture.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_TESTUTIL_STDCLOGCAPTURE_H_INCLUDED 6 | #define EASYHTTPCPP_TESTUTIL_STDCLOGCAPTURE_H_INCLUDED 7 | 8 | #include 9 | 10 | #include "Poco/Buffer.h" 11 | #include "Poco/MemoryStream.h" 12 | #include "Poco/SharedPtr.h" 13 | 14 | #include "TestUtilExports.h" 15 | 16 | namespace easyhttpcpp { 17 | namespace testutil { 18 | 19 | class EASYHTTPCPP_TESTUTIL_API StdCLogCapture { 20 | public: 21 | typedef std::vector CapturedLinesVec; 22 | 23 | StdCLogCapture(size_t captureSizeMax); 24 | virtual ~StdCLogCapture(); 25 | 26 | void startCapture(); 27 | CapturedLinesVec getCapture(); 28 | void endCapture(); 29 | 30 | private: 31 | std::streambuf* m_pOldRdbuf; 32 | Poco::SharedPtr< Poco::Buffer > m_pPocoBuffer; 33 | Poco::SharedPtr< Poco::MemoryOutputStream > m_pPocoMemoryStream; 34 | }; 35 | 36 | } /* namespace testutil */ 37 | } /* namespace easyhttpcpp */ 38 | 39 | #endif /* EASYHTTPCPP_TESTUTIL_STDCLOGCAPTURE_H_INCLUDED */ 40 | -------------------------------------------------------------------------------- /tests/testutil/TestConstants.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "TestConstants.h" 6 | 7 | namespace easyhttpcpp { 8 | namespace testutil { 9 | 10 | const char* const TestConstants::AppIdDevEnclaveClient = "1008"; 11 | const char* const TestConstants::AnalyticsDispatchEndpointQaV1 = "https://bdcore-asq-lb.bda.csxdev.com/actionlog/"; 12 | const char* const TestConstants::AnalyticsDispatchEndpointQaV2 = 13 | "https://sr-logcollector-qas.alph.cloud/v1/direct/999999999999DUMMY/log"; 14 | const char* const TestConstants::LoaderDistributionBaseUrl = "http://d3d9bizloqaofq.cloudfront.net/"; 15 | const char* const TestConstants::LoaderDistributionCertificateUrl1008 = 16 | "https://d2w29nwp6bf7n5.cloudfront.net/certificates/1008"; 17 | const char* const TestConstants::BaseUrlSni = "http://cdn.meta.csxdev.com/"; 18 | const char* const TestConstants::CertificateUrlEnclaveConfiguration 19 | = "https://d2w29nwp6bf7n5.cloudfront.net/certificates"; 20 | const char* const TestConstants::CertificateUrlSni = "https://cert-cdn.meta.csxdev.com/certificates/1008"; 21 | const char* const TestConstants::LongDirName64byte = "012345678901234567890123456789012345678901234567890LongDirName64"; 22 | 23 | } /* namespace testutil */ 24 | } /* namespace easyhttpcpp */ 25 | -------------------------------------------------------------------------------- /tests/testutil/TestConstants.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_TESTUTIL_TESTCONSTANTS_H_INCLUDED 6 | #define EASYHTTPCPP_TESTUTIL_TESTCONSTANTS_H_INCLUDED 7 | 8 | #include "TestUtilExports.h" 9 | 10 | namespace easyhttpcpp { 11 | namespace testutil { 12 | 13 | class EASYHTTPCPP_TESTUTIL_API TestConstants { 14 | public: 15 | static const char* const AppIdDevEnclaveClient; 16 | static const char* const AnalyticsDispatchEndpointQaV1; 17 | static const char* const AnalyticsDispatchEndpointQaV2; 18 | static const char* const LoaderDistributionBaseUrl; 19 | static const char* const LoaderDistributionCertificateUrl1008; 20 | static const char* const BaseUrlSni; 21 | static const char* const CertificateUrlEnclaveConfiguration; 22 | static const char* const CertificateUrlSni; 23 | static const char* const LongDirName64byte; 24 | }; 25 | 26 | } /* namespace testutil */ 27 | } /* namespace easyhttpcpp */ 28 | 29 | #endif /* EASYHTTPCPP_TESTUTIL_TESTCONSTANTS_H_INCLUDED */ 30 | -------------------------------------------------------------------------------- /tests/testutil/TestDatabaseUtil.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_TESTUTIL_TESTDATABASEUTIL_H_INCLUDED 6 | #define EASYHTTPCPP_TESTUTIL_TESTDATABASEUTIL_H_INCLUDED 7 | 8 | #include "Poco/Path.h" 9 | 10 | #include "TestUtilExports.h" 11 | 12 | namespace easyhttpcpp { 13 | namespace testutil { 14 | 15 | class EASYHTTPCPP_TESTUTIL_API TestDatabaseUtil { 16 | public: 17 | static bool isTableExist(const Poco::Path& databasePath, unsigned int version, const std::string& tableName); 18 | private: 19 | TestDatabaseUtil(); 20 | }; 21 | 22 | } /* namespace testutil */ 23 | } /* namespace easyhttpcpp */ 24 | 25 | #endif /* EASYHTTPCPP_TESTUTIL_TESTDATABASEUTIL_H_INCLUDED */ 26 | -------------------------------------------------------------------------------- /tests/testutil/TestDefs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_TESTUTIL_TESTDEFS_H_INCLUDED 6 | #define EASYHTTPCPP_TESTUTIL_TESTDEFS_H_INCLUDED 7 | 8 | namespace easyhttpcpp { 9 | namespace testutil { 10 | 11 | #define EASYHTTPCPP_RAW(...) #__VA_ARGS__ 12 | 13 | } /* namespace testutil */ 14 | } /* namespace easyhttpcpp */ 15 | 16 | #endif /* EASYHTTPCPP_TESTUTIL_TESTDEFS_H_INCLUDED */ 17 | -------------------------------------------------------------------------------- /tests/testutil/TestFileUtil.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | #include "easyhttpcpp/common/CoreLogger.h" 5 | #include "easyhttpcpp/common/FileUtil.h" 6 | #include "TestConstants.h" 7 | #include "TestFileUtil.h" 8 | #ifdef _WIN32 9 | #include "windows/TestFileUtilImpl.h" 10 | #else 11 | #include "unix/TestFileUtilImpl.h" 12 | #endif 13 | 14 | using easyhttpcpp::common::FileUtil; 15 | 16 | namespace easyhttpcpp { 17 | namespace testutil { 18 | 19 | static const std::string Tag = "TestFileUtil"; 20 | 21 | void TestFileUtil::changeAccessPermission(const Poco::Path& absolutePath, unsigned int mode) 22 | { 23 | TestFileUtilImpl::changeAccessPermission( 24 | FileUtil::convertToAbsolutePathString(absolutePath.toString(), true), mode); 25 | } 26 | 27 | void TestFileUtil::setReadOnly(const Poco::Path& path) 28 | { 29 | changeAccessPermission(path.absolute(), EASYHTTPCPP_FILE_PERMISSION_ALLUSER_READ_ONLY); 30 | } 31 | 32 | void TestFileUtil::setFullAccess(const Poco::Path& path) 33 | { 34 | changeAccessPermission(path.absolute(), EASYHTTPCPP_FILE_PERMISSION_FULL_ACCESS); 35 | } 36 | 37 | void TestFileUtil::appendLongPathDir(Poco::Path& path) 38 | { 39 | // path///// 40 | path.append(Poco::Path(TestConstants::LongDirName64byte)); 41 | path.append(Poco::Path(TestConstants::LongDirName64byte)); 42 | path.append(Poco::Path(TestConstants::LongDirName64byte)); 43 | path.append(Poco::Path(TestConstants::LongDirName64byte)); 44 | } 45 | 46 | } /* namespace testutil */ 47 | } /* namespace easyhttpcpp */ 48 | -------------------------------------------------------------------------------- /tests/testutil/TestPreferences.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_TESTUTIL_TESTPREFERENCES_H_INCLUDED 6 | #define EASYHTTPCPP_TESTUTIL_TESTPREFERENCES_H_INCLUDED 7 | 8 | #include 9 | 10 | #include "Poco/SingletonHolder.h" 11 | #include "Poco/Path.h" 12 | #include "Poco/JSON/Object.h" 13 | 14 | #include "easyhttpcpp/Proxy.h" 15 | 16 | using easyhttpcpp::Proxy; 17 | 18 | namespace easyhttpcpp { 19 | namespace testutil { 20 | 21 | class TestPreferences { 22 | public: 23 | enum ProfileType { 24 | ProfileQA, 25 | }; 26 | 27 | static TestPreferences& getInstance(); 28 | 29 | virtual void initialize(ProfileType prefsProfile); 30 | virtual Proxy::Ptr optGetProxy(Proxy::Ptr pDefaultValue); 31 | virtual Poco::SharedPtr optGetRootCaDirPath(Poco::Path* pDefaultValue); 32 | virtual Poco::SharedPtr optGetRootCaFilePath(Poco::Path* pDefaultValue); 33 | 34 | private: 35 | TestPreferences(); 36 | virtual ~TestPreferences(); 37 | 38 | bool m_initialized; 39 | 40 | friend class Poco::SingletonHolder; 41 | }; 42 | 43 | } /* namespace testutil */ 44 | } /* namespace easyhttpcpp */ 45 | 46 | #endif /* EASYHTTPCPP_TESTUTIL_TESTPREFERENCES_H_INCLUDED */ 47 | -------------------------------------------------------------------------------- /tests/testutil/TestServer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_TESTUTIL_TESTSERVER_H_INCLUDED 6 | #define EASYHTTPCPP_TESTUTIL_TESTSERVER_H_INCLUDED 7 | 8 | #include "Poco/SharedPtr.h" 9 | #include "Poco/Net/ServerSocket.h" 10 | #include "Poco/Net/HTTPRequestHandlerFactory.h" 11 | #include "Poco/Net/HTTPServer.h" 12 | 13 | #include "HttpTestRequestHandlerFactory.h" 14 | #include "TestUtilExports.h" 15 | 16 | namespace easyhttpcpp { 17 | namespace testutil { 18 | 19 | class HttpTestRequestHandlerFactory; 20 | 21 | class EASYHTTPCPP_TESTUTIL_API TestServer { 22 | public: 23 | TestServer(); 24 | virtual ~TestServer(); 25 | void start(unsigned short port); 26 | void stop(); 27 | HttpTestRequestHandlerFactory& getTestRequestHandlerFactory(); 28 | void setKeepAlive(bool keepAlive); 29 | void setKeepAliveTimeoutSec(long keepAliveTimeoutSec); 30 | 31 | protected: 32 | virtual Poco::Net::ServerSocket* newSocket(unsigned short port) = 0; 33 | 34 | private: 35 | Poco::Net::HTTPRequestHandlerFactory::Ptr m_pRequestHandlerFactory; 36 | Poco::SharedPtr m_pSocket; 37 | Poco::SharedPtr m_pServer; 38 | bool m_keepAlive; 39 | long m_keepAliveTimeoutSec; 40 | 41 | }; 42 | 43 | } /* namespace testutil */ 44 | } /* namespace easyhttpcpp */ 45 | 46 | #endif /* EASYHTTPCPP_TESUTUTIL_TESTSERVER_H_INCLUDED */ 47 | -------------------------------------------------------------------------------- /tests/testutil/TestUtilExports.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_TESTUTIL_TESTUTILEXPORTS_H_INCLUDED 6 | #define EASYHTTPCPP_TESTUTIL_TESTUTILEXPORTS_H_INCLUDED 7 | 8 | namespace easyhttpcpp { 9 | namespace testutil { 10 | 11 | #if defined(_WIN32) && defined(EASYHTTPCPP_DLL_TESTS) 12 | #ifdef EASYHTTPCPP_TESTUTIL_API_EXPORTS 13 | #define EASYHTTPCPP_TESTUTIL_API __declspec(dllexport) 14 | #else 15 | #define EASYHTTPCPP_TESTUTIL_API __declspec(dllimport) 16 | #endif 17 | #endif 18 | 19 | #ifndef EASYHTTPCPP_TESTUTIL_API 20 | #define EASYHTTPCPP_TESTUTIL_API 21 | #endif 22 | 23 | } /* namespace testutil */ 24 | } /* namespace easyhttpcpp */ 25 | 26 | #endif /* EASYHTTPCPP_TESTUTIL_TESTUTILEXPORTS_H_INCLUDED */ 27 | 28 | -------------------------------------------------------------------------------- /tests/testutil/unix/TestFileUtilImpl.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | #include "TestFileUtil.h" 5 | #include "TestFileUtilImpl.h" 6 | 7 | namespace easyhttpcpp { 8 | namespace testutil { 9 | 10 | void TestFileUtilImpl::changeAccessPermission(const std::string& absolutePath, unsigned int mode) 11 | { 12 | chmod(absolutePath.c_str(), mode); 13 | } 14 | 15 | } /* namespace testutil */ 16 | } /* namespace easyhttpcpp */ 17 | -------------------------------------------------------------------------------- /tests/testutil/unix/TestFileUtilImpl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_TESTUTIL_TESTFILEUTILIMPL_H_INCLUDED 6 | #define EASYHTTPCPP_TESTUTIL_TESTFILEUTILIMPL_H_INCLUDED 7 | 8 | namespace easyhttpcpp { 9 | namespace testutil { 10 | 11 | class TestFileUtilImpl { 12 | public: 13 | 14 | static void changeAccessPermission(const std::string& absolutePath, unsigned int mode); 15 | 16 | }; 17 | 18 | } /* namespace testutil */ 19 | } /* namespace easyhttpcpp */ 20 | 21 | #endif /* EASYHTTPCPP_TESTUTIL_TESTFILEUTILIMPL_H_INCLUDED */ 22 | -------------------------------------------------------------------------------- /tests/testutil/windows/TestFileUtilImpl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_TESTUTIL_TESTFILEUTILIMPL_H_INCLUDED 6 | #define EASYHTTPCPP_TESTUTIL_TESTFILEUTILIMPL_H_INCLUDED 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | namespace easyhttpcpp { 14 | namespace testutil { 15 | 16 | class TestFileUtilImpl { 17 | public: 18 | 19 | static void changeAccessPermission(const std::string& absolutePath, unsigned int mode); 20 | 21 | private: 22 | static void changePermission(LPCTSTR pPath, LPCTSTR pUser, DWORD permission, ACCESS_MODE mode); 23 | static PACL addACLExplicitAccess(PACL pAclOld, EXPLICIT_ACCESS& access); 24 | static bool setDACL(LPTSTR pPath, PACL pAcl); 25 | }; 26 | 27 | } /* namespace testutil */ 28 | } /* namespace easyhttpcpp */ 29 | 30 | #endif /* EASYHTTPCPP_TESTUTIL_TESTFILEUTILIMPL_H_INCLUDED */ 31 | -------------------------------------------------------------------------------- /tests/unittests/HttpCacheUnitTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "gtest/gtest.h" 6 | 7 | #include "Poco/Path.h" 8 | 9 | #include "easyhttpcpp/HttpCache.h" 10 | 11 | namespace easyhttpcpp { 12 | namespace test { 13 | 14 | static const char* const DefaultCachePath = "./Data/HttpCache/"; 15 | 16 | class HttpCacheUnitTest : public testing::Test { 17 | }; 18 | 19 | // path, maxSize 指定 20 | TEST(HttpCacheUnitTest, create_createsHttpCacheWithPathAndMaxSize_WhenSpecifiedParameter) 21 | { 22 | // Given: specified path and maxSize 23 | Poco::Path path(DefaultCachePath); 24 | size_t maxSize = 100; 25 | 26 | // When: call createCache 27 | HttpCache::Ptr pCache = HttpCache::createCache(path, maxSize); 28 | 29 | // Then: getPath get specified absolute path and maxSize 30 | const Poco::Path& gottenPath = pCache->getPath(); 31 | EXPECT_EQ(path.toString(), gottenPath.toString()); 32 | EXPECT_EQ(maxSize, pCache->getMaxSize()); 33 | } 34 | 35 | } /* namespace test */ 36 | } /* namespace easyhttpcpp */ 37 | -------------------------------------------------------------------------------- /tests/unittests/HttpsExceptionUnitTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "gtest/gtest.h" 6 | 7 | #include "easyhttpcpp/HttpException.h" 8 | #include "ExceptionTestUtil.h" 9 | 10 | namespace easyhttpcpp { 11 | namespace test { 12 | 13 | using easyhttpcpp::common::CoreException; 14 | 15 | static const unsigned int HttpIllegalArgumentExceptedtedCode = 100700; 16 | static const unsigned int HttpIllegalStateExceptionExpectedCode = 100701; 17 | static const unsigned int HttpExecutionExceptionExpectedCode = 100702; 18 | static const unsigned int HttpTimeoutExceptionExpectedCode = 100703; 19 | static const unsigned int HttpSslExceptionExpectedCode = 100704; 20 | 21 | EASYHTTPCPP_EXCEPTION_UNIT_TEST(CoreException, HttpException, HttpIllegalArgumentException, HttpIllegalArgumentExceptedtedCode) 22 | EASYHTTPCPP_EXCEPTION_UNIT_TEST(CoreException, HttpException, HttpIllegalStateException, 23 | HttpIllegalStateExceptionExpectedCode) 24 | EASYHTTPCPP_EXCEPTION_UNIT_TEST(CoreException, HttpException, HttpExecutionException, HttpExecutionExceptionExpectedCode) 25 | EASYHTTPCPP_EXCEPTION_UNIT_TEST(CoreException, HttpException, HttpTimeoutException, HttpTimeoutExceptionExpectedCode) 26 | EASYHTTPCPP_EXCEPTION_UNIT_TEST(CoreException, HttpException, HttpSslException, HttpSslExceptionExpectedCode) 27 | 28 | } /* namespace test */ 29 | } /* namespace easyhttpcpp */ 30 | -------------------------------------------------------------------------------- /tests/unittests/MediaTypeUnitTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "gtest/gtest.h" 6 | 7 | #include "easyhttpcpp/MediaType.h" 8 | 9 | namespace easyhttpcpp { 10 | namespace test { 11 | 12 | static const std::string ContentType = "text/plain"; 13 | 14 | TEST(MediaTypeUnitTest, toString_ReturnsContentType) 15 | { 16 | // Given: none 17 | MediaType mediaType(ContentType); 18 | // When: call toString() 19 | // Then: returns Content-Type 20 | EXPECT_EQ(ContentType, mediaType.toString()); 21 | } 22 | 23 | } /* namespace test */ 24 | } /* namespace easyhttpcpp */ 25 | 26 | -------------------------------------------------------------------------------- /tests/unittests/MockConnectionPoolInternal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_TEST_UNITTEST_MOCKCONNECTIONPOOLINTERNAL_H_INCLUDED 6 | #define EASYHTTPCPP_TEST_UNITTEST_MOCKCONNECTIONPOOLINTERNAL_H_INCLUDED 7 | 8 | #include "gtest/gtest.h" 9 | #include "gmock/gmock.h" 10 | 11 | #include "ConnectionPoolInternal.h" 12 | 13 | namespace easyhttpcpp { 14 | namespace test { 15 | 16 | class MockConnectionPoolInternal : public ConnectionPoolInternal { 17 | public: 18 | MockConnectionPoolInternal(unsigned int keepAliveIdleCountMax, unsigned long keepAliveTimeoutSec) : 19 | ConnectionPoolInternal(keepAliveIdleCountMax, keepAliveTimeoutSec) 20 | { 21 | } 22 | 23 | MOCK_CONST_METHOD0(getKeepAliveIdleCountMax, unsigned int()); 24 | MOCK_CONST_METHOD0(getKeepAliveTimeoutSec, unsigned long()); 25 | MOCK_METHOD0(getKeepAliveIdleConnectionCount, unsigned int()); 26 | MOCK_METHOD0(getTotalConnectionCount, unsigned int()); 27 | 28 | MOCK_METHOD3(getConnection, ConnectionInternal::Ptr(Request::Ptr pRequest, EasyHttpContext::Ptr pContext, 29 | bool& connectionReused)); 30 | MOCK_METHOD2(createConnection, ConnectionInternal::Ptr(Request::Ptr pRequest, EasyHttpContext::Ptr pContext)); 31 | MOCK_METHOD1(removeConnection, bool(ConnectionInternal::Ptr pConnectionInternal)); 32 | MOCK_METHOD1(releaseConnection, bool(ConnectionInternal::Ptr pConnectionInternal)); 33 | }; 34 | 35 | } /* namespace test */ 36 | } /* namespace easyhttpcpp */ 37 | 38 | #endif /* EASYHTTPCPP_TEST_UNITTEST_MOCKCONNECTIONPOOLINTERNAL_H_INCLUDED */ 39 | -------------------------------------------------------------------------------- /tests/unittests/MockConnectionStatusListener.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_TEST_UNITTEST_MOCKCONNECTIONSTATUSLISTENER_H_INCLUDED 6 | #define EASYHTTPCPP_TEST_UNITTEST_MOCKCONNECTIONSTATUSLISTENER_H_INCLUDED 7 | 8 | #include "gtest/gtest.h" 9 | #include "gmock/gmock.h" 10 | 11 | #include "ConnectionStatusListener.h" 12 | 13 | namespace easyhttpcpp { 14 | namespace test { 15 | 16 | class MockConnectionStatusListener : public ConnectionStatusListener { 17 | public: 18 | MOCK_METHOD2(onIdle, void(ConnectionInternal* pConnectionInternal, bool& listenerInvalidated)); 19 | }; 20 | 21 | } /* namespace test */ 22 | } /* namespace easyhttpcpp */ 23 | 24 | #endif /* EASYHTTPCPP_TEST_UNITTEST_MOCKCONNECTIONSTATUSLISTENER_H_INCLUDED */ 25 | -------------------------------------------------------------------------------- /tests/unittests/MockKeepAliveTimeoutListener.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #ifndef EASYHTTPCPP_TEST_UNITTEST_MOCKKEEPALIVETIMEOUTLISTENER_H_INCLUDED 6 | #define EASYHTTPCPP_TEST_UNITTEST_MOCKKEEPALIVETIMEOUTLISTENER_H_INCLUDED 7 | 8 | #include "gtest/gtest.h" 9 | #include "gmock/gmock.h" 10 | 11 | #include "KeepAliveTimeoutListener.h" 12 | 13 | namespace easyhttpcpp { 14 | namespace test { 15 | 16 | class MockKeepAliveTimeoutListener : public KeepAliveTimeoutListener { 17 | public: 18 | MOCK_METHOD1(onKeepAliveTimeoutExpired, void(const KeepAliveTimeoutTask* pKeepAliveTimeoutTask)); 19 | }; 20 | 21 | 22 | } /* namespace test */ 23 | } /* namespace easyhttpcpp */ 24 | 25 | #endif /* EASYHTTPCPP_TEST_UNITTEST_MOCKKEEPALIVETIMEOUTLISTENER_H_INCLUDED */ 26 | -------------------------------------------------------------------------------- /tests/unittests/common/CommonExceptionUnitTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "gtest/gtest.h" 6 | 7 | #include "easyhttpcpp/common/CommonException.h" 8 | #include "ExceptionTestUtil.h" 9 | 10 | namespace easyhttpcpp { 11 | namespace common { 12 | namespace test { 13 | 14 | EASYHTTPCPP_EXCEPTION_UNIT_TEST(CoreException, CommonException, PocoException, 100000); 15 | EASYHTTPCPP_EXCEPTION_UNIT_TEST(CoreException, CommonException, StdException, 100001); 16 | EASYHTTPCPP_EXCEPTION_UNIT_TEST(CoreException, CommonException, FutureIllegalStateException, 100002); 17 | EASYHTTPCPP_EXCEPTION_UNIT_TEST(CoreException, CommonException, FutureCancellationException, 100003); 18 | EASYHTTPCPP_EXCEPTION_UNIT_TEST(CoreException, CommonException, FutureExecutionException, 100004); 19 | EASYHTTPCPP_EXCEPTION_UNIT_TEST(CoreException, CommonException, FutureTimeoutException, 100005); 20 | 21 | } /* namespace test */ 22 | } /* namespace common */ 23 | } /* namespace easyhttpcpp */ 24 | -------------------------------------------------------------------------------- /tests/unittests/db/SqlExceptionUnitTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "gtest/gtest.h" 6 | 7 | #include "easyhttpcpp/db/SqlException.h" 8 | #include "ExceptionTestUtil.h" 9 | 10 | namespace easyhttpcpp { 11 | namespace db { 12 | namespace test { 13 | 14 | using easyhttpcpp::common::CoreException; 15 | 16 | static const unsigned int SqlIllegalArgumentExceptionExpectedCode = 100200; 17 | static const unsigned int SqlIllegalStateExceptionExpectedCode = 100201; 18 | static const unsigned int SqlExecutionExceptionExpectedCode = 100202; 19 | static const unsigned int SqlDatabaseCorruptExceptionExpectedCode = 100203; 20 | 21 | EASYHTTPCPP_EXCEPTION_UNIT_TEST(CoreException, SqlException, SqlExecutionException, SqlExecutionExceptionExpectedCode) 22 | EASYHTTPCPP_EXCEPTION_UNIT_TEST(CoreException, SqlException, SqlIllegalArgumentException, 23 | SqlIllegalArgumentExceptionExpectedCode) 24 | EASYHTTPCPP_EXCEPTION_UNIT_TEST(CoreException, SqlException, SqlIllegalStateException, SqlIllegalStateExceptionExpectedCode) 25 | EASYHTTPCPP_EXCEPTION_UNIT_TEST(CoreException, SqlException, SqlDatabaseCorruptException, 26 | SqlDatabaseCorruptExceptionExpectedCode) 27 | 28 | } /* namespace test */ 29 | } /* namespace db */ 30 | } /* namespace easyhttpcpp */ 31 | -------------------------------------------------------------------------------- /tests/unittests/messagedigest/MessageDigestExceptionUnitTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Sony Corporation 3 | */ 4 | 5 | #include "gtest/gtest.h" 6 | 7 | #include "easyhttpcpp/messagedigest/MessageDigestException.h" 8 | #include "ExceptionTestUtil.h" 9 | 10 | using easyhttpcpp::common::CoreException; 11 | 12 | namespace easyhttpcpp { 13 | namespace messagedigest { 14 | namespace test { 15 | 16 | namespace { 17 | static const unsigned int MessageDigestIllegalArgumentExceptionExpectedCode = 100300; 18 | static const unsigned int MessageDigestIllegalStateExceptionExpectedCode = 100301; 19 | static const unsigned int MessageDigestExecutionExceptionExpectedCode = 100302; 20 | } 21 | 22 | EASYHTTPCPP_EXCEPTION_UNIT_TEST(CoreException, MessageDigestException, MessageDigestIllegalArgumentException, MessageDigestIllegalArgumentExceptionExpectedCode) 23 | 24 | EASYHTTPCPP_EXCEPTION_UNIT_TEST(CoreException, MessageDigestException, MessageDigestIllegalStateException, MessageDigestIllegalStateExceptionExpectedCode) 25 | 26 | EASYHTTPCPP_EXCEPTION_UNIT_TEST(CoreException, MessageDigestException, MessageDigestExecutionException, MessageDigestExecutionExceptionExpectedCode) 27 | 28 | } /* namespace test */ 29 | } /* namespace messagedigest */ 30 | } /* namespace easyhttpcpp */ 31 | --------------------------------------------------------------------------------