├── .appveyor.yml ├── .gitignore ├── .gitmodules ├── .travis.yml ├── LICENSE.md ├── README.md ├── addon_config.mk ├── docs └── Doxyfile ├── example_advanced_client_get ├── addons.make ├── bin │ └── data │ │ └── ssl │ │ └── cacert.pem └── src │ ├── main.cpp │ ├── ofApp.cpp │ └── ofApp.h ├── example_basic_client_post ├── addons.make ├── bin │ └── data │ │ ├── .gitkeep │ │ ├── pixel.gif │ │ └── ssl │ │ └── cacert.pem └── src │ ├── main.cpp │ ├── ofApp.cpp │ └── ofApp.h ├── example_basic_client_post_json ├── addons.make ├── bin │ └── data │ │ ├── .gitkeep │ │ └── ssl │ │ └── cacert.pem └── src │ ├── main.cpp │ ├── ofApp.cpp │ └── ofApp.h ├── example_basic_server_file ├── addons.make ├── bin │ └── data │ │ └── DocumentRoot │ │ ├── 404.html │ │ ├── css │ │ ├── bootstrap-theme.css │ │ ├── bootstrap-theme.min.css │ │ ├── bootstrap.css │ │ ├── bootstrap.min.css │ │ └── style.css │ │ ├── fonts │ │ ├── glyphicons-halflings-regular.eot │ │ ├── glyphicons-halflings-regular.svg │ │ ├── glyphicons-halflings-regular.ttf │ │ └── glyphicons-halflings-regular.woff │ │ ├── img │ │ ├── favicon.ico │ │ └── openFrameworks.png │ │ ├── index.html │ │ └── js │ │ ├── bootstrap.js │ │ ├── bootstrap.min.js │ │ ├── jquery.min.js │ │ └── jquery.min.map └── src │ ├── main.cpp │ ├── ofApp.cpp │ └── ofApp.h ├── example_basic_server_file_headless ├── addons.make ├── bin │ └── data │ │ └── DocumentRoot │ │ ├── 404.html │ │ ├── css │ │ ├── bootstrap-theme.css │ │ ├── bootstrap-theme.min.css │ │ ├── bootstrap.css │ │ ├── bootstrap.min.css │ │ └── style.css │ │ ├── fonts │ │ ├── glyphicons-halflings-regular.eot │ │ ├── glyphicons-halflings-regular.svg │ │ ├── glyphicons-halflings-regular.ttf │ │ └── glyphicons-halflings-regular.woff │ │ ├── img │ │ ├── favicon.ico │ │ └── openFrameworks.png │ │ ├── index.html │ │ └── js │ │ ├── bootstrap.js │ │ ├── bootstrap.min.js │ │ ├── jquery.min.js │ │ └── jquery.min.map └── src │ ├── main.cpp │ ├── ofApp.cpp │ └── ofApp.h ├── example_basic_server_mjpeg_video ├── addons.make ├── bin │ └── data │ │ ├── DocumentRoot │ │ ├── 404.html │ │ ├── css │ │ │ ├── bootstrap-theme.css │ │ │ ├── bootstrap-theme.min.css │ │ │ ├── bootstrap.css │ │ │ ├── bootstrap.min.css │ │ │ └── style.css │ │ ├── fonts │ │ │ ├── glyphicons-halflings-regular.eot │ │ │ ├── glyphicons-halflings-regular.svg │ │ │ ├── glyphicons-halflings-regular.ttf │ │ │ └── glyphicons-halflings-regular.woff │ │ ├── img │ │ │ ├── favicon.ico │ │ │ └── openFrameworks.png │ │ ├── index.html │ │ └── js │ │ │ ├── bootstrap.js │ │ │ ├── bootstrap.min.js │ │ │ ├── jquery.min.js │ │ │ └── jquery.min.map │ │ └── fingers.mp4 └── src │ ├── main.cpp │ ├── ofApp.cpp │ └── ofApp.h ├── example_basic_server_post ├── addons.make ├── bin │ └── data │ │ ├── DocumentRoot │ │ ├── 404.html │ │ ├── css │ │ │ ├── bootstrap-theme.css │ │ │ ├── bootstrap-theme.min.css │ │ │ ├── bootstrap.css │ │ │ ├── bootstrap.min.css │ │ │ └── style.css │ │ ├── fonts │ │ │ ├── glyphicons-halflings-regular.eot │ │ │ ├── glyphicons-halflings-regular.svg │ │ │ ├── glyphicons-halflings-regular.ttf │ │ │ └── glyphicons-halflings-regular.woff │ │ ├── img │ │ │ ├── favicon.ico │ │ │ └── openFrameworks.png │ │ ├── index.html │ │ ├── js │ │ │ ├── bootstrap.js │ │ │ ├── bootstrap.min.js │ │ │ ├── jquery.min.js │ │ │ └── jquery.min.map │ │ └── uploaded.html │ │ └── uploads │ │ └── .gitkeep └── src │ ├── main.cpp │ ├── ofApp.cpp │ └── ofApp.h ├── example_basic_server_sent_events ├── addons.make ├── bin │ └── data │ │ └── DocumentRoot │ │ ├── 404.html │ │ ├── css │ │ ├── bootstrap-theme.css │ │ ├── bootstrap-theme.min.css │ │ ├── bootstrap.css │ │ ├── bootstrap.min.css │ │ └── style.css │ │ ├── fonts │ │ ├── glyphicons-halflings-regular.eot │ │ ├── glyphicons-halflings-regular.svg │ │ ├── glyphicons-halflings-regular.ttf │ │ └── glyphicons-halflings-regular.woff │ │ ├── img │ │ ├── favicon.ico │ │ └── openFrameworks.png │ │ ├── index.html │ │ └── js │ │ ├── bootstrap.js │ │ ├── bootstrap.min.js │ │ ├── jquery.min.js │ │ ├── jquery.min.map │ │ └── main.js └── src │ ├── main.cpp │ ├── ofApp.cpp │ └── ofApp.h ├── libs └── ofxHTTP │ ├── include │ └── ofx │ │ └── HTTP │ │ ├── AbstractClientTypes.h │ │ ├── AbstractServerTypes.h │ │ ├── AuthScope.h │ │ ├── Authentication.h │ │ ├── BaseClient.h │ │ ├── BaseRoute.h │ │ ├── BaseServer.h │ │ ├── Client.h │ │ ├── ClientCache.h │ │ ├── ClientEvents.h │ │ ├── ClientProgressStream.h │ │ ├── ClientSessionProvider.h │ │ ├── ClientSessionSettings.h │ │ ├── ClientState.h │ │ ├── Context.h │ │ ├── Cookie.h │ │ ├── CookieStore.h │ │ ├── CookieUtils.h │ │ ├── CredentialStore.h │ │ ├── Credentials.h │ │ ├── DefaultClientHeaders.h │ │ ├── DefaultCookieProcessor.h │ │ ├── DefaultEncodingResponseStreamFilter.h │ │ ├── DefaultProxyProcessor.h │ │ ├── DefaultRedirectProcessor.h │ │ ├── FileSystemRoute.h │ │ ├── FormRequest.h │ │ ├── GetRequest.h │ │ ├── GetRequestTask.h │ │ ├── HTTP.h │ │ ├── HTTPClient.h │ │ ├── HTTPHost.h │ │ ├── HTTPUtils.h │ │ ├── HeadRequest.h │ │ ├── IPVideoFrame.h │ │ ├── IPVideoRoute.h │ │ ├── JSONRequest.h │ │ ├── JSONResponse.h │ │ ├── JSONWebToken.h │ │ ├── OAuth10Credentials.h │ │ ├── OAuth10HTTPClient.h │ │ ├── OAuth10RequestFilter.h │ │ ├── OAuth20Credentials.h │ │ ├── OAuth20HTTPClient.h │ │ ├── OAuth20RequestFilter.h │ │ ├── PostRequest.h │ │ ├── PostRoute.h │ │ ├── PostRouteEvents.h │ │ ├── Progress.h │ │ ├── ProxySettings.h │ │ ├── PutRequest.h │ │ ├── Request.h │ │ ├── RequestHandlerAdapter.h │ │ ├── Response.h │ │ ├── SSEConnection.h │ │ ├── SSEEvents.h │ │ ├── SSEFrame.h │ │ ├── SSERoute.h │ │ ├── ServerEvents.h │ │ ├── Session.h │ │ ├── SessionStore.h │ │ ├── SimpleClient.h │ │ ├── SimpleFileServer.h │ │ ├── SimpleIPVideoServer.h │ │ ├── SimplePostServer.h │ │ ├── SimpleSSEServer.h │ │ ├── SimpleWebSocketServer.h │ │ ├── ThreadErrorHandler.h │ │ ├── ThreadSettings.h │ │ ├── URIBuilder.h │ │ ├── WebSocketConnection.h │ │ ├── WebSocketEvents.h │ │ ├── WebSocketExtensions.h │ │ ├── WebSocketFrame.h │ │ └── WebSocketRoute.h │ └── src │ ├── AuthScope.cpp │ ├── BaseClient.cpp │ ├── BaseRoute.cpp │ ├── BaseServer.cpp │ ├── Client.cpp │ ├── ClientCache.cpp │ ├── ClientEvents.cpp │ ├── ClientProgressStream.cpp │ ├── ClientSessionProvider.cpp │ ├── ClientSessionSettings.cpp │ ├── ClientState.cpp │ ├── Context.cpp │ ├── Cookie.cpp │ ├── CookieStore.cpp │ ├── CookieUtils.cpp │ ├── CredentialStore.cpp │ ├── Credentials.cpp │ ├── DefaultClientHeaders.cpp │ ├── DefaultCookieProcessor.cpp │ ├── DefaultEncodingResponseStreamFilter.cpp │ ├── DefaultProxyProcessor.cpp │ ├── DefaultRedirectProcessor.cpp │ ├── FileSystemRoute.cpp │ ├── FormRequest.cpp │ ├── GetRequest.cpp │ ├── GetRequestTask.cpp │ ├── HTTPClient.cpp │ ├── HTTPHost.cpp │ ├── HTTPUtils.cpp │ ├── HeadRequest.cpp │ ├── IPVideoFrame.cpp │ ├── IPVideoRoute.cpp │ ├── JSONRequest.cpp │ ├── JSONWebToken.cpp │ ├── OAuth10Credentials.cpp │ ├── OAuth10HTTPClient.cpp │ ├── OAuth10RequestFilter.cpp │ ├── OAuth20Credentials.cpp │ ├── OAuth20HTTPClient.cpp │ ├── OAuth20RequestFilter.cpp │ ├── PostRequest.cpp │ ├── PostRoute.cpp │ ├── PostRouteEvents.cpp │ ├── Progress.cpp │ ├── ProxySettings.cpp │ ├── PutRequest.cpp │ ├── Request.cpp │ ├── RequestHandlerAdapter.cpp │ ├── Response.cpp │ ├── SSEConnection.cpp │ ├── SSEFrame.cpp │ ├── SSERoute.cpp │ ├── Session.cpp │ ├── SessionStore.cpp │ ├── SimpleClient.cpp │ ├── SimpleFileServer.cpp │ ├── SimpleIPVideoServer.cpp │ ├── SimplePostServer.cpp │ ├── SimpleSSEServer.cpp │ ├── SimpleWebSocketServer.cpp │ ├── ThreadSettings.cpp │ ├── URIBuilder.cpp │ ├── WebSocketConnection.cpp │ ├── WebSocketExtensions.cpp │ ├── WebSocketFrame.cpp │ └── WebSocketRoute.cpp ├── scripts └── ci │ └── install.sh ├── src └── ofxHTTP.h └── tests └── client └── synchronous ├── addons.make ├── bin └── data │ ├── pixel.gif │ └── ssl │ └── cacert.pem └── src └── main.cpp /.appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 1.0.{build} 2 | os: Visual Studio 2015 RC 3 | 4 | environment: 5 | global: 6 | APPVEYOR_OS_NAME: windows 7 | matrix: 8 | #MSYS2 Building 9 | - platform: x86 10 | BUILDER: MSYS2 11 | 12 | #VisualStudio Building 13 | - platform: x86 14 | BUILDER : VS 15 | BITS: 32 16 | - platform: x64 17 | BUILDER : VS 18 | BITS: 64 19 | 20 | configuration: Debug 21 | shallow_clone: true 22 | clone_depth: 10 23 | init: 24 | - set MAKEFLAGS=-s 25 | - set MSYS2_PATH=c:\msys64 26 | - set CHERE_INVOKING=1 27 | - if "%BUILDER%_%PLATFORM%"=="MSYS2_x86" set MSYSTEM=MINGW32 28 | - if "%BUILDER%_%PLATFORM%"=="MSYS2_x64" set MSYSTEM=MINGW64 29 | - if "%BUILDER%"=="VS" set PATH=C:\Program Files (x86)\MSBuild\14.0\Bin;%PATH% 30 | - cd %APPVEYOR_BUILD_FOLDER%\..\ 31 | - set OF_ROOT=%CD%\openFrameworks 32 | - set OF_ADDON_NAME=%APPVEYOR_PROJECT_NAME% 33 | install: 34 | - git clone --depth=1 --branch=CI-TESTS https://github.com/bakercp/openFrameworks %OF_ROOT% 35 | - cd %OF_ROOT% 36 | - call scripts\ci\addons\install.cmd 37 | build_script: 38 | - cd %OF_ROOT% 39 | - call scripts\ci\addons\build.cmd 40 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # A .gitignore for openFrameworks addons. 2 | 3 | ################################################################################ 4 | # Documentation 5 | ################################################################################ 6 | 7 | # Doxygen-Related 8 | docs/html/* 9 | docs/* 10 | !docs/Doxyfile 11 | 12 | # Instructions and other documentation files. 13 | !docs/*.md 14 | !docs/*.txt 15 | 16 | ################################################################################ 17 | # Examples 18 | ################################################################################ 19 | 20 | # bin/data Folder 21 | example*/bin/data/* 22 | !example*/bin/data/data.txt 23 | 24 | # Project files 25 | example*/* 26 | !example*/src/ 27 | !example*/addons.make 28 | 29 | ################################################################################ 30 | # Libraries 31 | ################################################################################ 32 | 33 | # Exclude 3rd party libs by default. 34 | libs/* 35 | 36 | # Don't exclude ofx libs by default. 37 | !libs/ofx* 38 | 39 | ################################################################################ 40 | # Shared Data 41 | ################################################################################ 42 | 43 | shared/data/* 44 | !shared/data/*.sh 45 | 46 | ################################################################################ 47 | # Scripts 48 | ################################################################################ 49 | 50 | # Everything included by default. 51 | 52 | ################################################################################ 53 | # Build Artifacts 54 | ################################################################################ 55 | 56 | # Default Qt Creator Build Folders 57 | build-example*/ 58 | 59 | ################################################################################ 60 | # Utility Stuff 61 | ################################################################################ 62 | 63 | # Local folders, use for temporary storage, etc. 64 | __*/* 65 | 66 | # Temporary files. 67 | *.autosave 68 | 69 | # OSX 70 | .DS_Store 71 | .AppleDouble 72 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "scripts/ofx"] 2 | path = scripts/ofx 3 | url = https://github.com/bakercp/ofx.git 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c++ 2 | compiler: gcc 3 | sudo: true 4 | matrix: 5 | include: 6 | # fully specify builds, include can't dynamically expand matrix entries 7 | # relative order of sudo and env is important so that addons: is recognized 8 | 9 | # Linux 64bit, OF master 10 | - os: linux 11 | dist: trusty 12 | sudo: required 13 | env: TARGET="linux64" OF_BRANCH="master" 14 | addons: 15 | apt: 16 | sources: 17 | - ubuntu-toolchain-r-test 18 | packages: 19 | - gcc-4.9 20 | - g++-4.9 21 | - gdb 22 | 23 | # OSX, OF master 24 | - os: osx 25 | osx_image: xcode9 26 | compiler: clang 27 | env: TARGET="osx" OF_BRANCH="master" 28 | 29 | # Exclude the default build that would otherwise be generated 30 | # see https://github.com/travis-ci/travis-ci/issues/1228 31 | exclude: 32 | - compiler: gcc 33 | before_install: 34 | - curl -SLsO https://raw.githubusercontent.com/bakercp/ofxAddonScripts/${OF_BRANCH}/scripts/ci/tools/install.sh 35 | - source install.sh 36 | install: 37 | - do_install 38 | script: 39 | - do_script 40 | 41 | git: 42 | depth: 10 43 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Christopher Baker 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 | -------------------------------------------------------------------------------- /addon_config.mk: -------------------------------------------------------------------------------- 1 | meta: 2 | ADDON_NAME = ofxHTTP 3 | ADDON_DESCRIPTION = An HTTP addon for custom HTTP clients and servers. 4 | ADDON_AUTHOR = bakercp 5 | ADDON_TAGS = "http" "web" "client" "server" "oauth" "rest" 6 | ADDON_URL = http://github.com/bakercp/ofxHTTP 7 | 8 | common: 9 | ADDON_DEPENDENCIES = ofxPoco ofxSSLManager ofxIO ofxMediaType ofxNetworkUtils 10 | -------------------------------------------------------------------------------- /example_advanced_client_get/addons.make: -------------------------------------------------------------------------------- 1 | ofxHTTP 2 | ofxIO 3 | ofxMediaType 4 | ofxNetworkUtils 5 | ofxPoco 6 | ofxSSLManager 7 | -------------------------------------------------------------------------------- /example_advanced_client_get/src/main.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofApp.h" 9 | 10 | 11 | int main() 12 | { 13 | ofSetupOpenGL(250, 50, OF_WINDOW); 14 | return ofRunApp(std::make_shared()); 15 | } 16 | -------------------------------------------------------------------------------- /example_advanced_client_get/src/ofApp.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofApp.h" 9 | 10 | 11 | void ofApp::setup() 12 | { 13 | // Testing redirects and https. 14 | // This server will echo back everything that you send to it. 15 | std::string url = "https://httpbin.org/get"; 16 | 17 | // Create a client. 18 | ofxHTTP::Client client; 19 | 20 | // Create a request. 21 | ofxHTTP::GetRequest request(url); 22 | 23 | // Create a context. 24 | ofxHTTP::Context context; 25 | 26 | // Set custom session settings. 27 | // 28 | // See the class documentation for many additional settings. 29 | ofxHTTP::ClientSessionSettings sessionSettings; 30 | 31 | // Use an iPhone X user agent string. 32 | sessionSettings.setUserAgent("Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1"); 33 | 34 | // Set a 60 second keep-alive timeout (default is 8 seconds). 35 | sessionSettings.setKeepAliveTimeout(Poco::Timespan::SECONDS * 60); 36 | 37 | // Save the session settings with the context. 38 | context.setClientSessionSettings(sessionSettings); 39 | 40 | // Do the query! 41 | try 42 | { 43 | // Execute the request within the given context. 44 | auto response = client.execute(context, request); 45 | 46 | // Check the response. 47 | if (response->getStatus() == Poco::Net::HTTPResponse::HTTP_OK) 48 | { 49 | // A successful response. 50 | ofLogNotice("ofApp::setup") << "Response success, expecting " << response->estimatedContentLength() << " bytes."; 51 | 52 | // Buffer the response, or otherwise consume the stream. 53 | ofBuffer buffer(response->stream()); 54 | 55 | ofLogNotice("ofApp::setup") << "Content Begin"; 56 | 57 | std::cout << buffer << std::endl; 58 | 59 | ofLogNotice("ofApp::setup") << "Content End"; 60 | } 61 | else 62 | { 63 | ofLogError("ofApp::setup") << response->getStatus() << " " << response->getReason(); 64 | } 65 | } 66 | catch (const Poco::Exception& exc) 67 | { 68 | ofLogError("ofApp::setup") << exc.displayText(); 69 | } 70 | catch (const std::exception& exc) 71 | { 72 | ofLogError("ofApp::setup") << exc.what(); 73 | } 74 | } 75 | 76 | 77 | void ofApp::draw() 78 | { 79 | ofBackgroundGradient(ofColor::white, ofColor::black); 80 | 81 | ofDrawBitmapStringHighlight("See console for output.", ofPoint(30, 30)); 82 | } 83 | -------------------------------------------------------------------------------- /example_advanced_client_get/src/ofApp.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "ofMain.h" 12 | #include "ofxHTTP.h" 13 | 14 | 15 | class ofApp: public ofBaseApp 16 | { 17 | public: 18 | void setup() override; 19 | void draw() override; 20 | 21 | }; 22 | -------------------------------------------------------------------------------- /example_basic_client_post/addons.make: -------------------------------------------------------------------------------- 1 | ofxHTTP 2 | ofxIO 3 | ofxMediaType 4 | ofxNetworkUtils 5 | ofxPoco 6 | ofxSSLManager 7 | -------------------------------------------------------------------------------- /example_basic_client_post/bin/data/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakercp/ofxHTTP/fa65775e68a0ef8885a257a5ea055993342721a9/example_basic_client_post/bin/data/.gitkeep -------------------------------------------------------------------------------- /example_basic_client_post/bin/data/pixel.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakercp/ofxHTTP/fa65775e68a0ef8885a257a5ea055993342721a9/example_basic_client_post/bin/data/pixel.gif -------------------------------------------------------------------------------- /example_basic_client_post/src/main.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofApp.h" 9 | 10 | 11 | int main() 12 | { 13 | ofSetupOpenGL(250, 50, OF_WINDOW); 14 | return ofRunApp(std::make_shared()); 15 | } 16 | -------------------------------------------------------------------------------- /example_basic_client_post/src/ofApp.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofApp.h" 9 | 10 | 11 | void ofApp::setup() 12 | { 13 | // Testing redirects and https. 14 | // This server will echo back everything that you send to it. 15 | std::string uri = "https://httpbin.org/post"; 16 | 17 | // Here we prepare form fields for the post request. 18 | // This can be any set of key / value text pairs. 19 | // We include simple 20 | std::multimap formFields = 21 | { 22 | { "test_0", "123" }, 23 | { "test_1", "321" }, 24 | { "base_64_encoded_image", ofxIO::Base64Encoding::encode(ofBufferFromFile("pixel.gif")) } 25 | }; 26 | 27 | // Here we prepare a multi-part file upload. 28 | std::vector formFiles = { 29 | ofxHTTP::FormPart(ofxHTTP::FormPart::Type::FILE, 30 | "one_pixel_file", 31 | "pixel.gif") 32 | }; 33 | 34 | // Create a client. 35 | ofxHTTP::Client client; 36 | 37 | // Create a request. 38 | ofxHTTP::PostRequest request(uri); 39 | 40 | // Set the POST request data. 41 | // Add the form fields. 42 | request.addFormFields(formFields); 43 | // Add the file fields. 44 | request.addFormParts(formFiles); 45 | 46 | try 47 | { 48 | // Execute the request. 49 | auto response = client.execute(request); 50 | 51 | // Check the response. 52 | if (response->getStatus() == Poco::Net::HTTPResponse::HTTP_OK) 53 | { 54 | // A successful response. 55 | ofLogNotice("ofApp::setup") << "Response success, expecting " << response->estimatedContentLength() << " bytes."; 56 | 57 | // We expect JSON in response, so we don't bother checking and 58 | // just read the response directly into an ofJson object. 59 | // 60 | // We can also get the response as a ofBuffer (response->buffer()), 61 | // ofXml, ofPixels, etc and can check to see the response type with 62 | // the response->isXXX() methods. 63 | 64 | ofJson responseJson = response->json(); 65 | 66 | ofLogNotice("ofApp::setup") << "Content Begin"; 67 | 68 | std::cout << responseJson.dump(4) << std::endl; 69 | 70 | ofLogNotice("ofApp::setup") << "Content End"; 71 | 72 | // Here we get our echoed BASE64 encoded image and save it back to 73 | // the disk after decoding it. 74 | ofxIO::ByteBuffer encodedBuffer(responseJson["form"].value("base_64_encoded_image", "")); 75 | ofxIO::ByteBuffer decodedBuffer; 76 | ofxIO::Base64Encoding encoding; 77 | encoding.decode(encodedBuffer, decodedBuffer); 78 | 79 | // Now save the buffer back to disk. 80 | ofxIO::ByteBufferUtils::saveToFile(decodedBuffer, "decoded_pixel.gif"); 81 | 82 | 83 | } 84 | else 85 | { 86 | ofLogError("ofApp::setup") << response->getStatus() << " " << response->getReason(); 87 | } 88 | } 89 | catch (const Poco::Exception& exc) 90 | { 91 | ofLogError("ofApp::setup") << exc.displayText(); 92 | } 93 | catch (const std::exception& exc) 94 | { 95 | ofLogError("ofApp::setup") << exc.what(); 96 | } 97 | } 98 | 99 | 100 | void ofApp::draw() 101 | { 102 | ofBackgroundGradient(ofColor::white, ofColor::black); 103 | 104 | ofDrawBitmapStringHighlight("See console for output.", ofPoint(30, 30)); 105 | } 106 | -------------------------------------------------------------------------------- /example_basic_client_post/src/ofApp.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "ofMain.h" 12 | #include "ofxHTTP.h" 13 | 14 | 15 | class ofApp: public ofBaseApp 16 | { 17 | public: 18 | void setup() override; 19 | void draw() override; 20 | 21 | }; 22 | -------------------------------------------------------------------------------- /example_basic_client_post_json/addons.make: -------------------------------------------------------------------------------- 1 | ofxHTTP 2 | ofxIO 3 | ofxMediaType 4 | ofxNetworkUtils 5 | ofxPoco 6 | ofxSSLManager 7 | -------------------------------------------------------------------------------- /example_basic_client_post_json/bin/data/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakercp/ofxHTTP/fa65775e68a0ef8885a257a5ea055993342721a9/example_basic_client_post_json/bin/data/.gitkeep -------------------------------------------------------------------------------- /example_basic_client_post_json/src/main.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofApp.h" 9 | 10 | 11 | int main() 12 | { 13 | ofSetupOpenGL(250, 50, OF_WINDOW); 14 | return ofRunApp(std::make_shared()); 15 | } 16 | -------------------------------------------------------------------------------- /example_basic_client_post_json/src/ofApp.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofApp.h" 9 | 10 | 11 | void ofApp::setup() 12 | { 13 | // This server will echo back everything that you send to it. 14 | std::string uri = "http://httpbin.org/post"; 15 | 16 | ofJson json = { 17 | "hello", "jello" 18 | }; 19 | 20 | // Create a client. 21 | ofxHTTP::Client client; 22 | 23 | // Create a request. 24 | ofxHTTP::JSONRequest request(uri); 25 | 26 | // Set the json request data. 27 | request.setJSON(json); 28 | 29 | try 30 | { 31 | // Execute the request. 32 | auto response = client.execute(request); 33 | 34 | // Check the response. 35 | if (response->getStatus() == Poco::Net::HTTPResponse::HTTP_OK) 36 | { 37 | // A successful response. 38 | ofLogNotice("ofApp::setup") << "Response success, expecting " << response->estimatedContentLength() << " bytes."; 39 | 40 | // Buffer the response, or otherwise consume the stream. 41 | ofJson responseJson = response->json(); 42 | 43 | ofLogNotice("ofApp::setup") << "Content Begin"; 44 | 45 | std::cout << responseJson.dump(4) << std::endl; 46 | 47 | ofLogNotice("ofApp::setup") << "Content End"; 48 | } 49 | else 50 | { 51 | ofLogError("ofApp::setup") << response->getStatus() << " " << response->getReason(); 52 | } 53 | } 54 | catch (const Poco::Exception& exc) 55 | { 56 | ofLogError("ofApp::setup") << exc.displayText(); 57 | } 58 | catch (const std::exception& exc) 59 | { 60 | ofLogError("ofApp::setup") << exc.what(); 61 | } 62 | } 63 | 64 | 65 | void ofApp::draw() 66 | { 67 | ofBackgroundGradient(ofColor::white, ofColor::black); 68 | 69 | ofDrawBitmapStringHighlight("See console for output.", ofPoint(30, 30)); 70 | } 71 | -------------------------------------------------------------------------------- /example_basic_client_post_json/src/ofApp.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "ofMain.h" 12 | #include "ofxHTTP.h" 13 | 14 | 15 | class ofApp: public ofBaseApp 16 | { 17 | public: 18 | void setup() override; 19 | void draw() override; 20 | 21 | }; 22 | -------------------------------------------------------------------------------- /example_basic_server_file/addons.make: -------------------------------------------------------------------------------- 1 | ofxHTTP 2 | ofxIO 3 | ofxMediaType 4 | ofxNetworkUtils 5 | ofxPoco 6 | ofxSSLManager 7 | ofxPoco -------------------------------------------------------------------------------- /example_basic_server_file/bin/data/DocumentRoot/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 404 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 24 |
25 |

404 - File Not Found

26 |
27 |
28 |

29 | Sorry ... your file was not found. 30 |

31 |
32 | 33 |
34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /example_basic_server_file/bin/data/DocumentRoot/css/style.css: -------------------------------------------------------------------------------- 1 | @charset "UTF-8"; 2 | /* 3 | * jQuery File Upload Plugin CSS Example 8.8.2 4 | * https://github.com/blueimp/jQuery-File-Upload 5 | * 6 | * Copyright 2013, Sebastian Tschan 7 | * https://blueimp.net 8 | * 9 | * Licensed under the MIT license: 10 | * http://www.opensource.org/licenses/MIT 11 | */ 12 | 13 | body { 14 | padding-top: 60px; 15 | } 16 | -------------------------------------------------------------------------------- /example_basic_server_file/bin/data/DocumentRoot/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakercp/ofxHTTP/fa65775e68a0ef8885a257a5ea055993342721a9/example_basic_server_file/bin/data/DocumentRoot/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /example_basic_server_file/bin/data/DocumentRoot/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakercp/ofxHTTP/fa65775e68a0ef8885a257a5ea055993342721a9/example_basic_server_file/bin/data/DocumentRoot/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /example_basic_server_file/bin/data/DocumentRoot/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakercp/ofxHTTP/fa65775e68a0ef8885a257a5ea055993342721a9/example_basic_server_file/bin/data/DocumentRoot/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /example_basic_server_file/bin/data/DocumentRoot/img/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakercp/ofxHTTP/fa65775e68a0ef8885a257a5ea055993342721a9/example_basic_server_file/bin/data/DocumentRoot/img/favicon.ico -------------------------------------------------------------------------------- /example_basic_server_file/bin/data/DocumentRoot/img/openFrameworks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakercp/ofxHTTP/fa65775e68a0ef8885a257a5ea055993342721a9/example_basic_server_file/bin/data/DocumentRoot/img/openFrameworks.png -------------------------------------------------------------------------------- /example_basic_server_file/bin/data/DocumentRoot/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | ofx::HTTP::BasicServer 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 24 |
25 |

Basic File Server Demo

26 |
27 |
28 |

29 | ofx::HTTP::BasicServer is a simple server that implements a standard file route. 30 |

31 |
32 |
33 |
34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /example_basic_server_file/src/main.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofApp.h" 9 | 10 | 11 | int main() 12 | { 13 | ofSetupOpenGL(250, 50, OF_WINDOW); 14 | return ofRunApp(std::make_shared()); 15 | } 16 | -------------------------------------------------------------------------------- /example_basic_server_file/src/ofApp.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofApp.h" 9 | 10 | 11 | void ofApp::setup() 12 | { 13 | ofSetFrameRate(30); 14 | 15 | ofxHTTP::SimpleFileServerSettings settings; 16 | 17 | // Many other settings are available. 18 | settings.setPort(7890); 19 | 20 | // Create a whitelist. 21 | // ofx::Net::IPAddressRange::List whitelist; 22 | // whitelist.push_back(ofx::Net::IPAddressRange("127.0.0.1/32")); 23 | 24 | // Set the whitelist. 25 | // settings.setWhitelist(whitelist); 26 | 27 | // Apply the settings. 28 | server.setup(settings); 29 | 30 | // Start the server. 31 | server.start(); 32 | 33 | #if !defined(TARGET_LINUX_ARM) 34 | // Launch a browser with the address of the server. 35 | ofLaunchBrowser(server.url()); 36 | #endif 37 | 38 | } 39 | 40 | 41 | void ofApp::draw() 42 | { 43 | ofBackground(255); 44 | ofDrawBitmapStringHighlight("See " + server.url(), 10, 16); 45 | } 46 | -------------------------------------------------------------------------------- /example_basic_server_file/src/ofApp.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "ofMain.h" 12 | #include "ofxHTTP.h" 13 | 14 | 15 | class ofApp: public ofBaseApp 16 | { 17 | public: 18 | void setup() override; 19 | void draw() override; 20 | 21 | ofxHTTP::SimpleFileServer server; 22 | 23 | }; 24 | -------------------------------------------------------------------------------- /example_basic_server_file_headless/addons.make: -------------------------------------------------------------------------------- 1 | ofxHTTP 2 | ofxIO 3 | ofxMediaType 4 | ofxNetworkUtils 5 | ofxPoco 6 | ofxSSLManager 7 | -------------------------------------------------------------------------------- /example_basic_server_file_headless/bin/data/DocumentRoot/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 404 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 24 |
25 |

404 - File Not Found

26 |
27 |
28 |

29 | Sorry ... your file was not found. 30 |

31 |
32 | 33 |
34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /example_basic_server_file_headless/bin/data/DocumentRoot/css/style.css: -------------------------------------------------------------------------------- 1 | @charset "UTF-8"; 2 | /* 3 | * jQuery File Upload Plugin CSS Example 8.8.2 4 | * https://github.com/blueimp/jQuery-File-Upload 5 | * 6 | * Copyright 2013, Sebastian Tschan 7 | * https://blueimp.net 8 | * 9 | * Licensed under the MIT license: 10 | * http://www.opensource.org/licenses/MIT 11 | */ 12 | 13 | body { 14 | padding-top: 60px; 15 | } 16 | -------------------------------------------------------------------------------- /example_basic_server_file_headless/bin/data/DocumentRoot/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakercp/ofxHTTP/fa65775e68a0ef8885a257a5ea055993342721a9/example_basic_server_file_headless/bin/data/DocumentRoot/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /example_basic_server_file_headless/bin/data/DocumentRoot/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakercp/ofxHTTP/fa65775e68a0ef8885a257a5ea055993342721a9/example_basic_server_file_headless/bin/data/DocumentRoot/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /example_basic_server_file_headless/bin/data/DocumentRoot/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakercp/ofxHTTP/fa65775e68a0ef8885a257a5ea055993342721a9/example_basic_server_file_headless/bin/data/DocumentRoot/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /example_basic_server_file_headless/bin/data/DocumentRoot/img/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakercp/ofxHTTP/fa65775e68a0ef8885a257a5ea055993342721a9/example_basic_server_file_headless/bin/data/DocumentRoot/img/favicon.ico -------------------------------------------------------------------------------- /example_basic_server_file_headless/bin/data/DocumentRoot/img/openFrameworks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakercp/ofxHTTP/fa65775e68a0ef8885a257a5ea055993342721a9/example_basic_server_file_headless/bin/data/DocumentRoot/img/openFrameworks.png -------------------------------------------------------------------------------- /example_basic_server_file_headless/bin/data/DocumentRoot/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | ofx::HTTP::BasicServer 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 24 |
25 |

Basic File Server Demo

26 |
27 |
28 |

29 | ofx::HTTP::BasicServer is a simple server that implements a standard file route. 30 |

31 |
32 |
33 |
34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /example_basic_server_file_headless/src/main.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofApp.h" 9 | #include "ofAppNoWindow.h" 10 | 11 | 12 | int main() 13 | { 14 | ofAppNoWindow window; 15 | ofSetupOpenGL(&window, 1, 1, OF_WINDOW); 16 | return ofRunApp(std::make_shared()); 17 | } 18 | -------------------------------------------------------------------------------- /example_basic_server_file_headless/src/ofApp.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofApp.h" 9 | 10 | void ofApp::setup() 11 | { 12 | ofxHTTP::SimpleFileServerSettings settings; 13 | 14 | // Many other settings are available. 15 | settings.setPort(7890); 16 | 17 | // Apply the settings. 18 | server.setup(settings); 19 | 20 | // Start the server. 21 | server.start(); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /example_basic_server_file_headless/src/ofApp.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "ofMain.h" 12 | #include "ofxHTTP.h" 13 | 14 | 15 | class ofApp: public ofBaseApp 16 | { 17 | public: 18 | void setup() override; 19 | 20 | // We do not have an draw() method since this is a headless display. 21 | 22 | ofxHTTP::SimpleFileServer server; 23 | 24 | }; 25 | -------------------------------------------------------------------------------- /example_basic_server_mjpeg_video/addons.make: -------------------------------------------------------------------------------- 1 | ofxHTTP 2 | ofxIO 3 | ofxMediaType 4 | ofxNetworkUtils 5 | ofxPoco 6 | ofxSSLManager 7 | -------------------------------------------------------------------------------- /example_basic_server_mjpeg_video/bin/data/DocumentRoot/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 404 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 24 |
25 |

404 - File Not Found

26 |
27 |
28 |

29 | Sorry ... your file was not found. 30 |

31 |
32 | 33 |
34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /example_basic_server_mjpeg_video/bin/data/DocumentRoot/css/style.css: -------------------------------------------------------------------------------- 1 | @charset "UTF-8"; 2 | /* 3 | * jQuery File Upload Plugin CSS Example 8.8.2 4 | * https://github.com/blueimp/jQuery-File-Upload 5 | * 6 | * Copyright 2013, Sebastian Tschan 7 | * https://blueimp.net 8 | * 9 | * Licensed under the MIT license: 10 | * http://www.opensource.org/licenses/MIT 11 | */ 12 | 13 | body { 14 | padding-top: 60px; 15 | } 16 | -------------------------------------------------------------------------------- /example_basic_server_mjpeg_video/bin/data/DocumentRoot/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakercp/ofxHTTP/fa65775e68a0ef8885a257a5ea055993342721a9/example_basic_server_mjpeg_video/bin/data/DocumentRoot/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /example_basic_server_mjpeg_video/bin/data/DocumentRoot/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakercp/ofxHTTP/fa65775e68a0ef8885a257a5ea055993342721a9/example_basic_server_mjpeg_video/bin/data/DocumentRoot/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /example_basic_server_mjpeg_video/bin/data/DocumentRoot/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakercp/ofxHTTP/fa65775e68a0ef8885a257a5ea055993342721a9/example_basic_server_mjpeg_video/bin/data/DocumentRoot/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /example_basic_server_mjpeg_video/bin/data/DocumentRoot/img/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakercp/ofxHTTP/fa65775e68a0ef8885a257a5ea055993342721a9/example_basic_server_mjpeg_video/bin/data/DocumentRoot/img/favicon.ico -------------------------------------------------------------------------------- /example_basic_server_mjpeg_video/bin/data/DocumentRoot/img/openFrameworks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakercp/ofxHTTP/fa65775e68a0ef8885a257a5ea055993342721a9/example_basic_server_mjpeg_video/bin/data/DocumentRoot/img/openFrameworks.png -------------------------------------------------------------------------------- /example_basic_server_mjpeg_video/bin/data/DocumentRoot/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | ofx::HTTP::BasicIPVideoServer 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 24 |
25 |

Basic IPVideo Server Demo

26 |
27 |
28 |

29 | ofx::HTTP::BasicIPVideoServer is a simple server for MJPEG-based IPVideo. 30 |

31 | 32 |
33 | 34 |

35 | 36 | 37 |

38 | 39 |
40 |
41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /example_basic_server_mjpeg_video/bin/data/fingers.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakercp/ofxHTTP/fa65775e68a0ef8885a257a5ea055993342721a9/example_basic_server_mjpeg_video/bin/data/fingers.mp4 -------------------------------------------------------------------------------- /example_basic_server_mjpeg_video/src/main.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofApp.h" 9 | 10 | 11 | int main() 12 | { 13 | ofSetupOpenGL(320, 240, OF_WINDOW); 14 | return ofRunApp(std::make_shared()); 15 | } 16 | -------------------------------------------------------------------------------- /example_basic_server_mjpeg_video/src/ofApp.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofApp.h" 9 | 10 | 11 | void ofApp::setup() 12 | { 13 | ofSetFrameRate(30); 14 | 15 | // Set up our video to broadcast. 16 | player.load("fingers.mp4"); 17 | player.play(); 18 | player.setLoopState(OF_LOOP_NORMAL); 19 | 20 | ofxHTTP::SimpleIPVideoServerSettings settings; 21 | 22 | // Many other settings are available. 23 | settings.setPort(7890); 24 | 25 | // The default maximum number of client connections is 5. 26 | settings.ipVideoRouteSettings.setMaxClientConnections(1); 27 | 28 | // Apply the settings. 29 | server.setup(settings); 30 | 31 | // Start the server. 32 | server.start(); 33 | 34 | #if !defined(TARGET_LINUX_ARM) 35 | // Launch a browser with the address of the server. 36 | ofLaunchBrowser(server.url()); 37 | #endif 38 | 39 | } 40 | 41 | 42 | void ofApp::update() 43 | { 44 | // Update the video player. 45 | player.update(); 46 | 47 | // If the frame is new, then send it to the server to be broadcast. 48 | if(player.isFrameNew()) 49 | { 50 | // This can be any kind of pixels. 51 | server.send(player.getPixels()); 52 | } 53 | } 54 | 55 | 56 | void ofApp::draw() 57 | { 58 | // Draw the video on the server screen. 59 | player.draw(0,0); 60 | 61 | // Display the number of connected clients for reference. 62 | std::stringstream ss; 63 | 64 | ss << "Num clients connected: "; 65 | ss << server.numConnections(); 66 | 67 | ofDrawBitmapStringHighlight(ss.str(), 20, 20); 68 | } 69 | -------------------------------------------------------------------------------- /example_basic_server_mjpeg_video/src/ofApp.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "ofMain.h" 12 | #include "ofxHTTP.h" 13 | 14 | 15 | class ofApp: public ofBaseApp 16 | { 17 | public: 18 | void setup() override; 19 | void update() override; 20 | void draw() override; 21 | 22 | ofxHTTP::SimpleIPVideoServer server; 23 | 24 | ofVideoPlayer player; 25 | 26 | }; 27 | -------------------------------------------------------------------------------- /example_basic_server_post/addons.make: -------------------------------------------------------------------------------- 1 | ofxHTTP 2 | ofxIO 3 | ofxMediaType 4 | ofxNetworkUtils 5 | ofxPoco 6 | ofxSSLManager 7 | -------------------------------------------------------------------------------- /example_basic_server_post/bin/data/DocumentRoot/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 404 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 24 |
25 |

404 - File Not Found

26 |
27 |
28 |

29 | Sorry ... your file was not found. 30 |

31 |
32 | 33 |
34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /example_basic_server_post/bin/data/DocumentRoot/css/style.css: -------------------------------------------------------------------------------- 1 | @charset "UTF-8"; 2 | /* 3 | * jQuery File Upload Plugin CSS Example 8.8.2 4 | * https://github.com/blueimp/jQuery-File-Upload 5 | * 6 | * Copyright 2013, Sebastian Tschan 7 | * https://blueimp.net 8 | * 9 | * Licensed under the MIT license: 10 | * http://www.opensource.org/licenses/MIT 11 | */ 12 | 13 | body { 14 | padding-top: 60px; 15 | } 16 | -------------------------------------------------------------------------------- /example_basic_server_post/bin/data/DocumentRoot/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakercp/ofxHTTP/fa65775e68a0ef8885a257a5ea055993342721a9/example_basic_server_post/bin/data/DocumentRoot/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /example_basic_server_post/bin/data/DocumentRoot/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakercp/ofxHTTP/fa65775e68a0ef8885a257a5ea055993342721a9/example_basic_server_post/bin/data/DocumentRoot/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /example_basic_server_post/bin/data/DocumentRoot/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakercp/ofxHTTP/fa65775e68a0ef8885a257a5ea055993342721a9/example_basic_server_post/bin/data/DocumentRoot/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /example_basic_server_post/bin/data/DocumentRoot/img/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakercp/ofxHTTP/fa65775e68a0ef8885a257a5ea055993342721a9/example_basic_server_post/bin/data/DocumentRoot/img/favicon.ico -------------------------------------------------------------------------------- /example_basic_server_post/bin/data/DocumentRoot/img/openFrameworks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakercp/ofxHTTP/fa65775e68a0ef8885a257a5ea055993342721a9/example_basic_server_post/bin/data/DocumentRoot/img/openFrameworks.png -------------------------------------------------------------------------------- /example_basic_server_post/bin/data/DocumentRoot/uploaded.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | ofx::HTTP::BasicPostServer 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 24 |
25 |

Basic Post Server Demo

26 |
27 |
28 |

29 | Success! 30 |

31 |
32 | 33 |
34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /example_basic_server_post/bin/data/uploads/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakercp/ofxHTTP/fa65775e68a0ef8885a257a5ea055993342721a9/example_basic_server_post/bin/data/uploads/.gitkeep -------------------------------------------------------------------------------- /example_basic_server_post/src/main.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofApp.h" 9 | 10 | 11 | int main() 12 | { 13 | ofSetupOpenGL(250, 50, OF_WINDOW); 14 | return ofRunApp(std::make_shared()); 15 | } 16 | -------------------------------------------------------------------------------- /example_basic_server_post/src/ofApp.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofApp.h" 9 | 10 | 11 | void ofApp::setup() 12 | { 13 | ofSetLogLevel(OF_LOG_NOTICE); 14 | 15 | ofSetFrameRate(30); 16 | 17 | ofxHTTP::SimplePostServerSettings settings; 18 | 19 | // Many other settings are available. 20 | settings.setPort(7890); 21 | 22 | // If you want to set an alternate route path pattern (defaut is /post), 23 | // you can change the POST endpoint here. Just be sure to also update it in 24 | // any HTML forms in the bin/data/DocumentRoot. 25 | // settings.postRouteSettings.setRoutePathPattern("/"); 26 | 27 | // Apply the settings. 28 | server.setup(settings); 29 | 30 | // The client can listen for POST form and multi-part upload events. 31 | // User be aware, these methods are called from other threads. 32 | // The user is responsible for protecting shared resources (e.g. ofMutex). 33 | server.postRoute().registerPostEvents(this); 34 | 35 | // Start the server. 36 | server.start(); 37 | 38 | #if !defined(TARGET_LINUX_ARM) 39 | // Launch a browser with the address of the server. 40 | ofLaunchBrowser(server.url()); 41 | #endif 42 | 43 | } 44 | 45 | 46 | void ofApp::draw() 47 | { 48 | ofBackground(255); 49 | ofDrawBitmapStringHighlight("See " + server.url(), 10, 16); 50 | ofDrawBitmapStringHighlight("See the Console", 10, 42); 51 | } 52 | 53 | 54 | void ofApp::onHTTPPostEvent(ofxHTTP::PostEventArgs& args) 55 | { 56 | ofLogNotice("ofApp::onHTTPPostEvent") << "Data: " << args.getBuffer().getText(); 57 | } 58 | 59 | 60 | void ofApp::onHTTPFormEvent(ofxHTTP::PostFormEventArgs& args) 61 | { 62 | ofLogNotice("ofApp::onHTTPFormEvent") << ""; 63 | ofxHTTP::HTTPUtils::dumpNameValueCollection(args.getForm(), ofGetLogLevel()); 64 | } 65 | 66 | 67 | void ofApp::onHTTPUploadEvent(ofxHTTP::PostUploadEventArgs& args) 68 | { 69 | std::string stateString = ""; 70 | 71 | switch (args.getState()) 72 | { 73 | case ofxHTTP::PostUploadEventArgs::UPLOAD_STARTING: 74 | stateString = "STARTING"; 75 | break; 76 | case ofxHTTP::PostUploadEventArgs::UPLOAD_PROGRESS: 77 | stateString = "PROGRESS"; 78 | break; 79 | case ofxHTTP::PostUploadEventArgs::UPLOAD_FINISHED: 80 | stateString = "FINISHED"; 81 | break; 82 | } 83 | 84 | ofLogNotice("ofApp::onHTTPUploadEvent") << ""; 85 | ofLogNotice("ofApp::onHTTPUploadEvent") << " state: " << stateString; 86 | ofLogNotice("ofApp::onHTTPUploadEvent") << " formFieldName: " << args.getFormFieldName(); 87 | ofLogNotice("ofApp::onHTTPUploadEvent") << "orig. filename: " << args.getOriginalFilename(); 88 | ofLogNotice("ofApp::onHTTPUploadEvent") << " filename: " << args.getFilename(); 89 | ofLogNotice("ofApp::onHTTPUploadEvent") << " fileType: " << args.getFileType().toString(); 90 | ofLogNotice("ofApp::onHTTPUploadEvent") << "# bytes xfer'd: " << args.getNumBytesTransferred(); 91 | } 92 | -------------------------------------------------------------------------------- /example_basic_server_post/src/ofApp.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "ofMain.h" 12 | #include "ofxHTTP.h" 13 | 14 | 15 | class ofApp: public ofBaseApp 16 | { 17 | public: 18 | void setup() override; 19 | void draw() override; 20 | 21 | void onHTTPPostEvent(ofxHTTP::PostEventArgs& evt); 22 | void onHTTPFormEvent(ofxHTTP::PostFormEventArgs& evt); 23 | void onHTTPUploadEvent(ofxHTTP::PostUploadEventArgs& evt); 24 | 25 | ofxHTTP::SimplePostServer server; 26 | 27 | }; 28 | -------------------------------------------------------------------------------- /example_basic_server_sent_events/addons.make: -------------------------------------------------------------------------------- 1 | ofxHTTP 2 | ofxIO 3 | ofxMediaType 4 | ofxNetworkUtils 5 | ofxPoco 6 | ofxSSLManager 7 | -------------------------------------------------------------------------------- /example_basic_server_sent_events/bin/data/DocumentRoot/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 404 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 24 |
25 |

404 - File Not Found

26 |
27 |
28 |

29 | Sorry ... your file was not found. 30 |

31 |
32 | 33 |
34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /example_basic_server_sent_events/bin/data/DocumentRoot/css/style.css: -------------------------------------------------------------------------------- 1 | @charset "UTF-8"; 2 | /* 3 | * jQuery File Upload Plugin CSS Example 8.8.2 4 | * https://github.com/blueimp/jQuery-File-Upload 5 | * 6 | * Copyright 2013, Sebastian Tschan 7 | * https://blueimp.net 8 | * 9 | * Licensed under the MIT license: 10 | * http://www.opensource.org/licenses/MIT 11 | */ 12 | 13 | body { 14 | padding-top: 60px; 15 | } 16 | -------------------------------------------------------------------------------- /example_basic_server_sent_events/bin/data/DocumentRoot/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakercp/ofxHTTP/fa65775e68a0ef8885a257a5ea055993342721a9/example_basic_server_sent_events/bin/data/DocumentRoot/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /example_basic_server_sent_events/bin/data/DocumentRoot/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakercp/ofxHTTP/fa65775e68a0ef8885a257a5ea055993342721a9/example_basic_server_sent_events/bin/data/DocumentRoot/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /example_basic_server_sent_events/bin/data/DocumentRoot/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakercp/ofxHTTP/fa65775e68a0ef8885a257a5ea055993342721a9/example_basic_server_sent_events/bin/data/DocumentRoot/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /example_basic_server_sent_events/bin/data/DocumentRoot/img/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakercp/ofxHTTP/fa65775e68a0ef8885a257a5ea055993342721a9/example_basic_server_sent_events/bin/data/DocumentRoot/img/favicon.ico -------------------------------------------------------------------------------- /example_basic_server_sent_events/bin/data/DocumentRoot/img/openFrameworks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakercp/ofxHTTP/fa65775e68a0ef8885a257a5ea055993342721a9/example_basic_server_sent_events/bin/data/DocumentRoot/img/openFrameworks.png -------------------------------------------------------------------------------- /example_basic_server_sent_events/bin/data/DocumentRoot/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | ofx::HTTP::SimpleSSEServer 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 24 |
25 |

Simple Server Sent Events (SSE) Server Demo

26 |
27 |
28 |

29 | ofx::HTTP::SimpleSSEServer is a simple server implements Server Sent Events. 30 |

31 |
32 |
33 |

Server Sent Events

34 |
    35 |
  • ...
  • 36 |
37 |
38 |
39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /example_basic_server_sent_events/bin/data/DocumentRoot/js/main.js: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | $(document).ready(function() { 8 | var eventList = document.getElementById("event-list"); 9 | 10 | var evtSource = new EventSource("/event-source"); 11 | 12 | evtSource.onmessage = function(e) { 13 | var newElement = document.createElement("li"); 14 | newElement.innerHTML = "message: " + e.data; 15 | eventList.appendChild(newElement); 16 | }; 17 | 18 | evtSource.addEventListener("ping", function(e) { 19 | var newElement = document.createElement("li"); 20 | var obj = JSON.parse(e.data); 21 | newElement.innerHTML = "ping at " + obj.time; 22 | eventList.appendChild(newElement); 23 | }, false); 24 | 25 | }); 26 | -------------------------------------------------------------------------------- /example_basic_server_sent_events/src/main.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofApp.h" 9 | 10 | 11 | int main() 12 | { 13 | ofSetupOpenGL(250, 50, OF_WINDOW); 14 | return ofRunApp(std::make_shared()); 15 | } 16 | -------------------------------------------------------------------------------- /example_basic_server_sent_events/src/ofApp.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofApp.h" 9 | 10 | 11 | void ofApp::setup() 12 | { 13 | ofSetLogLevel(OF_LOG_NOTICE); 14 | 15 | ofSetFrameRate(30); 16 | 17 | ofxHTTP::SimpleSSEServerSettings settings; 18 | 19 | // Many other settings are available. 20 | settings.setPort(7890); 21 | 22 | // Apply the settings. 23 | server.setup(settings); 24 | 25 | // Register listeners. 26 | server.sseRoute().registerEventListeners(this); 27 | 28 | // Start the server. 29 | server.start(); 30 | 31 | #if !defined(TARGET_LINUX_ARM) 32 | // Launch a browser with the address of the server. 33 | ofLaunchBrowser(server.url()); 34 | #endif 35 | 36 | } 37 | 38 | 39 | void ofApp::draw() 40 | { 41 | ofBackground(255); 42 | ofDrawBitmapStringHighlight("See " + server.url(), 10, 16); 43 | ofDrawBitmapStringHighlight("See the Console", 10, 42); 44 | } 45 | 46 | 47 | void ofApp::keyPressed(int key) 48 | { 49 | if (key == 'c') 50 | { 51 | ofJson json; 52 | 53 | json["cached"] = true; 54 | json["date"] = ofGetTimestampString(); 55 | 56 | ofxHTTP::SSEFrame frame(json.dump()); 57 | server.sseRoute().send(frame, true); 58 | } 59 | else if (key == 'd') 60 | { 61 | ofxHTTP::SSEFrame frame("not"); 62 | server.sseRoute().send(frame); 63 | } 64 | } 65 | 66 | 67 | void ofApp::onSSEOpenEvent(ofxHTTP::SSEOpenEventArgs& evt) 68 | { 69 | ofLogNotice("ofApp::onSSEOpenEvent") << "Connection opened from: " << evt.connection().clientAddress().toString(); 70 | } 71 | 72 | 73 | void ofApp::onSSECloseEvent(ofxHTTP::SSECloseEventArgs& evt) 74 | { 75 | ofLogNotice("ofApp::onSSECloseEvent") << "Connection closed: " << evt.code() << " : " << evt.reason(); 76 | } 77 | 78 | 79 | void ofApp::onSSEFrameSentEvent(ofxHTTP::SSEFrameEventArgs& evt) 80 | { 81 | ofLogNotice("ofApp::onSSEFrameSentEvent") << "Frame sent: " << evt.frame().data(); 82 | } 83 | -------------------------------------------------------------------------------- /example_basic_server_sent_events/src/ofApp.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "ofMain.h" 12 | #include "ofxHTTP.h" 13 | 14 | 15 | class ofApp: public ofBaseApp 16 | { 17 | public: 18 | void setup() override; 19 | void draw() override; 20 | 21 | void keyPressed(int key) override; 22 | 23 | void onSSEOpenEvent(ofxHTTP::SSEOpenEventArgs& evt); 24 | void onSSECloseEvent(ofxHTTP::SSECloseEventArgs& evt); 25 | void onSSEFrameSentEvent(ofxHTTP::SSEFrameEventArgs& evt); 26 | 27 | ofxHTTP::SimpleSSEServer server; 28 | 29 | }; 30 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/AbstractClientTypes.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "Poco/Net/HTTPClientSession.h" 12 | #include "Poco/Net/HTTPRequest.h" 13 | #include "Poco/Net/HTTPResponse.h" 14 | #include "Poco/URI.h" 15 | #include "ofTypes.h" 16 | #include "ofx/HTTP/Cookie.h" 17 | #include "ofx/IO/FilteredStreams.h" 18 | 19 | 20 | namespace ofx { 21 | namespace HTTP { 22 | 23 | 24 | class Request; 25 | class Response; 26 | class Context; 27 | 28 | 29 | /// \brief Represents an abstract request filter. 30 | /// 31 | /// The implementation must be thread-safe, as multiple clients may call the 32 | /// request filter methods. 33 | class AbstractRequestFilter 34 | { 35 | public: 36 | virtual ~AbstractRequestFilter() 37 | { 38 | } 39 | 40 | virtual void requestFilter(Context& context, 41 | Request& request) const = 0; 42 | 43 | }; 44 | 45 | 46 | /// Some response filters will modify the request for resubmission, thus the 47 | /// 48 | class AbstractResponseFilter 49 | { 50 | public: 51 | virtual ~AbstractResponseFilter() 52 | { 53 | } 54 | 55 | virtual void responseFilter(Context& context, 56 | Request& request, 57 | Response& response) const = 0; 58 | 59 | }; 60 | 61 | 62 | class AbstractRequestResponseFilter: 63 | public AbstractRequestFilter, 64 | public AbstractResponseFilter 65 | { 66 | public: 67 | virtual ~AbstractRequestResponseFilter() 68 | { 69 | } 70 | 71 | }; 72 | 73 | 74 | class AbstractRequestStreamFilter: public AbstractRequestFilter 75 | { 76 | public: 77 | virtual ~AbstractRequestStreamFilter() 78 | { 79 | } 80 | 81 | virtual void requestStreamFilter(Context& context, 82 | const Request& request, 83 | IO::FilteredOutputStream& requestStream) const = 0; 84 | 85 | }; 86 | 87 | 88 | class AbstractResponseStreamFilter: public AbstractRequestResponseFilter 89 | { 90 | public: 91 | virtual ~AbstractResponseStreamFilter() 92 | { 93 | } 94 | 95 | virtual void responseStreamFilter(Context& context, 96 | const Request& request, 97 | const Response& response, 98 | IO::FilteredInputStream& responseStream) const = 0; 99 | 100 | }; 101 | 102 | 103 | //class AbstractClientSessionProvider; 104 | // 105 | // 106 | //class AbstractClientSession: public Poco::Net::HTTPClientSession 107 | //{ 108 | //public: 109 | // virtual ~AbstractClientSession() 110 | // { 111 | // } 112 | // 113 | // /// \returns the Abstract client session provider or nullptr if none exists. 114 | // virtual AbstractClientSessionProvider* parent() const; 115 | // 116 | //}; 117 | 118 | 119 | class AbstractClientSessionProvider: public AbstractRequestFilter 120 | { 121 | public: 122 | virtual ~AbstractClientSessionProvider() 123 | { 124 | } 125 | 126 | virtual void returnClientSession(std::unique_ptr session) const = 0; 127 | 128 | }; 129 | 130 | 131 | class ClientCacheEntry; 132 | 133 | 134 | class AbstractClientCacheStorage 135 | { 136 | public: 137 | virtual ~AbstractClientCacheStorage() 138 | { 139 | } 140 | 141 | virtual void put(const std::string& key, ClientCacheEntry value) = 0; 142 | 143 | virtual ClientCacheEntry get(const std::string& key) = 0; 144 | 145 | virtual void remove(const std::string& key) = 0; 146 | 147 | virtual void update(const std::string& key) = 0; 148 | 149 | }; 150 | 151 | 152 | } } // namespace ofx::HTTP 153 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/AuthScope.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include "Poco/URI.h" 16 | #include "ofx/HTTP/Authentication.h" 17 | 18 | 19 | namespace ofx { 20 | namespace HTTP { 21 | 22 | 23 | class AuthScope 24 | { 25 | public: 26 | AuthScope(); 27 | 28 | AuthScope(const std::string& host); 29 | 30 | AuthScope(const std::string& host, uint16_t port); 31 | 32 | AuthScope(const std::string& scheme, 33 | const std::string& host, 34 | uint16_t port); 35 | 36 | AuthScope(const std::string& host, 37 | AuthenticationType authType); 38 | 39 | AuthScope(const std::string& host, 40 | uint16_t port, 41 | AuthenticationType authType); 42 | 43 | AuthScope(const std::string& scheme, 44 | const std::string& host, 45 | uint16_t port, 46 | const std::string& realm, 47 | AuthenticationType authType); 48 | 49 | AuthScope(const Poco::URI& uri); 50 | 51 | bool hasScheme() const; 52 | void clearScheme(); 53 | void setScheme(const std::string& scheme); 54 | std::string getScheme() const; 55 | 56 | bool hasHost() const; 57 | void clearHost(); 58 | void setHost(const std::string& host); 59 | std::string getHost() const; 60 | 61 | bool hasPort() const; 62 | void clearPort(); 63 | void setPort(uint16_t port); 64 | uint16_t getPort() const; 65 | 66 | bool hasRealm() const; 67 | void clearRealm(); 68 | void setRealm(const std::string& realm); 69 | std::string getRealm() const; 70 | 71 | bool hasAuthType() const; 72 | void clearAuthType(); 73 | void setAuthType(AuthenticationType authType); 74 | AuthenticationType getAuthType() const; 75 | 76 | int match(const AuthScope& scope) const; 77 | 78 | bool operator == (const AuthScope& scope) const; 79 | bool operator != (const AuthScope& scope) const; 80 | bool operator < (const AuthScope& scope) const; 81 | 82 | std::string toString() const; 83 | 84 | private: 85 | bool _hasScheme; 86 | std::string _scheme; 87 | 88 | bool _hasHost; 89 | std::string _host; 90 | 91 | bool _hasPort; 92 | uint16_t _port; 93 | 94 | bool _hasRealm; 95 | std::string _realm; 96 | 97 | bool _hasAuthType; 98 | AuthenticationType _authType; 99 | 100 | }; 101 | 102 | 103 | } } // namespace ofx::HTTP 104 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/Authentication.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | namespace ofx { 12 | namespace HTTP { 13 | 14 | 15 | enum AuthenticationType 16 | { 17 | NONE, 18 | BASIC, 19 | DIGEST 20 | }; 21 | 22 | enum AuthenticationStatus 23 | { 24 | OK, 25 | UNAUTHORIZED, 26 | NO_CREDENTIALS 27 | }; 28 | 29 | 30 | } } // namespace ofx::HTTP 31 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/ClientSessionProvider.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "ofx/HTTP/AbstractClientTypes.h" 12 | #include "ofx/HTTP/HTTPHost.h" 13 | 14 | 15 | namespace ofx { 16 | namespace HTTP { 17 | 18 | 19 | //class ClientSession: public AbstractClientSession 20 | //{ 21 | //public: 22 | // ClientSession(const HTTPHost& host); 23 | // 24 | // virtual ~ClientSession(); 25 | // 26 | // virtual AbstractClientSessionProvider* parent() const; 27 | // 28 | //private: 29 | // ClientSessionProvider* _parent = nullptr; 30 | // 31 | //}; 32 | 33 | 34 | 35 | /// \brief Set up a client session based on the requested URI scheme and host. 36 | class ClientSessionProvider: public AbstractClientSessionProvider 37 | { 38 | public: 39 | ClientSessionProvider(); 40 | 41 | virtual ~ClientSessionProvider(); 42 | 43 | virtual void requestFilter(Context& context, 44 | Request& request) const override; 45 | 46 | virtual void returnClientSession(std::unique_ptr session) const override; 47 | 48 | private: 49 | /// \brief Attempt to determine the host information from a request or context. 50 | static HTTPHost _extractHost(const Context& context, 51 | const Request& request); 52 | 53 | static HTTPHost _extractHost(const Poco::Net::HTTPClientSession& session); 54 | 55 | /// \brief Attempt to determine the can be used to contact the given host. 56 | static bool _isValidSessionForHost(const Poco::Net::HTTPClientSession& session, 57 | const HTTPHost& host); 58 | 59 | /// \brief Get session for the given host and context. 60 | void _getSessionForRequest(Context& context, const HTTPHost& host) const; 61 | 62 | /// \brief The session pool. It is effectively a cache, and thus mutable. 63 | mutable std::vector> _sessions; 64 | 65 | /// \brief The mutex for multi-threaded access. 66 | mutable std::mutex _mutex; 67 | 68 | }; 69 | 70 | 71 | } } // namespace ofx::HTTP 72 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/ClientState.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include 12 | 13 | 14 | namespace ofx { 15 | namespace HTTP { 16 | 17 | 18 | enum class ClientState 19 | { 20 | /// \brief A default value that should not be encountered. 21 | NONE, 22 | 23 | /// \brief The system starts to detect a proxy. 24 | /// 25 | /// This step may not occur depending on the system configuration. 26 | DETECTING_PROXY, 27 | 28 | /// \brief The system is resolving the hostname for the HTTP connection. 29 | /// 30 | /// This step may not occur if the hostname doesn't need to be resolved. 31 | RESOLVING_NAME, 32 | 33 | /// \brief The HTTP connection to the server is negotiating SSL. 34 | /// 35 | /// If the SSL negotiation fails, then this will be the last step that 36 | /// occurs on the HTTP connection. 37 | CONNECTING_TO_SERVER, 38 | 39 | /// \brief HTTP headers are being sent to the server. 40 | NEGOTIATING_SSL, 41 | 42 | /// \brief HTTP headers are being sent to the server. 43 | SENDING_HEADERS, 44 | 45 | /// \brief HTTP content is being sent to the server. 46 | /// 47 | /// This step may not occur if there is no content to send. 48 | SENDING_CONTENTS, 49 | 50 | /// \brief The HTTP client is waiting for a response from the server. 51 | WAITING_FOR_RESPONSE, 52 | 53 | /// \brief The HTTP client is receiving headers from the server. 54 | RECEIVING_HEADERS, 55 | 56 | /// \brief The HTTP client is receiving content from the server. 57 | RECEIVING_CONTENTS, 58 | 59 | /// \brief The HTTP client is being redirected. 60 | REDIRECTING 61 | }; 62 | 63 | 64 | std::string to_string(ClientState state); 65 | 66 | bool from_string(const std::string text, ClientState& state); 67 | 68 | 69 | } } // namespace ofx::HTTP 70 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/Cookie.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "Poco/URI.h" 12 | #include "Poco/String.h" 13 | #include "Poco/Timestamp.h" 14 | #include "Poco/UTF8String.h" 15 | #include "Poco/Net/HTTPCookie.h" 16 | #include "ofUtils.h" 17 | 18 | 19 | namespace ofx { 20 | namespace HTTP { 21 | 22 | 23 | class Cookie: public Poco::Net::HTTPCookie 24 | { 25 | public: 26 | Cookie(const Poco::Net::HTTPCookie& cookie); 27 | Cookie(const Poco::Net::HTTPCookie& cookie, Poco::Timestamp createdAt); 28 | 29 | virtual ~Cookie(); 30 | 31 | /// \returns The Cooke's created-at timestamp. 32 | Poco::Timestamp createdAt() const; 33 | 34 | // bool isExpired(Poco::Timestamp expiredAt = Poco::Timestamp()) const; 35 | // bool isSession() const; 36 | // 37 | // bool matchesDomain(const Poco::URI& uri) const; 38 | // bool matchesPath(const Poco::URI& uri) const; 39 | // bool matchesURI(const Poco::URI& uri, 40 | // bool matchSessionCookies = true) const; 41 | // // matches uri 42 | // // makes sure the cookie 43 | // bool matches(const Cookie& cookie) const; 44 | // 45 | // std::string toString() const; 46 | 47 | protected: 48 | /// \brief The Cookie's created-at timestamp. 49 | Poco::Timestamp _createdAt; 50 | 51 | }; 52 | 53 | 54 | } } // namespace ofx::HTTP 55 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/CookieUtils.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | // 7 | // 8 | //#pragma once 9 | // 10 | // 11 | //#include 12 | //#include 13 | //#include 14 | //#include "Poco/RegularExpression.h" 15 | //#include "Poco/String.h" 16 | //#include "Poco/URI.h" 17 | //#include "Poco/Net/HTTPCookie.h" 18 | //#include "Poco/Net/HTTPRequest.h" 19 | //#include "Poco/Net/HTTPResponse.h" 20 | //#include "Poco/Net/NameValueCollection.h" 21 | //#include "ofx/HTTP/Cookie.h" 22 | // 23 | // 24 | //namespace ofx { 25 | //namespace HTTP { 26 | // 27 | // 28 | //class CookieUtils 29 | //{ 30 | //public: 31 | // static bool equals(const std::string& thisString, 32 | // const std::string& otherString); 33 | // 34 | // static bool startsWith(const std::string& fullString, 35 | // const std::string& beginning); 36 | // 37 | // static bool endsWith(const std::string& fullString, 38 | // const std::string& ending); 39 | // 40 | // /// \brief path-matches algorithm, as defined by RFC 2965 41 | // static bool pathMatches(const Poco::URI& uri, 42 | // const Poco::Net::HTTPCookie& cookie); 43 | // 44 | // static bool domainMatches(const Poco::URI& uri, 45 | // const Cookie& cookie); 46 | // 47 | // static bool compare(const Cookie& a, 48 | // const Cookie& b); 49 | // 50 | // static void sortByPath(std::vector& cookies); 51 | // 52 | // static bool hasExpired(const Cookie& cookie); 53 | // 54 | //}; 55 | // 56 | // 57 | //} } // namespace ofx::HTTP 58 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/Credentials.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include 12 | 13 | 14 | namespace ofx { 15 | namespace HTTP { 16 | 17 | 18 | class Credentials 19 | { 20 | public: 21 | Credentials(); 22 | Credentials(const std::string& username, const std::string& password); 23 | 24 | virtual ~Credentials(); 25 | 26 | virtual void clear(); 27 | 28 | std::string getUsername() const; 29 | std::string getPassword() const; 30 | 31 | void setUsername(const std::string& username); 32 | void setPassword(const std::string& password); 33 | 34 | bool hasCredentials() const; 35 | 36 | std::string toString() const; 37 | 38 | protected: 39 | std::string _username; 40 | std::string _password; 41 | 42 | }; 43 | 44 | 45 | } } // namespace ofx::HTTP 46 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/DefaultClientHeaders.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "ofx/HTTP/AbstractClientTypes.h" 12 | 13 | 14 | namespace ofx { 15 | namespace HTTP { 16 | 17 | 18 | class DefaultClientHeaders: public AbstractRequestFilter 19 | { 20 | public: 21 | DefaultClientHeaders(); 22 | 23 | virtual ~DefaultClientHeaders(); 24 | 25 | virtual void requestFilter(Context& context, Request& request) const override; 26 | 27 | }; 28 | 29 | 30 | } } // namespace ofx::HTTP 31 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/DefaultCookieProcessor.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "ofx/HTTP/AbstractClientTypes.h" 12 | 13 | 14 | namespace ofx { 15 | namespace HTTP { 16 | 17 | 18 | //class DefaultCookieProcessor: public AbstractCookieProcessor 19 | //{ 20 | //public: 21 | // DefaultCookieProcessor(); 22 | // 23 | // virtual ~DefaultCookieProcessor(); 24 | // 25 | // virtual void filter(Poco::Net::HTTPRequest& request, 26 | // Context& context); 27 | // 28 | // virtual void filter(Poco::Net::HTTPRequest& request, 29 | // Poco::Net::HTTPResponse& response, 30 | // Context& context); 31 | // 32 | //}; 33 | 34 | 35 | 36 | } } // namespace ofx::HTTP 37 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/DefaultEncodingResponseStreamFilter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "ofx/HTTP/AbstractClientTypes.h" 12 | #include "ofx/HTTP/Request.h" 13 | #include "ofx/HTTP/Response.h" 14 | #include "ofx/HTTP/Context.h" 15 | 16 | 17 | namespace ofx { 18 | namespace HTTP { 19 | 20 | 21 | class DefaultEncodingResponseStreamFilter: public AbstractResponseStreamFilter 22 | { 23 | public: 24 | DefaultEncodingResponseStreamFilter(); 25 | virtual ~DefaultEncodingResponseStreamFilter(); 26 | 27 | void requestFilter(Context& context, Request& request) const override; 28 | 29 | void responseFilter(Context& context, 30 | Request& request, 31 | Response& response) const override; 32 | 33 | void responseStreamFilter(Context& context, 34 | const Request& request, 35 | const Response& response, 36 | IO::FilteredInputStream& responseStream) const override; 37 | 38 | /// \brief The "Accept-Encoding" header key. 39 | static const std::string ACCEPT_ENCODING_HEADER; 40 | 41 | /// \brief The "Content-Encoding" header key. 42 | static const std::string CONTENT_ENCODING_HEADER; 43 | 44 | }; 45 | 46 | 47 | } } // namespace ofx::HTTP 48 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/DefaultProxyProcessor.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "ofx/HTTP/AbstractClientTypes.h" 12 | 13 | 14 | namespace ofx { 15 | namespace HTTP { 16 | 17 | 18 | class DefaultProxyProcessor: public AbstractRequestResponseFilter 19 | { 20 | public: 21 | DefaultProxyProcessor(); 22 | 23 | virtual ~DefaultProxyProcessor(); 24 | 25 | virtual void requestFilter(Context& context, Request& request) const override; 26 | 27 | virtual void responseFilter(Context& context, 28 | Request& request, 29 | Response& response) const override; 30 | 31 | }; 32 | 33 | 34 | } } // namespace ofx::HTTP 35 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/DefaultRedirectProcessor.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "ofx/HTTP/AbstractClientTypes.h" 12 | 13 | 14 | namespace ofx { 15 | namespace HTTP { 16 | 17 | 18 | /// \brief A simple default client redirect policy. 19 | /// 20 | /// This redirect policy will attempt to redirect response codes: 21 | /// 22 | /// - 301 Moved Permanently 23 | /// - 302 Found 24 | /// - 303 See Other 25 | /// - 307 Temporary Redirect 26 | /// 27 | /// Additionally, this policy will will redirect content containing requests 28 | /// such as POST and PUT by converting their request type to a GET. 29 | class DefaultRedirectProcessor: public AbstractRequestResponseFilter 30 | { 31 | public: 32 | DefaultRedirectProcessor(); 33 | 34 | virtual ~DefaultRedirectProcessor(); 35 | 36 | virtual void requestFilter(Context& context, 37 | Request& request) const override; 38 | 39 | virtual void responseFilter(Context& context, 40 | Request& request, 41 | Response& response) const override; 42 | 43 | }; 44 | 45 | 46 | } } // namespace ofx::HTTP 47 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/FileSystemRoute.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "ofx/HTTP/BaseRoute.h" 12 | 13 | 14 | namespace ofx { 15 | namespace HTTP { 16 | 17 | 18 | class FileSystemRouteSettings: public BaseRouteSettings 19 | { 20 | public: 21 | FileSystemRouteSettings(const std::string& routePathPattern = DEFAULT_ROUTE_PATH_PATTERN, 22 | bool requireSecurePort = false, 23 | bool requireAuthentication = false); 24 | 25 | virtual ~FileSystemRouteSettings(); 26 | 27 | // TODO: 28 | // e.g. http://httpd.apache.org/docs/2.2/mod/mod_deflate.html 29 | // or the reverse? compression type as key? 30 | // ofxHTTPCompressorEntry html(MediaType("text/html")); 31 | // html.addCompressionType(GZIP); 32 | // html.addCompressionType(DEFLATE); 33 | // 34 | // ofxHTTPCompressorEntry plain(MediaType("text/plain")); 35 | // html.addCompressionType(GZIP); 36 | // html.addCompressionType(DEFLATE); 37 | 38 | void setDefaultIndex(const std::string& defaultIndex); 39 | const std::string& getDefaultIndex() const; 40 | 41 | void setDocumentRoot(const std::string& documentRoot); 42 | const std::string& getDocumentRoot() const; 43 | 44 | void setAutoCreateDocumentRoot(bool autoCreateDocumentRoot); 45 | bool getAutoCreateDocumentRoot() const; 46 | 47 | void setRequireDocumentRootInDataFolder(bool requireDocumentRootInDataFolder); 48 | bool getRequireDocumentRootInDataFolder() const; 49 | 50 | static const std::string DEFAULT_DOCUMENT_ROOT; 51 | static const std::string DEFAULT_INDEX; 52 | 53 | /// \brief An unfortunate compromise until C++11. 54 | /// \note C++ is not able to initialize static collections until 55 | /// after C++11. This is a compromise until then. 56 | static const std::string DEFAULT_GET_HTTP_METHODS_ARRAY[]; 57 | 58 | /// \brief The default HTTP methods for this route. 59 | static const HTTPMethodSet DEFAULT_GET_HTTP_METHODS; 60 | 61 | private: 62 | std::string _defaultIndex; 63 | std::string _documentRoot; 64 | 65 | bool _autoCreateDocumentRoot; 66 | bool _requireDocumentRootInDataFolder; 67 | 68 | }; 69 | 70 | 71 | /// \brief A route for serving files from the file system. 72 | class FileSystemRoute: public BaseRoute_ 73 | { 74 | public: 75 | typedef FileSystemRouteSettings Settings; 76 | 77 | FileSystemRoute(const Settings& settings); 78 | 79 | virtual ~FileSystemRoute(); 80 | 81 | virtual void handleRequest(ServerEventArgs& evt) override; 82 | 83 | virtual void handleErrorResponse(ServerEventArgs& evt); 84 | 85 | Poco::Net::HTTPRequestHandler* createRequestHandler(const Poco::Net::HTTPServerRequest& request) override; 86 | 87 | }; 88 | 89 | 90 | } } // namespace ofx::HTTP 91 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/FormRequest.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "ofx/HTTP/Request.h" 12 | #include "Poco/Net/HTMLForm.h" 13 | #include "Poco/Net/NameValueCollection.h" 14 | 15 | 16 | namespace ofx { 17 | namespace HTTP { 18 | 19 | 20 | /// \brief A Custom Base HTTP Request. 21 | class FormRequest: public Request 22 | { 23 | public: 24 | using Request::Request; 25 | 26 | /// \brief Destroy this BaseReuqest. 27 | virtual ~FormRequest(); 28 | 29 | /// \brief Add a name value pair to upload with this request. 30 | /// 31 | /// When form fields are added to anything other then POST and PUT requests, 32 | /// the form fields will be converted to query parameters and appended to 33 | /// the URI before request submission. 34 | /// 35 | /// \param name The field name. 36 | /// \param value The field value. 37 | void addFormField(const std::string& name, 38 | const std::string& value); 39 | 40 | /// \brief Set a name value pair to upload with this request. 41 | /// 42 | /// When form fields are added to anything other then POST and PUT requests, 43 | /// the form fields will be converted to query parameters and appended to 44 | /// the URI before request submission. 45 | /// 46 | /// \param name The field name. 47 | /// \param value The field value. 48 | void setFormField(const std::string& name, 49 | const std::string& value); 50 | 51 | /// \brief Add additional form fields. 52 | /// 53 | /// When form fields are added to anything other then POST and PUT requests, 54 | /// the form fields will be converted to query parameters and appended to 55 | /// the URI before request submission. 56 | /// 57 | /// \param formFields The form fields to add. 58 | void addFormFields(const Poco::Net::NameValueCollection& formFields); 59 | 60 | /// \brief Add additional form fields. 61 | /// 62 | /// When form fields are added to anything other then POST and PUT requests, 63 | /// the form fields will be converted to query parameters and appended to 64 | /// the URI before request submission. 65 | /// 66 | /// \param formFields The form fields to add. 67 | void addFormFields(const std::multimap& formFields); 68 | 69 | /// \brief Clear all form fields. 70 | void clearFormFields(); 71 | 72 | /// \brief The default MIME type. 73 | static const std::string DEFAULT_MEDIA_TYPE; 74 | 75 | /// \brief A friend class. 76 | friend class BaseClient; 77 | 78 | }; 79 | 80 | 81 | } } // namespace ofx::HTTP 82 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/GetRequest.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "ofx/HTTP/FormRequest.h" 12 | 13 | 14 | namespace ofx { 15 | namespace HTTP { 16 | 17 | 18 | class GetRequest: public FormRequest 19 | { 20 | public: 21 | GetRequest(const std::string& uri, 22 | const std::string& httpVersion = Poco::Net::HTTPMessage::HTTP_1_1); 23 | 24 | virtual ~GetRequest(); 25 | 26 | }; 27 | 28 | 29 | } } // namespace ofx::HTTP 30 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/GetRequestTask.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "Poco/Task.h" 12 | #include "Poco/TaskNotification.h" 13 | #include "ofx/HTTP/ClientEvents.h" 14 | #include "ofx/HTTP/Client.h" 15 | #include "ofx/HTTP/ThreadSettings.h" 16 | 17 | 18 | namespace ofx { 19 | namespace HTTP { 20 | 21 | 22 | class GetRequestTask: public Poco::Task 23 | { 24 | public: 25 | GetRequestTask(const std::string& uri, const std::string& cachePath = ""); 26 | 27 | virtual ~GetRequestTask(); 28 | 29 | void runTask(); 30 | 31 | bool onHTTPClientStateChange(ClientStateChangeEventArgs& args); 32 | 33 | bool onHTTPClientRequestProgress(ClientRequestProgressEventArgs& args); 34 | bool onHTTPClientResponseProgress(ClientResponseProgressEventArgs& args); 35 | 36 | bool onHTTPClientResponseStream(ClientResponseStreamEventArgs& args); 37 | bool onHTTPClientError(ClientErrorEventArgs& args); 38 | 39 | private: 40 | std::string _uri; 41 | std::string _cachePath; 42 | }; 43 | 44 | 45 | } } // namespace ofx::HTTP 46 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/HTTP.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | /// \namespace ofx 12 | /// \brief openFrameworks Extended 13 | /// \sa http://openframeworks.cc 14 | /// \sa http://ofxaddons.com 15 | namespace ofx 16 | { 17 | 18 | /// \namespace HTTP 19 | /// \brief HTTP is a package for HTTP Client and Server activities. 20 | namespace HTTP 21 | { 22 | 23 | 24 | } } // namespace ofx::HTTP 25 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/HTTPClient.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | // 7 | // 8 | //#pragma once 9 | // 10 | // 11 | //#include "ofConstants.h" 12 | //#include "json.hpp" 13 | //#include "ofx/HTTP/BaseClient.h" 14 | //#include "ofx/HTTP/ClientSessionProvider.h" 15 | //#include "ofx/HTTP/CredentialStore.h" 16 | //#include "ofx/HTTP/DefaultClientHeaders.h" 17 | //#include "ofx/HTTP/DefaultProxyProcessor.h" 18 | //#include "ofx/HTTP/DefaultRedirectProcessor.h" 19 | //#include "ofx/HTTP/DefaultEncodingResponseStreamFilter.h" 20 | //#include "ofx/HTTP/Response.h" 21 | //#include "ofx/HTTP/GetRequest.h" 22 | //#include "ofx/HTTP/JSONRequest.h" 23 | //#include "ofx/HTTP/PostRequest.h" 24 | // 25 | // 26 | //namespace ofx { 27 | //namespace HTTP { 28 | // 29 | // 30 | //class HTTPClient: public BaseClient 31 | //{ 32 | //public: 33 | // HTTPClient(); 34 | // 35 | // virtual ~HTTPClient(); 36 | // 37 | // /// \brief GET data from the given URI. 38 | // /// \param uri The endpoint URI. 39 | // /// \returns a buffered response. 40 | //// std::unique_ptr> get(const std::string& uri); 41 | //// 42 | //// /// \brief POST JSON to the given URI using application/json type. 43 | //// /// \param uri The endpoint URI. 44 | //// /// \param json The JSON to post. 45 | //// /// \returns a buffered response. 46 | //// std::unique_ptr> post(const std::string& uri, 47 | //// const ofJson& json); 48 | //// 49 | //// 50 | //// std::unique_ptr> form(const std::string& uri, 51 | //// const std::multimap formFields = { }, 52 | //// const std::vector& formParts = { }); 53 | // 54 | //private: 55 | // ClientSessionProvider _clientSessionProvider; 56 | // DefaultClientHeaders _defaultClientHeaders; 57 | // DefaultProxyProcessor _defaultProxyProcessor; 58 | // DefaultCredentialStore _defaultAuthenticationProcessor; 59 | // DefaultRedirectProcessor _defaultRedirectProcessor; 60 | // DefaultEncodingResponseStreamFilter _encodingResponseStreamFilter; 61 | // 62 | //}; 63 | // 64 | // 65 | //} } // namespace ofx::HTTP 66 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/HTTPHost.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include 12 | #include 13 | 14 | 15 | namespace ofx { 16 | namespace HTTP { 17 | 18 | 19 | class HTTPHost 20 | { 21 | public: 22 | HTTPHost(const std::string& scheme, 23 | const std::string& host, 24 | uint16_t port); 25 | 26 | ~HTTPHost(); 27 | 28 | std::string scheme() const; 29 | std::string host() const; 30 | uint16_t port() const; 31 | 32 | /// \returns true of this host is secure. 33 | bool secure() const; 34 | 35 | std::string toString() const; 36 | 37 | /// \brief Stream output. 38 | /// \param os the std::ostream. 39 | /// \param host The HTTPHost to output. 40 | /// \returns the updated std::ostream reference. 41 | friend std::ostream& operator << (std::ostream& os, const HTTPHost& host); 42 | 43 | private: 44 | std::string _scheme; 45 | std::string _host; 46 | uint16_t _port; 47 | 48 | }; 49 | 50 | 51 | inline std::ostream& operator<<(std::ostream& os, const HTTPHost& host) 52 | { 53 | os << host.toString(); 54 | return os; 55 | } 56 | 57 | 58 | } } // namespace ofx::HTTP 59 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/HeadRequest.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "ofx/HTTP/FormRequest.h" 12 | 13 | 14 | namespace ofx { 15 | namespace HTTP { 16 | 17 | 18 | class HeadRequest: public FormRequest 19 | { 20 | public: 21 | HeadRequest(const std::string& uri, 22 | const std::string& httpVersion = Poco::Net::HTTPMessage::HTTP_1_1); 23 | 24 | virtual ~HeadRequest(); 25 | 26 | }; 27 | 28 | 29 | } } // namespace ofx::HTTP 30 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/IPVideoFrame.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "ofFileUtils.h" 12 | #include "ofImage.h" 13 | 14 | 15 | namespace ofx { 16 | namespace HTTP { 17 | 18 | 19 | class IPVideoFrameSettings 20 | { 21 | public: 22 | IPVideoFrameSettings(); 23 | virtual ~IPVideoFrameSettings(); 24 | 25 | void setWidth(int width); 26 | int getWidth() const; 27 | 28 | void setHeight(int height); 29 | int getHeight() const; 30 | 31 | void setFlipHorizontal(bool flipHorizontal); 32 | bool getFlipHorizontal() const; 33 | 34 | void setFlipVertical(bool flipVertical); 35 | bool getFlipVertical() const; 36 | 37 | void setQuality(ofImageQualityType quality); 38 | ofImageQualityType getQuality() const; 39 | 40 | enum 41 | { 42 | NO_RESIZE = -1, 43 | }; 44 | 45 | private: 46 | std::size_t _width = NO_RESIZE; 47 | std::size_t _height = NO_RESIZE; 48 | bool _flipHorizontal = false; 49 | bool _flipVertical = false; 50 | ofImageQualityType _quality = OF_IMAGE_QUALITY_BEST; 51 | 52 | }; 53 | 54 | 55 | class IPVideoFrame 56 | { 57 | public: 58 | IPVideoFrame(const IPVideoFrameSettings& settings, 59 | uint64_t timestamp, 60 | const ofBuffer& buffer); 61 | 62 | virtual ~IPVideoFrame(); 63 | 64 | const IPVideoFrameSettings& settings() const; 65 | 66 | uint64_t timestamp() const; 67 | 68 | ofBuffer& buffer(); 69 | 70 | private: 71 | IPVideoFrameSettings _settings; 72 | uint64_t _timestamp; 73 | ofBuffer _buffer; 74 | 75 | }; 76 | 77 | 78 | } } // namespace ofx::HTTP 79 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/JSONRequest.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "ofConstants.h" 12 | #include "ofJson.h" 13 | #include "ofx/HTTP/Request.h" 14 | 15 | 16 | namespace ofx { 17 | namespace HTTP { 18 | 19 | 20 | /// \brief An HTTP POST Request with a JSON request body. 21 | class JSONRequest: public Request 22 | { 23 | public: 24 | /// \brief Construct a JSONRequest with a given uri and http version. 25 | /// \param uri the POST endpoint uri. 26 | /// \param httpVersion Either HTTP/1.0 or HTTP/1.1. 27 | JSONRequest(const std::string& uri, 28 | const std::string& httpVersion = Poco::Net::HTTPMessage::HTTP_1_1); 29 | 30 | /// \brief Construct a JSONRequest with a given uri and http version. 31 | /// \param uri the Post endpoint uri. 32 | /// \param json The json to send. 33 | /// \param httpVersion Either HTTP/1.0 or HTTP/1.1. 34 | JSONRequest(const std::string& uri, 35 | const ofJson& json, 36 | const std::string& httpVersion); 37 | 38 | /// \brief Destroy the JSONRequest. 39 | virtual ~JSONRequest(); 40 | 41 | /// \brief Set the JSON content. 42 | /// \param json The JSON content. 43 | virtual void setJSON(const ofJson& json); 44 | 45 | /// \returns a const reference to the request JSON. 46 | virtual const ofJson& getJSON() const; 47 | 48 | /// \brief The JSON media type. 49 | static const std::string JSON_MEDIA_TYPE; 50 | 51 | protected: 52 | /// \brief Custom prepareRequest() to set the content length; 53 | virtual void prepareRequest() override; 54 | 55 | /// \brief Writes from the form buffer. 56 | /// \param requestStream The stream to write the request body. 57 | void writeRequestBody(std::ostream& requestStream) override; 58 | 59 | /// \brief The JSON data to send. 60 | ofJson _json; 61 | 62 | private: 63 | /// \brief An output buffer. 64 | std::stringstream _outBuffer; 65 | 66 | }; 67 | 68 | 69 | } } // namespace ofx::HTTP 70 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/JSONResponse.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "ofx/HTTP/Response" 12 | 13 | 14 | namespace ofx { 15 | namespace HTTP { 16 | 17 | 18 | 19 | ///// \brief An HTTP POST Request with a JSON request body. 20 | //class JSONResponse: public Response 21 | //{ 22 | //public: 23 | // /// \brief Construct a JSONResponse 24 | // JSONResponse(); 25 | // 26 | // /// \brief Construct a JSONResponse 27 | // /// \param json The JSON content. 28 | // JSONResponse(const ofJson& json); 29 | // 30 | // /// \brief Destroy the JSONRequest. 31 | // virtual ~JSONRequest(); 32 | // 33 | // /// \brief Set the JSON content. 34 | // /// \param json The JSON content. 35 | // virtual void setJSON(const ofJson& json); 36 | // 37 | // /// \returns a const reference to the request JSON. 38 | // virtual const ofJson& getJSON() const; 39 | // 40 | // /// \brief The JSON media type. 41 | // static const std::string JSON_MEDIA_TYPE; 42 | // 43 | //protected: 44 | // /// \brief Custom prepareRequest() to set the content length; 45 | // virtual void prepareRequest() override; 46 | // 47 | // /// \brief Writes from the form buffer. 48 | // /// \param requestStream The stream to write the request body. 49 | // void writeRequestBody(std::ostream& requestStream) override; 50 | // 51 | // /// \brief The JSON data to send. 52 | // mutable ofJson _json; 53 | // 54 | //private: 55 | // /// \brief An output buffer. 56 | // std::stringstream _outBuffer; 57 | // 58 | //}; 59 | 60 | 61 | 62 | 63 | } } // namespace ofx::HTTP 64 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/OAuth10Credentials.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include 12 | #include "ofFileUtils.h" 13 | #include "ofConstants.h" 14 | #include "ofJson.h" 15 | 16 | 17 | namespace ofx { 18 | namespace HTTP { 19 | 20 | 21 | class OAuth10Credentials 22 | { 23 | public: 24 | OAuth10Credentials(); 25 | 26 | OAuth10Credentials(const std::string& consumerKey, 27 | const std::string& consumerSecret); 28 | 29 | OAuth10Credentials(const std::string& consumerKey, 30 | const std::string& consumerSecret, 31 | const std::string& accessToken, 32 | const std::string& accessTokentSecret); 33 | 34 | /// \brief Destroy the OAuth10Credentials. 35 | virtual ~OAuth10Credentials(); 36 | 37 | std::string consumerKey() const; 38 | 39 | std::string consumerSecret() const; 40 | 41 | std::string accessToken() const; 42 | 43 | std::string accessTokenSecret() const; 44 | 45 | std::string owner() const; 46 | 47 | std::string ownerId() const; 48 | 49 | static OAuth10Credentials fromJSON(const ofJson& value); 50 | 51 | static ofJson toJSON(const OAuth10Credentials& credentials); 52 | 53 | static OAuth10Credentials fromFile(const std::filesystem::path& credentialsFile); 54 | 55 | static bool toFile(const OAuth10Credentials& credentials, 56 | const std::filesystem::path& credentialsFile); 57 | 58 | private: 59 | /// \brief The OAuth 1.0 consumer key. 60 | std::string _consumerKey; 61 | 62 | /// \brief The OAuth 1.0 consumer secret. 63 | std::string _consumerSecret; 64 | 65 | /// \brief The OAuth 1.0 access token. 66 | std::string _accessToken; 67 | 68 | /// \brief The OAuth 1.0 access token secret. 69 | std::string _accessTokenSecret; 70 | 71 | /// \brief Optional owner information. 72 | std::string _owner; 73 | 74 | /// \brief Optional owner id information. 75 | std::string _ownerId; 76 | }; 77 | 78 | 79 | } } // namespace ofx::Twitter 80 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/OAuth10HTTPClient.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "ofx/HTTP/Client.h" 12 | #include "ofx/HTTP/OAuth10Credentials.h" 13 | #include "ofx/HTTP/OAuth10RequestFilter.h" 14 | 15 | 16 | namespace ofx { 17 | namespace HTTP { 18 | 19 | 20 | /// \brief An OAuth 1.0 compatible base client. 21 | class OAuth10HTTPClient: public Client 22 | { 23 | public: 24 | /// \brief Create a default client. 25 | OAuth10HTTPClient(); 26 | 27 | /// \brief Create a client with the provided credentials. 28 | /// \param credentials OAuth 1.0 credentials. 29 | OAuth10HTTPClient(const OAuth10Credentials& credentials); 30 | 31 | /// \brief Destroy the client. 32 | virtual ~OAuth10HTTPClient(); 33 | 34 | /// \brief Set the OAuth 1.0 credentials. 35 | /// \param credentials OAuth 1.0 credentials. 36 | void setCredentials(const OAuth10Credentials& credentials); 37 | 38 | /// \returns the OAuth 1.0 credentials. 39 | OAuth10Credentials getCredentials() const; 40 | 41 | protected: 42 | virtual void requestFilter(Context& context, 43 | Request& request) const override; 44 | 45 | 46 | private: 47 | /// \brief The request filter. 48 | OAuth10RequestFilter _oAuth10RequestFilter; 49 | 50 | }; 51 | 52 | 53 | } } // namespace ofx::HTTP 54 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/OAuth10RequestFilter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "ofx/HTTP/AbstractClientTypes.h" 12 | #include "ofx/HTTP/OAuth10Credentials.h" 13 | 14 | 15 | namespace ofx { 16 | namespace HTTP { 17 | 18 | 19 | /// \brief An OAuth 1.0 request filter. 20 | class OAuth10RequestFilter: public AbstractRequestFilter 21 | { 22 | public: 23 | /// \brief Create a default OAuth 1.0 request filter. 24 | OAuth10RequestFilter(); 25 | 26 | /// \brief Create a default OAuth 1.0 request filter with credentials. 27 | /// \param credentials The OAuth 1.0 credentials. 28 | OAuth10RequestFilter(const OAuth10Credentials& credentials); 29 | 30 | /// \brief Destroy the request filter. 31 | virtual ~OAuth10RequestFilter(); 32 | 33 | /// \brief Set the 0Auth 1.0 credentials. 34 | /// \param credentials The OAuth 1.0 credentials. 35 | void setCredentials(const OAuth10Credentials& credentials); 36 | 37 | /// \returns The OAuth 1.0 credentials. 38 | OAuth10Credentials getCredentials() const; 39 | 40 | virtual void requestFilter(Context& context, 41 | Request& request) const override; 42 | 43 | private: 44 | /// \brief The OAuth 1.0 credentials used for authentication. 45 | OAuth10Credentials _credentials; 46 | 47 | }; 48 | 49 | 50 | } } // namespace ofx::HTTP 51 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/OAuth20Credentials.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include 12 | #include "ofConstants.h" 13 | #include "json.hpp" 14 | 15 | 16 | namespace ofx { 17 | namespace HTTP { 18 | 19 | 20 | class OAuth20Credentials 21 | { 22 | public: 23 | OAuth20Credentials(); 24 | 25 | OAuth20Credentials(const std::string& bearerToken); 26 | 27 | OAuth20Credentials(const std::string& bearerToken, 28 | const std::string& scheme); 29 | 30 | virtual ~OAuth20Credentials(); 31 | 32 | void setBearerToken(const std::string& bearerToken); 33 | 34 | const std::string& getBearerToken() const; 35 | 36 | void setScheme(const std::string& scheme); 37 | 38 | const std::string& getScheme() const; 39 | 40 | static const std::string SCHEME; 41 | 42 | // static OAuth20Credentials fromJSON(const ofJson& value); 43 | // 44 | // static ofJson toJSON(const OAuth20Credentials& credentials); 45 | // 46 | // static OAuth20Credentials fromFile(const std::filesystem::path& credentialsFile); 47 | // 48 | // static bool toFile(const OAuth20Credentials& credentials, 49 | // const std::string& credentialsFile); 50 | 51 | 52 | private: 53 | /// \brief The OAuth 2.0 bearer token. 54 | std::string _bearerToken; 55 | 56 | /// \brief The OAuth 1.0 scheme. 57 | std::string _scheme; 58 | }; 59 | 60 | 61 | } } // namespace ofx::HTTP 62 | 63 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/OAuth20HTTPClient.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "ofx/HTTP/Client.h" 12 | #include "ofx/HTTP/OAuth20Credentials.h" 13 | #include "ofx/HTTP/OAuth20RequestFilter.h" 14 | 15 | 16 | namespace ofx { 17 | namespace HTTP { 18 | 19 | 20 | /// \brief An OAuth 2.0 compatible base client. 21 | class OAuth20HTTPClient: public Client 22 | { 23 | public: 24 | /// \brief Create a default client. 25 | OAuth20HTTPClient(); 26 | 27 | /// \brief Create a client with the provided credentials. 28 | /// \param credentials OAuth 2.0 credentials. 29 | OAuth20HTTPClient(const OAuth20Credentials& credentials); 30 | 31 | /// \breif Destroy the client. 32 | virtual ~OAuth20HTTPClient(); 33 | 34 | /// \brief Set the OAuth 2.0 credentials. 35 | /// \param credentials OAuth 2.0 credentials. 36 | void setCredentials(const OAuth20Credentials& credentials); 37 | 38 | /// \returns the OAuth 2.0 credentials. 39 | OAuth20Credentials getCredentials() const; 40 | 41 | protected: 42 | virtual void requestFilter(Context& context, 43 | Request& request) const override; 44 | 45 | 46 | private: 47 | /// \brief The request filter. 48 | OAuth20RequestFilter _oAuth20RequestFilter; 49 | 50 | }; 51 | 52 | 53 | } } // namespace ofx::HTTP 54 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/OAuth20RequestFilter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "ofx/HTTP/AbstractClientTypes.h" 12 | #include "ofx/HTTP/OAuth20Credentials.h" 13 | 14 | 15 | namespace ofx { 16 | namespace HTTP { 17 | 18 | 19 | /// \brief An OAuth 2.0 request filter. 20 | class OAuth20RequestFilter: public AbstractRequestFilter 21 | { 22 | public: 23 | /// \brief Create a default OAuth 2.0 request filter. 24 | OAuth20RequestFilter(); 25 | 26 | /// \brief Create a default OAuth 2.0 request filter with credentials. 27 | /// \param credentials The OAuth 2.0 credentials. 28 | OAuth20RequestFilter(const OAuth20Credentials& credentials); 29 | 30 | /// \brief Destroy the request filter. 31 | virtual ~OAuth20RequestFilter(); 32 | 33 | /// \brief Set the 0Auth 2.0 credentials. 34 | /// \param credentials The OAuth 2.0 credentials. 35 | void setCredentials(const OAuth20Credentials& credentials); 36 | 37 | /// \returns The OAuth 2.0 credentials. 38 | OAuth20Credentials getCredentials() const; 39 | 40 | virtual void requestFilter(Context& context, 41 | Request& request) const override; 42 | 43 | private: 44 | /// \brief The OAuth 2.0 credentials used for authentication. 45 | OAuth20Credentials _credentials; 46 | 47 | }; 48 | 49 | 50 | } } // namespace ofx::HTTP 51 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/PostRouteEvents.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakercp/ofxHTTP/fa65775e68a0ef8885a257a5ea055993342721a9/libs/ofxHTTP/include/ofx/HTTP/PostRouteEvents.h -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/Progress.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include 12 | #include 13 | #include "Poco/Timestamp.h" 14 | 15 | 16 | namespace ofx { 17 | namespace HTTP { 18 | 19 | 20 | class Progress 21 | { 22 | public: 23 | Progress(); 24 | 25 | Progress(int64_t totalBytes); 26 | 27 | virtual ~Progress(); 28 | 29 | int64_t getTotalBytesTranferred() const; 30 | 31 | void setTotalBytesTransferred(int64_t totalBytesTransferred); 32 | 33 | int64_t getTotalBytes() const; 34 | 35 | void setTotalBytes(int64_t totalBytes); 36 | 37 | /// \brief Get the progress of the request upload or download. 38 | /// 39 | /// If the total content length is unknown (e.g. during chunked-transfer) 40 | /// that can't be estimated, progress of UNKNOWN_CONTENT_LENGTH will be 41 | /// returned. 42 | /// 43 | /// In cases where the totalBytes cannot be accurately determined, progress 44 | /// values not accurately reflect the actual progress. The user is 45 | /// is encouraged to handle progress values outside of of expected 0-1 46 | /// ranges. 47 | /// 48 | /// In cases where the total bytes are 0, the progress will always return 49 | /// 1.0 indicating completion. 50 | /// 51 | /// \returns a progress value if total bytes are > 0, otherwise UNKNOWN_CONTENT_LENGTH. 52 | float progress() const; 53 | 54 | /// \returns the approximate bytes transferred per second. 55 | float bytesPerSecond() const; 56 | 57 | /// \returns the last updated time. 58 | Poco::Timestamp lastUpdateTime() const; 59 | 60 | Poco::Timestamp startTime() const; 61 | 62 | /// \brief A constant indicating an unknown content length. 63 | static const int64_t UNKNOWN_CONTENT_LENGTH; 64 | 65 | private: 66 | int64_t _totalBytesTransferred = 0; 67 | int64_t _totalBytes = UNKNOWN_CONTENT_LENGTH; 68 | Poco::Timestamp _lastUpdateTime; 69 | Poco::Timestamp _startTime; 70 | 71 | }; 72 | 73 | 74 | } } // namespace ofx::HTTP 75 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/ProxySettings.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include 12 | #include 13 | #include "ofx/HTTP/Credentials.h" 14 | 15 | 16 | namespace ofx { 17 | namespace HTTP { 18 | 19 | 20 | class ProxySettings: public Credentials 21 | { 22 | public: 23 | ProxySettings(); 24 | 25 | ProxySettings(const std::string& host, 26 | uint16_t port); 27 | 28 | ProxySettings(const std::string& username, 29 | const std::string& password, 30 | const std::string& host, 31 | uint16_t port); 32 | 33 | virtual ~ProxySettings(); 34 | 35 | virtual void clear(); 36 | 37 | std::string getHost() const; 38 | void setHost(const std::string& host); 39 | 40 | uint16_t getPort() const; 41 | void setPort(uint16_t port); 42 | 43 | static const std::string DEFAULT_PROXY_HOST; 44 | static const uint16_t DEFAULT_PROXY_PORT; 45 | 46 | protected: 47 | std::string _host; 48 | uint16_t _port; 49 | 50 | }; 51 | 52 | 53 | } } // namespace ofx::HTTP 54 | 55 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/PutRequest.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | #include "ofFileUtils.h" 11 | #include "ofx/HTTP/FormRequest.h" 12 | 13 | 14 | namespace ofx { 15 | namespace HTTP { 16 | 17 | 18 | class PutRequest: public FormRequest 19 | { 20 | public: 21 | /// \brief Construct a PutRequest with a given uri and http version. 22 | /// \param uri the Put endpoint uri. 23 | /// \param httpVersion Either HTTP/1.0 or HTTP/1.1. 24 | PutRequest(const std::string& uri, 25 | const std::string& httpVersion = Poco::Net::HTTPMessage::HTTP_1_1); 26 | 27 | virtual ~PutRequest(); 28 | 29 | /// \brief Set the file to include in the body of the PUT request. 30 | /// \param filename The file to include in the body of the PUT request. 31 | void setPutFile(const std::string& filename); 32 | 33 | /// \brief Set the buffer to include in the body of the PUT request. 34 | /// \param buffer The buffer to include in the body of the PUT request. 35 | void setPutBuffer(const ofBuffer& buffer); 36 | 37 | /// \brief Set the start byte to include in the header of the PUT request. 38 | /// \param startByte The byte number representing the offset of the 39 | /// data included in the body. End byte is assumed to be the end 40 | /// of the resource. 41 | void setContentRange(std::size_t startByte); 42 | 43 | /// \brief Set the start byte to include in the header of the PUT request. 44 | /// \param startByte The byte number representing the offset of the data 45 | /// included in the body. 46 | /// \param endByte The byte number representing the end offset of the data 47 | /// included in the body. 48 | /// \throws InvalidArgumentException if startByte is not less than or equal 49 | /// to endByte. 50 | void setContentRange(std::size_t startByte, 51 | std::size_t endByte); 52 | 53 | /// \brief Set the content type for the put request. 54 | /// 55 | /// The default content type is `application/octet-stream`. 56 | /// 57 | /// \contentType The content type of the PUT request. 58 | void setContentType(const std::string& contentType); 59 | 60 | virtual void prepareRequest() override; 61 | virtual void writeRequestBody(std::ostream& requestStream) override; 62 | 63 | protected: 64 | std::size_t _startByte; 65 | 66 | std::size_t _endByte; 67 | 68 | std::string _contentType; 69 | 70 | ofBuffer _buffer; 71 | 72 | }; 73 | 74 | 75 | } } // namespace ofx::HTTP 76 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/RequestHandlerAdapter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "Poco/Net/HTTPRequestHandler.h" 12 | #include "Poco/Net/HTTPServerRequest.h" 13 | #include "Poco/Net/HTTPServerResponse.h" 14 | #include "ofLog.h" 15 | 16 | 17 | namespace ofx { 18 | namespace HTTP { 19 | 20 | 21 | /// \brief A wrapper class to allow Poco::Net::HTTPRequestHandler to be reused. 22 | /// 23 | // A route handler adapter adapts the factory class (e.g. the BaseRoute_) 24 | // to act as a reusable instance. The instance passed to the RouteHandler 25 | // adapter should not modify the internal state of the route itself. 26 | class RequestHandlerAdapter: public Poco::Net::HTTPRequestHandler 27 | { 28 | public: 29 | /// \brief Create a RequestHandlerAdapter with the given handler reference. 30 | /// \param handler The default RequestHandlerAdapter to use. 31 | RequestHandlerAdapter(Poco::Net::HTTPRequestHandler& handler); 32 | 33 | /// \brief Destroy the RequestHandlerAdapter. 34 | virtual ~RequestHandlerAdapter(); 35 | 36 | virtual void handleRequest(Poco::Net::HTTPServerRequest& request, 37 | Poco::Net::HTTPServerResponse& response) override; 38 | 39 | protected: 40 | /// \brief The the handler to adapt. 41 | Poco::Net::HTTPRequestHandler& _handler; 42 | 43 | }; 44 | 45 | 46 | } } // namespace ofx::HTTP 47 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/SSEConnection.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include 12 | #include 13 | //#include "Poco/Buffer.h" 14 | //#include "Poco/Exception.h" 15 | //#include "Poco/Timespan.h" 16 | //#include "Poco/Net/Socket.h" 17 | //#include "Poco/Net/WebSocket.h" 18 | //#include "Poco/Net/NetException.h" 19 | //#include "ofFileUtils.h" 20 | //#include "ofLog.h" 21 | #include "ofx/HTTP/AbstractServerTypes.h" 22 | #include "ofx/HTTP/HTTPUtils.h" 23 | #include "ofx/HTTP/SSEFrame.h" 24 | #include "ofx/HTTP/SSERoute.h" 25 | 26 | 27 | namespace ofx { 28 | namespace HTTP { 29 | 30 | 31 | /// \brief A class representing a Server Sent Event Source with a single client. 32 | /// 33 | /// Frames can be sent across thread boundaries and are queued for sending 34 | /// during the SSERouteConnection's service loop. All accessors are 35 | /// synchronized and thread-safe. 36 | class SSEConnection: public /*BaseConnection_//*/BaseRouteHandler_ 37 | { 38 | public: 39 | /// \brief Create a SSEConnection. 40 | /// \param route A reference to the parent SSERoute. 41 | SSEConnection(SSERoute& route); 42 | 43 | /// \brief Destroy the SSEConnection. 44 | virtual ~SSEConnection(); 45 | 46 | void handleRequest(ServerEventArgs& evt) override; 47 | 48 | void stop() override; 49 | 50 | /// \brief Queue data to be sent to the client. 51 | /// \param frame The data to send to the client. 52 | /// \param cache True if the frame should be cached. 53 | /// \returns false iff frame was not queued. 54 | bool send(const IndexedSSEFrame& frame) const; 55 | 56 | /// \returns The original http request headers. 57 | Poco::Net::NameValueCollection requestHeaders() const; 58 | 59 | /// \returns the client's SocketAddress. 60 | Poco::Net::SocketAddress clientAddress() const; 61 | 62 | /// \returns true iff this SSEConnection is connected to a client. 63 | bool isConnected() const; 64 | 65 | /// \returns the size of the send queue. 66 | std::size_t sendQueueSize() const; 67 | 68 | /// \brief Clears the send queue. 69 | void clearSendQueue(); 70 | 71 | /// \brief Get the total bytes sent to the client. 72 | /// \returns the total bytes sent to the client. 73 | std::size_t totalBytesSent() const; 74 | 75 | private: 76 | /// \brief The original request headers for reference. 77 | Poco::Net::NameValueCollection _requestHeaders; 78 | 79 | /// \brief The client's SocketAddress for reference. 80 | Poco::Net::SocketAddress _clientAddress; 81 | 82 | /// \brief True iff the SSEConnection is connected to a client. 83 | bool _isConnected = false; 84 | 85 | /// \brief The total number of bytes sent to the client. 86 | std::size_t _totalBytesSent = 0; 87 | 88 | /// \brief A queue of the SSEFrames scheduled for delivery. 89 | mutable std::queue _frameQueue; 90 | 91 | /// \brief A mutex for threadsafe access to the frame queue, etc. 92 | mutable std::mutex _mutex; 93 | 94 | /// \brief A condition for restarting the thread when a frame is ready. 95 | mutable std::condition_variable _condition; 96 | 97 | /// \brief The server sent event content type "text/event-stream". 98 | static const std::string SSE_CONTENT_TYPE; 99 | 100 | /// \brief Event boundary. 101 | static const std::string SSE_EVENT_BOUNDARY; 102 | 103 | }; 104 | 105 | 106 | } } // namespace ofx::HTTP 107 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/SSEEvents.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "ofx/HTTP/ServerEvents.h" 12 | #include "ofx/HTTP/SSEFrame.h" 13 | 14 | 15 | namespace ofx { 16 | namespace HTTP { 17 | 18 | 19 | class SSERouteHandler; 20 | class SSEConnection; 21 | 22 | 23 | /// \brief The base server sent event arguments. 24 | class SSEEventArgs: public ServerEventArgs 25 | { 26 | public: 27 | /// \brief Create a SSEEventArgs object with the provided params. 28 | /// \param args The server event arguments. 29 | /// \param connection A reference to the associated SSEConnection. 30 | SSEEventArgs(ServerEventArgs& args, 31 | SSEConnection& connection): 32 | ServerEventArgs(args), 33 | _connection(connection) 34 | { 35 | } 36 | 37 | /// \returns the associated connection. 38 | SSEConnection& connection() 39 | { 40 | return _connection; 41 | } 42 | 43 | private: 44 | /// \brief A reference to the SSEConnection. 45 | SSEConnection& _connection; 46 | 47 | }; 48 | 49 | 50 | class SSECloseEventArgs: public SSEEventArgs 51 | { 52 | public: 53 | SSECloseEventArgs(ServerEventArgs& evt, 54 | SSEConnection& connection, 55 | uint16_t code, 56 | const std::string& reason): 57 | SSEEventArgs(evt, connection), 58 | _code(code), 59 | _reason(reason) 60 | { 61 | } 62 | 63 | /// \returns A code, 0 if unset. 64 | uint16_t code() const 65 | { 66 | return _code; 67 | } 68 | 69 | /// \returns A UTF-8 encoded client close reason, empty if unset. 70 | const std::string& reason() const 71 | { 72 | return _reason; 73 | } 74 | 75 | protected: 76 | uint16_t _code; 77 | 78 | const std::string& _reason; 79 | 80 | }; 81 | 82 | 83 | class SSEFrameEventArgs: public SSEEventArgs 84 | { 85 | public: 86 | /// \brief Create a SSEFrameEventArgs object. 87 | /// \param args The server event arguments. 88 | /// \param connection A reference to the associated SSEConnection. 89 | /// \param frame The server sent event frame. 90 | SSEFrameEventArgs(ServerEventArgs& args, 91 | SSEConnection& connection, 92 | const SSEFrame& frame): 93 | SSEEventArgs(args, connection), 94 | _frame(frame) 95 | { 96 | } 97 | 98 | /// \returns A const reference to the SSEFrame associated with the event. 99 | const SSEFrame& frame() const 100 | { 101 | return _frame; 102 | } 103 | 104 | private: 105 | /// \brief A reference to the SSEFrame associated with the event. 106 | const SSEFrame& _frame; 107 | 108 | }; 109 | 110 | 111 | /// \brief A typedef for SSEOpenEventArgs. 112 | typedef SSEEventArgs SSEOpenEventArgs; 113 | 114 | 115 | /// \brief A collection of events called by SSEConnections. 116 | class SSEEvents 117 | { 118 | public: 119 | /// \brief An event that is called when an SSE connection is opened. 120 | ofEvent onSSEOpenEvent; 121 | 122 | /// \brief An event that is called when an SSE connection is closed. 123 | ofEvent onSSECloseEvent; 124 | 125 | /// \brief An event that is called when a SSE frame is sent. 126 | ofEvent onSSEFrameSentEvent; 127 | 128 | }; 129 | 130 | 131 | } } // namespace ofx::HTTP 132 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/SSEFrame.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include 12 | #include 13 | #include 14 | #include "ofConstants.h" 15 | 16 | 17 | namespace ofx { 18 | namespace HTTP { 19 | 20 | 21 | /// \brief A SSE frame. 22 | class SSEFrame 23 | { 24 | public: 25 | /// \brief Create a SSEFrame without an event name. 26 | /// \param data The UTF-8 encoded data to send. 27 | SSEFrame(const std::string& data); 28 | 29 | /// \brief Create a SSEFrame with an event name. 30 | /// \param event The UTF-8 encoded event name to send. 31 | /// \param data The UTF-8 encoded data to send. 32 | SSEFrame(const std::string& event, const std::string& data); 33 | 34 | /// \brief Destroy a SSEFrame. 35 | virtual ~SSEFrame(); 36 | 37 | /// \returns the UTF-8 encoded event name or an empty string if unset. 38 | std::string event() const; 39 | 40 | /// \returns the UTF-8 encoded data to be sent. 41 | std::string data() const; 42 | 43 | // /// \brief Return the parsed lines of the text. 44 | // std::vector lines() const; 45 | // 46 | // /// \brief 47 | // std::string sseFormattedData() const; 48 | 49 | protected: 50 | /// \brief The UTF-8 encoded event name or an empty string if unset 51 | std::string _event; 52 | 53 | /// \brief The UTF-8 encoded data to be sent. 54 | std::string _data; 55 | 56 | }; 57 | 58 | 59 | /// \brief An indexed SSE frame for caching and playback purposes. 60 | class IndexedSSEFrame 61 | { 62 | public: 63 | /// \brief Create an indexed SSE frame. 64 | /// \param frame The frame to cache. 65 | /// \param index The index of the frame. 66 | IndexedSSEFrame(const SSEFrame& frame, uint64_t index); 67 | 68 | /// \returns a const reference to the indexed frame. 69 | const SSEFrame& frame() const; 70 | 71 | /// \returns the index of the frame. 72 | uint64_t index() const; 73 | 74 | enum 75 | { 76 | // 77 | NOT_INDEXED = std::numeric_limits::max() 78 | }; 79 | 80 | private: 81 | /// The indexed frame. 82 | SSEFrame _frame; 83 | 84 | /// \brief The index of the frame. 85 | uint64_t _index = NOT_INDEXED; 86 | 87 | }; 88 | 89 | 90 | } } // namespace ofx::HTTP 91 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/ServerEvents.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "Poco/UUID.h" 12 | #include "Poco/Net/MediaType.h" 13 | #include "Poco/Net/NameValueCollection.h" 14 | #include "Poco/Net/HTTPResponse.h" 15 | #include "Poco/Net/HTTPServerRequest.h" 16 | #include "ofEvents.h" 17 | #include "ofx/HTTP/AbstractServerTypes.h" 18 | 19 | 20 | namespace ofx { 21 | namespace HTTP { 22 | 23 | 24 | /// \brief An event describing a server request. 25 | class ServerEventArgs: public ofEventArgs 26 | { 27 | public: 28 | /// \brief Construct the ServerEventArgs. 29 | /// \param request the Poco::Net::HTTPServerRequest. 30 | /// \param response the Poco::Net::HTTPServerResponse. 31 | /// \param session The AbstractSession associated with this event. 32 | ServerEventArgs(Poco::Net::HTTPServerRequest& request, 33 | Poco::Net::HTTPServerResponse& response, 34 | AbstractSession& session): 35 | _request(request), 36 | _response(response), 37 | _session(session) 38 | { 39 | } 40 | 41 | /// \brief Destroy the ServerEventArgs. 42 | virtual ~ServerEventArgs() 43 | { 44 | } 45 | 46 | /// \brief Get the Poco::Net::HTTPServerRequest. 47 | /// \return the Poco::Net::HTTPServerRequest. 48 | Poco::Net::HTTPServerRequest& request() 49 | { 50 | return _request; 51 | } 52 | 53 | /// \brief Get the Poco::Net::HTTPServerResponse. 54 | /// \return the Poco::Net::HTTPServerResponse. 55 | Poco::Net::HTTPServerResponse& response() 56 | { 57 | return _response; 58 | } 59 | 60 | /// \brief Get the session associated with this event. 61 | /// \returns the session associated with this event. 62 | AbstractSession& session() 63 | { 64 | return _session; 65 | } 66 | 67 | protected: 68 | /// \brief A reference to the server request. 69 | Poco::Net::HTTPServerRequest& _request; 70 | 71 | /// \brief Callbacks are permitted to set the response. 72 | /// 73 | /// \warning Before working with the response, the callback must check the 74 | /// HTTPServerResponse::sent() method to ensure that the response stream 75 | /// is still available available. 76 | Poco::Net::HTTPServerResponse& _response; 77 | 78 | /// \brief The session associated with the event. 79 | AbstractSession& _session; 80 | 81 | }; 82 | 83 | 84 | /// \brief A class describing a set of low level HTTP server events. 85 | class ServerEvents 86 | { 87 | public: 88 | /// \brief The onHTTPServerEvent event. 89 | ofEvent onHTTPServerEvent; 90 | 91 | }; 92 | 93 | 94 | } } // namespace ofx::HTTP 95 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/Session.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include 12 | #include 13 | #include "ofx/HTTP/AbstractServerTypes.h" 14 | #include "Poco/Mutex.h" 15 | #include "ofEvents.h" 16 | 17 | 18 | namespace ofx { 19 | namespace HTTP { 20 | 21 | 22 | class BaseSession: public AbstractSession 23 | { 24 | public: 25 | BaseSession(const std::string sessionId = generateId()); 26 | 27 | virtual ~BaseSession(); 28 | 29 | std::string getId() const override; 30 | 31 | /// \brief A utility function for generating unique session ids. 32 | /// \returns A unique session id string. 33 | static std::string generateId(); 34 | 35 | static const std::string KEY_LAST_MODIFIED; 36 | 37 | protected: 38 | BaseSession(const BaseSession&); 39 | BaseSession& operator = (const BaseSession&); 40 | 41 | std::string _sessionId; 42 | 43 | mutable std::mutex _mutex; 44 | 45 | }; 46 | 47 | 48 | 49 | /// \brief A client cookie-based session store for servers. 50 | /// 51 | /// Client sessions are tracked via cookie. Server routes can access the session 52 | /// store and associate any information with the client's session. 53 | class SimpleSession: public BaseSession 54 | { 55 | public: 56 | SimpleSession(const std::string& sessionId = generateId()); 57 | 58 | virtual ~SimpleSession(); 59 | 60 | bool has(const std::string& key) const override; 61 | 62 | void put(const std::string& key, const std::string& value) override; 63 | 64 | std::string get(const std::string& key, 65 | const std::string& defaultValue) const override; 66 | 67 | std::string get(const std::string& key) const override; 68 | 69 | void remove(const std::string& key) override; 70 | 71 | void clear() override; 72 | 73 | protected: 74 | SimpleSession(const SimpleSession&); 75 | SimpleSession& operator = (const SimpleSession&); 76 | 77 | std::map _sessionDict; 78 | 79 | }; 80 | 81 | 82 | } } // namespace ofx::HTTP 83 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/SessionStore.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include 12 | #include 13 | #include "Poco/Mutex.h" 14 | #include "ofTypes.h" 15 | #include "ofx/HTTP/AbstractServerTypes.h" 16 | 17 | 18 | namespace ofx { 19 | namespace HTTP { 20 | 21 | 22 | class BaseSessionStore: public AbstractSessionStore 23 | { 24 | public: 25 | BaseSessionStore(); 26 | 27 | BaseSessionStore(const std::string& sessionKeyName); 28 | 29 | virtual ~BaseSessionStore(); 30 | 31 | AbstractSession& getSession(Poco::Net::HTTPServerRequest& request, 32 | Poco::Net::HTTPServerResponse& response); 33 | 34 | void destroySession(Poco::Net::HTTPServerRequest& request, 35 | Poco::Net::HTTPServerResponse& response); 36 | 37 | static const std::string DEFAULT_SESSION_KEY_NAME; 38 | 39 | protected: 40 | virtual bool hasSession(const std::string& sessionId) const = 0; 41 | virtual AbstractSession& getSession(const std::string& sessionId) = 0; 42 | virtual AbstractSession& createSession() = 0; 43 | virtual void destroySession(const std::string& sessionId) = 0; 44 | 45 | const std::string _sessionKeyName; 46 | 47 | private: 48 | BaseSessionStore(const BaseSessionStore&); 49 | BaseSessionStore& operator = (const BaseSessionStore&); 50 | 51 | }; 52 | 53 | 54 | /// \brief An in-memory session store. 55 | class SimpleSessionStore: public BaseSessionStore 56 | { 57 | public: 58 | SimpleSessionStore(); 59 | 60 | SimpleSessionStore(const std::string& sessionKeyName); 61 | 62 | virtual ~SimpleSessionStore(); 63 | 64 | protected: 65 | SimpleSessionStore(const SimpleSessionStore&); 66 | SimpleSessionStore& operator = (const SimpleSessionStore&); 67 | 68 | bool hasSession(const std::string& sessionId) const override; 69 | AbstractSession& getSession(const std::string& sessionId) override; 70 | AbstractSession& createSession() override; 71 | void destroySession(const std::string& sessionId) override; 72 | 73 | typedef std::map> SessionMap; 74 | 75 | SessionMap _sessionMap; 76 | 77 | mutable std::mutex _mutex; 78 | 79 | }; 80 | 81 | 82 | } } // namespace ofx::HTTP 83 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/SimpleClient.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "ofJson.h" 12 | #include "ofx/HTTP/Client.h" 13 | 14 | 15 | namespace ofx { 16 | namespace HTTP { 17 | 18 | 19 | /// \brief A Simple HTTP cient. 20 | class SimpleClient: public Client 21 | { 22 | public: 23 | using Client::Client; 24 | 25 | /// \brief Destroy the SimpleClient. 26 | virtual ~SimpleClient(); 27 | 28 | /// \brief GET data from the given URI. 29 | /// \param uri The endpoint URI. 30 | /// \returns a buffered response. 31 | // std::unique_ptr> get(const std::string& uri); 32 | 33 | }; 34 | 35 | 36 | } } // namespace ofx::HTTP 37 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/SimpleFileServer.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "ofx/HTTP/BaseServer.h" 12 | #include "ofx/HTTP/FileSystemRoute.h" 13 | 14 | 15 | namespace ofx { 16 | namespace HTTP { 17 | 18 | 19 | /// \brief Settings for a SimpleFileServer. 20 | class SimpleFileServerSettings: public BaseServerSettings 21 | { 22 | public: 23 | /// \brief File system route settings. 24 | FileSystemRouteSettings fileSystemRouteSettings; 25 | }; 26 | 27 | 28 | /// \brief A simple file server implementation. 29 | class SimpleFileServer: public BaseServer_ 30 | { 31 | public: 32 | /// \brief A typedef for the SimpleFileServerSettings. 33 | typedef SimpleFileServerSettings Settings; 34 | 35 | /// \brief Create a SimpleFileServer with the provided Settings. 36 | /// \param settings The Settings used to configure the server. 37 | SimpleFileServer(const Settings& settings = Settings()); 38 | 39 | /// \brief Destroy the BasicServer. 40 | virtual ~SimpleFileServer(); 41 | 42 | virtual void setup(const Settings& settings) override; 43 | 44 | /// \return A reference to the file system route. 45 | FileSystemRoute& fileSystemRoute(); 46 | 47 | protected: 48 | /// \brief The FileSystemRoute attached to this server. 49 | FileSystemRoute _fileSystemRoute; 50 | 51 | }; 52 | 53 | 54 | } } // namespace ofx::HTTP 55 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/SimpleIPVideoServer.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "ofx/HTTP/BaseServer.h" 12 | #include "ofx/HTTP/FileSystemRoute.h" 13 | #include "ofx/HTTP/IPVideoRoute.h" 14 | #include "ofx/HTTP/PostRoute.h" 15 | 16 | 17 | namespace ofx { 18 | namespace HTTP { 19 | 20 | 21 | /// \brief Settings for a SimpleIPVideoServer. 22 | class SimpleIPVideoServerSettings: public BaseServerSettings 23 | { 24 | public: 25 | /// \brief File system route settings. 26 | FileSystemRouteSettings fileSystemRouteSettings; 27 | 28 | /// \brief Post route settings. 29 | PostRouteSettings postRouteSettings; 30 | 31 | /// \brief IPVideo route settings. 32 | IPVideoRouteSettings ipVideoRouteSettings; 33 | }; 34 | 35 | 36 | /// \brief A simple MJPEG-based IPVideo server implementation. 37 | class SimpleIPVideoServer: public BaseServer_ 38 | { 39 | public: 40 | /// \brief A typedef for the SimpleIPVideoServerSettings. 41 | typedef SimpleIPVideoServerSettings Settings; 42 | 43 | /// \brief Create a SimpleIPVideoServer with the given settings. 44 | /// \param settings the server settings. 45 | SimpleIPVideoServer(const Settings& settings = Settings()); 46 | 47 | /// \brief Destroy the simeple IP Video Server. 48 | virtual ~SimpleIPVideoServer(); 49 | 50 | virtual void setup(const Settings& settings) override; 51 | 52 | /// \brief Submit the pixels to send. 53 | /// \param pixels The pixels to send. 54 | void send(const ofPixels& pixels); 55 | 56 | /// \returns the number of clicents that are currently connected. 57 | std::size_t numConnections() const; 58 | 59 | /// \returns A reference to the file system route. 60 | FileSystemRoute& fileSystemRoute(); 61 | 62 | /// \returns A reference to the post route. 63 | PostRoute& postRoute(); 64 | 65 | /// \returns A reference to the IPVideo route. 66 | IPVideoRoute& ipVideoRoute(); 67 | 68 | protected: 69 | /// \brief The FileSystemRoute attached to this server. 70 | FileSystemRoute _fileSystemRoute; 71 | 72 | /// \brief The PostRoute attached to this server. 73 | PostRoute _postRoute; 74 | 75 | /// \brief THe IPVideo route attached to this server. 76 | IPVideoRoute _ipVideoRoute; 77 | 78 | }; 79 | 80 | 81 | } } // namespace ofx::HTTP 82 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/SimplePostServer.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "ofx/HTTP/SimpleFileServer.h" 12 | #include "ofx/HTTP/PostRoute.h" 13 | #include "ofx/HTTP/PostRouteEvents.h" 14 | 15 | 16 | namespace ofx { 17 | namespace HTTP { 18 | 19 | 20 | /// \brief Settings for a SimplePostServer. 21 | class SimplePostServerSettings: public BaseServerSettings 22 | { 23 | public: 24 | /// \brief File system route settings. 25 | FileSystemRouteSettings fileSystemRouteSettings; 26 | 27 | /// \brief Post route settings. 28 | PostRouteSettings postRouteSettings; 29 | 30 | }; 31 | 32 | 33 | class SimplePostServer: 34 | public BaseServer_ 35 | { 36 | public: 37 | typedef SimplePostServerSettings Settings; 38 | 39 | SimplePostServer(const Settings& settings = Settings()); 40 | 41 | virtual ~SimplePostServer(); 42 | 43 | virtual void setup(const Settings& settings) override; 44 | 45 | /// \return A reference to the file system route. 46 | FileSystemRoute& fileSystemRoute(); 47 | 48 | PostRoute& postRoute(); 49 | 50 | protected: 51 | /// \brief The FileSystemRoute attached to this server. 52 | FileSystemRoute _fileSystemRoute; 53 | 54 | PostRoute _postRoute; 55 | 56 | }; 57 | 58 | 59 | } } // namespace ofx::HTTP 60 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/SimpleSSEServer.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "ofx/HTTP/BaseServer.h" 12 | #include "ofx/HTTP/FileSystemRoute.h" 13 | #include "ofx/HTTP/SSERoute.h" 14 | 15 | 16 | namespace ofx { 17 | namespace HTTP { 18 | 19 | 20 | /// \brief Aggregate settings for a SimpleSSEServer. 21 | class SimpleSSEServerSettings: public BaseServerSettings 22 | { 23 | public: 24 | /// \brief File system route settings. 25 | FileSystemRouteSettings fileSystemRouteSettings; 26 | 27 | /// \brief Server sent event route settings. 28 | SSERouteSettings sseRouteSettings; 29 | 30 | }; 31 | 32 | 33 | /// \brief A basic implementation of an HTTP Server supporting server sent events. 34 | class SimpleSSEServer: public BaseServer_ 35 | { 36 | public: 37 | /// \brief A typedef for the SimpleSSEServerSettings. 38 | typedef SimpleSSEServerSettings Settings; 39 | 40 | /// \brief Create a SimpleSSEServer with the provided Settings. 41 | /// \param settings The Settings used to configure the server. 42 | SimpleSSEServer(const Settings& settings = Settings()); 43 | 44 | /// \brief Destroy the SimpleSSEServer. 45 | virtual ~SimpleSSEServer(); 46 | 47 | virtual void setup(const Settings& settings) override; 48 | 49 | /// \returns the file system route. 50 | FileSystemRoute& fileSystemRoute(); 51 | 52 | /// \returns the SSERoute attached to this server. 53 | SSERoute& sseRoute(); 54 | 55 | private: 56 | /// \brief The FileSystemRoute attached to this server. 57 | FileSystemRoute _fileSystemRoute; 58 | 59 | /// \brief The SSERoute attached to this server. 60 | SSERoute _sseRoute; 61 | 62 | }; 63 | 64 | 65 | } } // namespace ofx::HTTP 66 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/SimpleWebSocketServer.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "ofx/HTTP/BaseServer.h" 12 | #include "ofx/HTTP/FileSystemRoute.h" 13 | #include "ofx/HTTP/WebSocketRoute.h" 14 | 15 | 16 | namespace ofx { 17 | namespace HTTP { 18 | 19 | 20 | /// \brief Aggregate settings for a SimpleWebSocketServer. 21 | class SimpleWebSocketServerSettings: public BaseServerSettings 22 | { 23 | public: 24 | /// \brief File system route settings. 25 | FileSystemRouteSettings fileSystemRouteSettings; 26 | 27 | /// \brief Web Socket route settings. 28 | WebSocketRouteSettings webSocketRouteSettings; 29 | 30 | }; 31 | 32 | 33 | /// \brief A basic implementation of an HTTP Server supporting WebSockets. 34 | class SimpleWebSocketServer: public BaseServer_ 35 | { 36 | public: 37 | /// \brief A typedef for the SimpleWebSocketServerSettings. 38 | typedef SimpleWebSocketServerSettings Settings; 39 | 40 | /// \brief Create a SimpleWebSocketServer with the provided Settings. 41 | /// \param settings The Settings used to configure the server. 42 | SimpleWebSocketServer(const Settings& settings = Settings()); 43 | 44 | /// \brief Destroy the SimpleWebSocketServer. 45 | virtual ~SimpleWebSocketServer(); 46 | 47 | virtual void setup(const Settings& settings) override; 48 | 49 | /// \return A reference to the file system route. 50 | FileSystemRoute& fileSystemRoute(); 51 | 52 | /// \returns the WebSocketRoute attached to this server. 53 | WebSocketRoute& webSocketRoute(); 54 | 55 | private: 56 | /// \brief The FileSystemRoute attached to this server. 57 | FileSystemRoute _fileSystemRoute; 58 | 59 | /// \brief The WebSocketRoute attached to this server. 60 | WebSocketRoute _webSocketRoute; 61 | 62 | }; 63 | 64 | 65 | } } // namespace ofx::HTTP 66 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/ThreadErrorHandler.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "ofLog.h" 12 | #include "Poco/ErrorHandler.h" 13 | 14 | 15 | /// \brief A ThreadErrorHandler to implement in-thread exception handling. 16 | class ThreadErrorHandler: public Poco::ErrorHandler 17 | { 18 | public: 19 | ThreadErrorHandler(const std::string& threadName = "NONE"): 20 | _threadName(threadName) 21 | { 22 | } 23 | 24 | virtual ~ThreadErrorHandler() 25 | { 26 | } 27 | 28 | void exception(const Poco::Exception& exc) 29 | { 30 | ofLogError("ofThreadErrorHandler::exception") << "Uncaught thread exception: " << exc.displayText(); 31 | } 32 | 33 | void exception(const std::exception& exc) 34 | { 35 | ofLogError("ofThreadErrorHandler::exception") << "Uncaught thread exception: " << exc.what(); 36 | } 37 | 38 | void exception() 39 | { 40 | ofLogError("ofThreadErrorHandler::exception") << "Uncaught thread exception: Unknown exception."; 41 | } 42 | 43 | void setThreadName(const std::string& threadName) 44 | { 45 | _threadName = threadName; 46 | } 47 | 48 | std::string getThreadName() const 49 | { 50 | return _threadName; 51 | } 52 | 53 | private: 54 | std::string _threadName; 55 | 56 | }; 57 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/ThreadSettings.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include 12 | #include "Poco/Thread.h" 13 | 14 | 15 | namespace ofx { 16 | namespace HTTP { 17 | 18 | 19 | class ThreadSettings 20 | { 21 | public: 22 | ThreadSettings(const std::string& name = "default", 23 | const Poco::Thread::Priority& priority = Poco::Thread::PRIO_NORMAL); 24 | 25 | virtual ~ThreadSettings(); 26 | 27 | std::string getName() const; 28 | void setName(const std::string& name); 29 | Poco::Thread::Priority getPriority() const; 30 | void setPriority(const Poco::Thread::Priority& priority); 31 | 32 | protected: 33 | std::string _name; 34 | Poco::Thread::Priority _priority; 35 | 36 | }; 37 | 38 | 39 | } } // namespace ofx::HTTP 40 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/URIBuilder.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include "Poco/URI.h" 16 | #include "Poco/Net/HTMLForm.h" 17 | #include "ofUtils.h" 18 | 19 | 20 | namespace ofx { 21 | namespace HTTP { 22 | 23 | 24 | /// \brief A base utility for building URIs. 25 | class URIBuilder: public Poco::Net::NameValueCollection 26 | { 27 | public: 28 | /// \brief Construct an empty URI. 29 | URIBuilder(); 30 | 31 | /// \brief Construct a URI using a base URI. 32 | /// \param uri A base URI. Query parameters will be extracted. 33 | URIBuilder(const Poco::URI& uri); 34 | 35 | /// \brief Destroy the URIBuilder. 36 | virtual ~URIBuilder(); 37 | 38 | /// \brief Set a boolean key / value pair in the name value collection. 39 | /// \param key The key. 40 | /// \param value The boolean value. 41 | /// \param numerical if true, will set the value as a "1" or "0", 42 | /// otherwise will set the value as a "true" or "false". 43 | void set(const std::string& key, bool value, bool numerical = true); 44 | 45 | /// \brief Add a boolean key / value pair in the name value collection. 46 | /// \param key The key. 47 | /// \param value The boolean value. 48 | /// \param numerical if true, will set the value as a "1" or "0", 49 | /// otherwise will set the value as a "true" or "false". 50 | void add(const std::string& key, bool value, bool numerical = true); 51 | 52 | /// \brief Set an key / value pair in the name value collection. 53 | /// 54 | /// This method converts the value to a string if possible. 55 | /// 56 | /// \param key The key. 57 | /// \param value The value. 58 | /// \tparam T The type to set. 59 | template 60 | void set(const std::string& key, const T& value) 61 | { 62 | Poco::Net::NameValueCollection::set(key, ofToString(value)); 63 | } 64 | 65 | /// \brief Set an key / value pair in the name value collection. 66 | /// 67 | /// This method converts the value to a string if possible. 68 | /// 69 | /// \param key The key. 70 | /// \param value The value. 71 | /// \tparam T The type to set. 72 | template 73 | void set(const std::string& key, const T& value, int preceision) 74 | { 75 | Poco::Net::NameValueCollection::set(key, ofToString(value, preceision)); 76 | } 77 | 78 | /// \brief Add an key / value pair in the name value collection. 79 | /// 80 | /// This method converts the value to a string if possible. 81 | /// 82 | /// \param key The key. 83 | /// \param value The boolean value. 84 | /// otherwise will set the value as a "true" or "false". 85 | /// \tparam T The type to set. 86 | template 87 | void add(const std::string& key, const T& value) 88 | { 89 | Poco::Net::NameValueCollection::set(key, ofToString(value)); 90 | } 91 | 92 | /// \tparam T The type to set. 93 | template 94 | void add(const std::string& key, const T& value, int preceision) 95 | { 96 | Poco::Net::NameValueCollection::set(key, ofToString(value, preceision)); 97 | } 98 | 99 | /// \brief Get the built URI as a Poco::URI object. 100 | /// \returns the built URI. 101 | Poco::URI toURI() const; 102 | 103 | /// \brief Get the built URI as a std::string. 104 | /// \returns the built URI as a std::string. 105 | std::string toString() const; 106 | 107 | private: 108 | /// \brief The Poco::URI used as a building foundation. 109 | Poco::URI _uri; 110 | 111 | }; 112 | 113 | 114 | } } // namespace ofx::HTTP 115 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/WebSocketExtensions.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include 12 | #if defined(POCO_UNBUNDLED) 13 | #include 14 | #else 15 | #include "Poco/zlib.h" 16 | #endif 17 | #include "Poco/Buffer.h" 18 | #include "ofx/HTTP/AbstractServerTypes.h" 19 | #include "ofx/HTTP/WebSocketFrame.h" 20 | 21 | 22 | namespace ofx { 23 | namespace HTTP { 24 | 25 | 26 | /// \brief A filter factory for per-message WebSocket compression. 27 | /// \note This is experimental and may not be fully RFC7692-compliant. 28 | /// \sa https://tools.ietf.org/html/rfc7692 29 | class WebSocketPerMessageCompressionFactory: public AbstractWebSocketFilterFactory 30 | { 31 | public: 32 | /// \brief Create a WebSocketPerMessageCompressionFactory extension. 33 | WebSocketPerMessageCompressionFactory(); 34 | 35 | /// \brief Destroy a WebSocketPerMessageCompressionFactory. 36 | virtual ~WebSocketPerMessageCompressionFactory(); 37 | 38 | std::unique_ptr makeFilterForRequest(ServerEventArgs& evt) const override; 39 | 40 | }; 41 | 42 | 43 | /// \brief A WebSocketFilter for per-message compression. 44 | class WebSocketPerMessageCompressionFilter: public AbstractWebSocketFilter 45 | { 46 | public: 47 | WebSocketPerMessageCompressionFilter(); 48 | virtual ~WebSocketPerMessageCompressionFilter(); 49 | 50 | void receiveFilter(WebSocketFrame& frame) override; 51 | void sendFilter(WebSocketFrame& frame) override; 52 | 53 | private: 54 | enum 55 | { 56 | BUFFER_SIZE = 32768, 57 | MIN_WINDOW_BITS = 8, 58 | MAX_WINDOW_BITS = 15 59 | }; 60 | 61 | int _deflateWindowBits = 15; 62 | int _deflateMemLevel = 8; 63 | 64 | int _inflateWindowBits = 15; 65 | 66 | //bool _noContextTakeover = false; 67 | 68 | z_stream _deflateState; 69 | z_stream _inflateState; 70 | 71 | uint8_t* _buffer; 72 | 73 | }; 74 | 75 | 76 | } } // namespace ofx::HTTP 77 | -------------------------------------------------------------------------------- /libs/ofxHTTP/include/ofx/HTTP/WebSocketFrame.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "Poco/Net/WebSocket.h" 12 | #include "ofx/IO/ByteBuffer.h" 13 | #include "ofFileUtils.h" 14 | 15 | 16 | namespace ofx { 17 | namespace HTTP { 18 | 19 | 20 | /// \brief A WebSocketFrame frame. 21 | class WebSocketFrame: public IO::ByteBuffer 22 | { 23 | public: 24 | /// \brief Create a WebSocketFrame. 25 | WebSocketFrame(int flags = Poco::Net::WebSocket::FRAME_TEXT); 26 | 27 | /// \brief Create a WebSocketFrame. 28 | WebSocketFrame(const IO::ByteBuffer& buffer, 29 | int flags = Poco::Net::WebSocket::FRAME_TEXT); 30 | 31 | /// \brief Create a WebSocketFrame. 32 | WebSocketFrame(const ofBuffer& buffer, 33 | int flags = Poco::Net::WebSocket::FRAME_TEXT); 34 | 35 | /// \brief Create a WebSocketFrame. 36 | WebSocketFrame(const std::string& text, 37 | int flags = Poco::Net::WebSocket::FRAME_TEXT); 38 | 39 | /// \brief Create a WebSocketFrame. 40 | WebSocketFrame(const char* buffer, 41 | std::size_t size, 42 | int flags = Poco::Net::WebSocket::FRAME_TEXT); 43 | 44 | /// \brief Create a WebSocketFrame. 45 | WebSocketFrame(const unsigned char* buffer, 46 | std::size_t size, 47 | int flags = Poco::Net::WebSocket::FRAME_TEXT); 48 | 49 | /// \brief Destroy a WebSocketFrame. 50 | virtual ~WebSocketFrame(); 51 | 52 | /// \returns the WebSocketFrame flags. 53 | int flags() const; 54 | 55 | /// \returns true iff a continuation frame. 56 | bool isContinuation() const; 57 | 58 | /// \returns true iff a text frame. 59 | bool isText() const; 60 | 61 | /// \returns true iff a binary frame. 62 | bool isBinary() const; 63 | 64 | /// \returns true iff a close frame. 65 | bool isClose() const; 66 | 67 | /// \returns true iff a ping frame. 68 | bool isPing() const; 69 | 70 | /// \returns true iff a pong frame. 71 | bool isPong() const; 72 | 73 | /// \returns true iff a final frame. 74 | bool isFinal() const; 75 | 76 | /// \brief Set the FIN bit. 77 | /// \param value The bit's value. 78 | void setFinal(bool value); 79 | 80 | /// \returns true iff a RSV1 frame. 81 | bool isRSV1() const; 82 | 83 | /// \brief Set the RSV1 bit. 84 | /// \param value The bit's value. 85 | void setRSV1(bool value); 86 | 87 | /// \returns true iff a RSV2 frame. 88 | bool isRSV2() const; 89 | 90 | /// \brief Set the RSV2 bit. 91 | /// \param value The bit's value. 92 | void setRSV2(bool value); 93 | 94 | /// \returns true iff a RSV3 frame. 95 | bool isRSV3() const; 96 | 97 | /// \brief Set the RSV3 bit. 98 | /// \param value The bit's value. 99 | void setRSV3(bool value); 100 | 101 | /// \returns a string representing the WebSocketFrame. 102 | std::string toString() const; 103 | 104 | protected: 105 | /// \brief the websocket flags for this frame. 106 | int _flags; 107 | 108 | }; 109 | 110 | 111 | } } // namespace ofx::HTTP 112 | -------------------------------------------------------------------------------- /libs/ofxHTTP/src/BaseRoute.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofx/HTTP/BaseRoute.h" 9 | 10 | 11 | namespace ofx { 12 | namespace HTTP { 13 | 14 | 15 | const std::string BaseRouteSettings::DEFAULT_ROUTE_PATH_PATTERN = "/.*"; 16 | 17 | 18 | BaseRouteSettings::BaseRouteSettings(const std::string& routePathPattern, 19 | bool requireSecurePort, 20 | bool requireAuthentication, 21 | const HTTPMethodSet& validHTTPMethods): 22 | _routePathPattern(routePathPattern), 23 | _requireSecurePort(requireSecurePort), 24 | _requireAuthentication(requireAuthentication), 25 | _validHTTPMethods(validHTTPMethods) 26 | { 27 | } 28 | 29 | 30 | BaseRouteSettings::~BaseRouteSettings() 31 | { 32 | } 33 | 34 | 35 | void BaseRouteSettings::setRoutePathPattern(const std::string& routePathPattern) 36 | { 37 | _routePathPattern = routePathPattern; 38 | } 39 | 40 | 41 | const std::string& BaseRouteSettings::getRoutePathPattern() const 42 | { 43 | return _routePathPattern; 44 | } 45 | 46 | 47 | void BaseRouteSettings::setRequireSecurePort(bool requireSecurePort) 48 | { 49 | _requireSecurePort = requireSecurePort; 50 | } 51 | 52 | 53 | bool BaseRouteSettings::requireSecurePort() const 54 | { 55 | return _requireSecurePort; 56 | } 57 | 58 | 59 | void BaseRouteSettings::setRequireAuthentication(bool requireAuthentication) 60 | { 61 | _requireAuthentication = requireAuthentication; 62 | } 63 | 64 | 65 | bool BaseRouteSettings::requireAuthentication() const 66 | { 67 | return _requireAuthentication; 68 | } 69 | 70 | 71 | void BaseRouteSettings::setValidHTTPMethods(const BaseRouteSettings::HTTPMethodSet& validHTTPMethods) 72 | { 73 | _validHTTPMethods = validHTTPMethods; 74 | } 75 | 76 | 77 | const BaseRouteSettings::HTTPMethodSet& BaseRouteSettings::getValidHTTPMethods() const 78 | { 79 | return _validHTTPMethods; 80 | } 81 | 82 | 83 | void BaseRouteSettings::setValidContentTypes(const MediaTypeSet& validContentTypes) 84 | { 85 | _validContentTypes = validContentTypes; 86 | } 87 | 88 | 89 | const BaseRouteSettings::MediaTypeSet& BaseRouteSettings::getValidContentTypes() const 90 | { 91 | return _validContentTypes; 92 | } 93 | 94 | 95 | } } // namespace ofx::HTTP 96 | -------------------------------------------------------------------------------- /libs/ofxHTTP/src/ClientCache.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofx/HTTP/ClientCache.h" 9 | 10 | 11 | namespace ofx { 12 | namespace HTTP { 13 | 14 | 15 | 16 | SQLiteClientCacheStorage::~SQLiteClientCacheStorage() 17 | { 18 | } 19 | 20 | 21 | void SQLiteClientCacheStorage::put(const std::string& key, ClientCacheEntry value) 22 | { 23 | // noop 24 | } 25 | 26 | 27 | ClientCacheEntry SQLiteClientCacheStorage::get(const std::string& key) 28 | { 29 | return ClientCacheEntry(); 30 | } 31 | 32 | 33 | void SQLiteClientCacheStorage::remove(const std::string& key) 34 | { 35 | // noop 36 | } 37 | 38 | 39 | void SQLiteClientCacheStorage::update(const std::string& key) 40 | { 41 | // noop 42 | } 43 | 44 | 45 | } } // namespace ofx::HTTP 46 | -------------------------------------------------------------------------------- /libs/ofxHTTP/src/ClientState.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofx/HTTP/ClientState.h" 9 | #include 10 | 11 | 12 | namespace ofx { 13 | namespace HTTP { 14 | 15 | 16 | const std::map CLIENT_STATE_STRINGS = { 17 | { ClientState::NONE, "NONE" }, 18 | { ClientState::DETECTING_PROXY, "DETECTING_PROXY" }, 19 | { ClientState::RESOLVING_NAME, "RESOLVING_NAME" }, 20 | { ClientState::CONNECTING_TO_SERVER, "CONNECTING_TO_SERVER" }, 21 | { ClientState::NEGOTIATING_SSL, "NEGOTIATING_SSL" }, 22 | { ClientState::SENDING_HEADERS, "SENDING_HEADERS" }, 23 | { ClientState::SENDING_CONTENTS, "SENDING_CONTENTS" }, 24 | { ClientState::WAITING_FOR_RESPONSE, "WAITING_FOR_RESPONSE" }, 25 | { ClientState::RECEIVING_HEADERS, "RECEIVING_HEADERS" }, 26 | { ClientState::RECEIVING_CONTENTS, "RECEIVING_CONTENTS" }, 27 | { ClientState::REDIRECTING, "REDIRECTING" } 28 | }; 29 | 30 | 31 | std::string to_string(ClientState state) 32 | { 33 | return CLIENT_STATE_STRINGS.at(state); 34 | } 35 | 36 | 37 | bool from_string(const std::string text, ClientState& state) 38 | { 39 | for (const auto& entry: CLIENT_STATE_STRINGS) 40 | { 41 | if (text == entry.second) 42 | { 43 | state = entry.first; 44 | return true; 45 | } 46 | } 47 | 48 | state = ClientState::NONE; 49 | return false; 50 | } 51 | 52 | 53 | } } // namespace ofx::HTTP 54 | -------------------------------------------------------------------------------- /libs/ofxHTTP/src/Context.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakercp/ofxHTTP/fa65775e68a0ef8885a257a5ea055993342721a9/libs/ofxHTTP/src/Context.cpp -------------------------------------------------------------------------------- /libs/ofxHTTP/src/Credentials.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofx/HTTP/Credentials.h" 9 | 10 | 11 | namespace ofx { 12 | namespace HTTP { 13 | 14 | 15 | Credentials::Credentials() 16 | { 17 | } 18 | 19 | 20 | Credentials::Credentials(const std::string& username, 21 | const std::string& password): 22 | _username(username), 23 | _password(password) 24 | { 25 | } 26 | 27 | 28 | Credentials::~Credentials() 29 | { 30 | } 31 | 32 | 33 | void Credentials::clear() 34 | { 35 | _username.clear(); 36 | _password.clear(); 37 | } 38 | 39 | 40 | std::string Credentials::getUsername() const 41 | { 42 | return _username; 43 | } 44 | 45 | 46 | std::string Credentials::getPassword() const 47 | { 48 | return _password; 49 | } 50 | 51 | 52 | void Credentials::setUsername(const std::string& username) 53 | { 54 | _username = username; 55 | } 56 | 57 | 58 | void Credentials::setPassword(const std::string& password) 59 | { 60 | _password = password; 61 | } 62 | 63 | 64 | bool Credentials::hasCredentials() const 65 | { 66 | return !_username.empty() || !_password.empty(); 67 | } 68 | 69 | 70 | std::string Credentials::toString() const 71 | { 72 | return _username + ":" + _password; 73 | } 74 | 75 | 76 | } } // namespace ofx::HTTP 77 | -------------------------------------------------------------------------------- /libs/ofxHTTP/src/DefaultClientHeaders.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofx/HTTP/DefaultClientHeaders.h" 9 | #include "ofx/HTTP/Request.h" 10 | #include "ofx/HTTP/Context.h" 11 | 12 | 13 | namespace ofx { 14 | namespace HTTP { 15 | 16 | 17 | DefaultClientHeaders::DefaultClientHeaders() 18 | { 19 | } 20 | 21 | 22 | DefaultClientHeaders::~DefaultClientHeaders() 23 | { 24 | } 25 | 26 | 27 | void DefaultClientHeaders::requestFilter(Context& context, 28 | Request& request) const 29 | { 30 | const ClientSessionSettings& settings = context.getClientSessionSettings(); 31 | 32 | if (!settings.getUserAgent().empty()) 33 | { 34 | request.set("User-Agent", settings.getUserAgent()); 35 | } 36 | 37 | // request.set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"); 38 | // request.set("Accept-Language", "en-US,en;q=0.8"); 39 | 40 | for (const auto& entry: settings.getDefaultHeaders()) 41 | { 42 | request.set(entry.first, entry.second); 43 | } 44 | } 45 | 46 | 47 | 48 | } } // namespace ofx::HTTP 49 | -------------------------------------------------------------------------------- /libs/ofxHTTP/src/DefaultCookieProcessor.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofx/HTTP/DefaultCookieProcessor.h" 9 | 10 | 11 | namespace ofx { 12 | namespace HTTP { 13 | 14 | 15 | //DefaultCookieProcessor::DefaultCookieProcessor() 16 | //{ 17 | //} 18 | // 19 | // 20 | //DefaultCookieProcessor::~DefaultCookieProcessor() 21 | //{ 22 | //} 23 | // 24 | // 25 | //void DefaultCookieProcessor::filter(Poco::Net::HTTPRequest& request, 26 | // Context& context) 27 | //{ 28 | //// CookieStore::SharedPtr store(context.getCookieStore().lock()); 29 | //// 30 | //// 31 | //// if (store) 32 | //// { 33 | ////// store->set(request); // apply cookies; 34 | //// cout << "DefaultCookieProcessor::processRequest!" << std::endl; 35 | //// } 36 | //} 37 | // 38 | // 39 | //void DefaultCookieProcessor::filter(Poco::Net::HTTPRequest& request, 40 | // Poco::Net::HTTPResponse& response, 41 | // Context& context) 42 | //{ 43 | //// CookieStore::SharedPtr store(context.getCookieStore().lock()); 44 | //// 45 | //// 46 | //// if (store) 47 | //// { 48 | //// cout << "storing this!" << endl; 49 | //// 50 | //// Utils::dumpHeaders(response, OF_LOG_NOTICE); 51 | //// 52 | //// std::vector newCookies; 53 | //// response.getCookies(newCookies); 54 | //// 55 | //// std::vector::iterator iter = newCookies.begin(); 56 | //// while (iter != newCookies.end()) 57 | //// { 58 | //// cout << "COOKIE: " << (*iter).toString() << endl; 59 | //// 60 | //// 61 | //// Cookie cookie(*iter); 62 | ////// cookie.setDomain(request.getHost()); 63 | ////// cout << cookie.toString() << endl; 64 | //// ++iter; 65 | //// } 66 | //// 67 | ////// store->store(request, response); // store cookies; 68 | //// cout << "DefaultCookieProcessor::processResponse!" << std::endl; 69 | //// 70 | ////// store->dump(); 71 | //// } 72 | //} 73 | 74 | 75 | } } // namespace ofx::HTTP 76 | -------------------------------------------------------------------------------- /libs/ofxHTTP/src/DefaultEncodingResponseStreamFilter.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofx/HTTP/DefaultEncodingResponseStreamFilter.h" 9 | #include "ofx/HTTP/Request.h" 10 | #include "ofx/HTTP/Response.h" 11 | #include "ofx/HTTP/Context.h" 12 | #include "ofx/IO/StreamFilters.h" 13 | 14 | 15 | namespace ofx { 16 | namespace HTTP { 17 | 18 | 19 | const std::string DefaultEncodingResponseStreamFilter::ACCEPT_ENCODING_HEADER = "Accept-Encoding"; 20 | const std::string DefaultEncodingResponseStreamFilter::CONTENT_ENCODING_HEADER = "Content-Encoding"; 21 | 22 | 23 | DefaultEncodingResponseStreamFilter::DefaultEncodingResponseStreamFilter() 24 | { 25 | } 26 | 27 | 28 | DefaultEncodingResponseStreamFilter::~DefaultEncodingResponseStreamFilter() 29 | { 30 | } 31 | 32 | 33 | void DefaultEncodingResponseStreamFilter::requestFilter(Context&, 34 | Request& request) const 35 | { 36 | // Set the headers indicating the encodings we can decode. 37 | request.set(ACCEPT_ENCODING_HEADER, "gzip, deflate"); 38 | } 39 | 40 | 41 | void DefaultEncodingResponseStreamFilter::responseFilter(Context&, 42 | Request&, 43 | Response&) const 44 | { 45 | } 46 | 47 | 48 | void DefaultEncodingResponseStreamFilter::responseStreamFilter(Context& context, 49 | const Request& request, 50 | const Response& response, 51 | IO::FilteredInputStream& responseStream) const 52 | { 53 | if (response.has(CONTENT_ENCODING_HEADER)) 54 | { 55 | std::string contentEncoding = response.get(CONTENT_ENCODING_HEADER); 56 | 57 | if (contentEncoding == "gzip") 58 | { 59 | responseStream.push(std::make_unique(Poco::InflatingStreamBuf::StreamType::STREAM_GZIP)); 60 | } 61 | else if (contentEncoding == "deflate") 62 | { 63 | responseStream.push(std::make_unique(Poco::InflatingStreamBuf::StreamType::STREAM_ZLIB)); 64 | } 65 | } 66 | } 67 | 68 | 69 | } } // namespace ofx::HTTP 70 | -------------------------------------------------------------------------------- /libs/ofxHTTP/src/DefaultProxyProcessor.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofx/HTTP/DefaultProxyProcessor.h" 9 | #include "ofx/HTTP/Request.h" 10 | #include "ofx/HTTP/Response.h" 11 | #include "ofx/HTTP/Context.h" 12 | 13 | 14 | namespace ofx { 15 | namespace HTTP { 16 | 17 | 18 | DefaultProxyProcessor::DefaultProxyProcessor() 19 | { 20 | } 21 | 22 | 23 | DefaultProxyProcessor::~DefaultProxyProcessor() 24 | { 25 | } 26 | 27 | 28 | void DefaultProxyProcessor::requestFilter(Context& context, Request&) const 29 | { 30 | context.setState(ClientState::DETECTING_PROXY); 31 | 32 | if (!context.getProxyRedirectURI().empty()) 33 | { 34 | context.clientSession()->setProxy(context.getProxyRedirectURI().getHost(), 35 | context.getProxyRedirectURI().getPort()); 36 | } 37 | else 38 | { 39 | const ProxySettings& proxySettings = context.getClientSessionSettings().getProxySettings(); 40 | 41 | if (!proxySettings.getHost().empty()) 42 | { 43 | context.clientSession()->setProxyHost(proxySettings.getHost()); 44 | } 45 | 46 | if (proxySettings.getPort() != 0) 47 | { 48 | context.clientSession()->setProxyPort(proxySettings.getPort()); 49 | } 50 | 51 | if (proxySettings.hasCredentials()) 52 | { 53 | context.clientSession()->setProxyCredentials(proxySettings.getUsername(), 54 | proxySettings.getPassword()); 55 | } 56 | } 57 | } 58 | 59 | 60 | void DefaultProxyProcessor::responseFilter(Context& context, 61 | Request& request, 62 | Response& response) const 63 | { 64 | // The requested resource MUST be accessed through the proxy 65 | // given by the Location field. The Location field gives the 66 | // URI of the proxy. The recipient is expected to repeat this 67 | // single request via the proxy. 305 responses MUST only be 68 | // generated by origin servers. Only use for one single request! 69 | 70 | if (response.getStatus() == Poco::Net::HTTPResponse::HTTP_USEPROXY) 71 | { 72 | if (context.getProxyRedirectURI().empty() && response.has("Location")) 73 | { 74 | Poco::URI proxyRedirectURI; 75 | proxyRedirectURI.resolve(response.get("Location")); 76 | context.setProxyRedirectURI(proxyRedirectURI); 77 | 78 | // Set the context to resubmit based on the proxy-redirect URI. 79 | context.setResubmit(true); 80 | } 81 | else 82 | { 83 | throw Poco::Net::HTTPException(response.getReasonForStatus(response.getStatus()), 84 | response.getStatus()); 85 | } 86 | } 87 | } 88 | 89 | 90 | } } // namespace ofx::HTTP 91 | -------------------------------------------------------------------------------- /libs/ofxHTTP/src/FormRequest.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofx/HTTP/FormRequest.h" 9 | 10 | 11 | namespace ofx { 12 | namespace HTTP { 13 | 14 | 15 | const std::string FormRequest::DEFAULT_MEDIA_TYPE = "application/octet-stream"; 16 | 17 | 18 | FormRequest::~FormRequest() 19 | { 20 | } 21 | 22 | 23 | void FormRequest::addFormFields(const Poco::Net::NameValueCollection& formFields) 24 | { 25 | for (auto& entry : formFields) 26 | { 27 | _form.add(entry.first, entry.second); 28 | } 29 | } 30 | 31 | 32 | void FormRequest::addFormFields(const std::multimap& formFields) 33 | { 34 | for (auto& entry : formFields) 35 | { 36 | _form.add(entry.first, entry.second); 37 | } 38 | } 39 | 40 | 41 | void FormRequest::addFormField(const std::string& name, 42 | const std::string& value) 43 | { 44 | _form.add(name, value); 45 | } 46 | 47 | 48 | void FormRequest::setFormField(const std::string& name, 49 | const std::string& value) 50 | { 51 | _form.set(name, value); 52 | } 53 | 54 | 55 | void FormRequest::clearFormFields() 56 | { 57 | _form.clear(); 58 | } 59 | 60 | 61 | } } // namespace ofx::HTTP 62 | -------------------------------------------------------------------------------- /libs/ofxHTTP/src/GetRequest.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofx/HTTP/GetRequest.h" 9 | 10 | 11 | namespace ofx { 12 | namespace HTTP { 13 | 14 | 15 | GetRequest::GetRequest(const std::string& uri, 16 | const std::string& httpVersion): 17 | FormRequest(Poco::Net::HTTPRequest::HTTP_GET, 18 | uri, 19 | httpVersion) 20 | { 21 | } 22 | 23 | 24 | GetRequest::~GetRequest() 25 | { 26 | } 27 | 28 | 29 | } } // namespace ofx::HTTP 30 | -------------------------------------------------------------------------------- /libs/ofxHTTP/src/HTTPClient.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | // 7 | // 8 | //#include "ofx/HTTP/HTTPClient.h" 9 | //#include "ofx/HTTP/GetRequest.h" 10 | //#include "ofx/HTTP/JSONRequest.h" 11 | // 12 | // 13 | //namespace ofx { 14 | //namespace HTTP { 15 | // 16 | // 17 | //HTTPClient::HTTPClient() 18 | //{ 19 | // addRequestFilter(&_clientSessionProvider); 20 | // addRequestFilter(&_defaultProxyProcessor); 21 | // addRequestFilter(&_defaultAuthenticationProcessor); 22 | // addRequestFilter(&_defaultRedirectProcessor); 23 | // addRequestFilter(&_defaultClientHeaders); 24 | // 25 | // // response processors 26 | // addResponseFilter(&_defaultProxyProcessor); 27 | // addResponseFilter(&_defaultAuthenticationProcessor); 28 | // addResponseFilter(&_defaultRedirectProcessor); 29 | // 30 | // addResponseStreamFilter(&_encodingResponseStreamFilter); 31 | //} 32 | // 33 | // 34 | //HTTPClient::~HTTPClient() 35 | //{ 36 | //} 37 | // 38 | //// 39 | ////std::unique_ptr> HTTPClient::get(const std::string& uri) 40 | ////{ 41 | //// return executeBuffered>(std::make_unique(uri)); 42 | ////} 43 | //// 44 | //// 45 | ////std::unique_ptr> HTTPClient::post(const std::string& uri, 46 | //// const ofJson& json) 47 | ////{ 48 | //// return executeBuffered>(std::make_unique(uri, json)); 49 | ////} 50 | //// 51 | //// 52 | ////std::unique_ptr> HTTPClient::form(const std::string& uri, 53 | //// const std::multimap formFields, 54 | //// const std::vector& formParts) 55 | ////{ 56 | //// auto request = std::make_unique(uri); 57 | //// request->addFormFields(formFields); 58 | //// request->addFormParts(formParts); 59 | //// return executeBuffered>(std::move(request)); 60 | ////} 61 | // 62 | // 63 | //} } // namespace ofx::HTTP 64 | -------------------------------------------------------------------------------- /libs/ofxHTTP/src/HTTPHost.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofx/HTTP/HTTPHost.h" 9 | 10 | 11 | namespace ofx { 12 | namespace HTTP { 13 | 14 | 15 | HTTPHost::HTTPHost(const std::string& scheme, 16 | const std::string& host, 17 | uint16_t port): 18 | _scheme(scheme), 19 | _host(host), 20 | _port(port) 21 | { 22 | 23 | } 24 | 25 | HTTPHost::~HTTPHost() 26 | { 27 | } 28 | 29 | 30 | std::string HTTPHost::scheme() const 31 | { 32 | return _scheme; 33 | } 34 | 35 | 36 | std::string HTTPHost::host() const 37 | { 38 | return _host; 39 | } 40 | 41 | 42 | uint16_t HTTPHost::port() const 43 | { 44 | return _port; 45 | } 46 | 47 | 48 | bool HTTPHost::secure() const 49 | { 50 | return _scheme == "https" || _scheme == "wss"; 51 | } 52 | 53 | 54 | std::string HTTPHost::toString() const 55 | { 56 | return "[" + _scheme + "," + _host + "," + std::to_string(_port) + "]"; 57 | // std::stringstream ss; 58 | // ss << "[" << _scheme << "," << _host << "," << _port << "]"; 59 | // return ss.str(); 60 | } 61 | 62 | 63 | } } // namespace ofx::HTTP 64 | -------------------------------------------------------------------------------- /libs/ofxHTTP/src/HeadRequest.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofx/HTTP/HeadRequest.h" 9 | 10 | 11 | namespace ofx { 12 | namespace HTTP { 13 | 14 | 15 | HeadRequest::HeadRequest(const std::string& uri, 16 | const std::string& httpVersion): 17 | FormRequest(Poco::Net::HTTPRequest::HTTP_HEAD, 18 | uri, 19 | httpVersion) 20 | { 21 | } 22 | 23 | 24 | HeadRequest::~HeadRequest() 25 | { 26 | } 27 | 28 | 29 | } } // namespace ofx::HTTP 30 | -------------------------------------------------------------------------------- /libs/ofxHTTP/src/IPVideoFrame.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofx/HTTP/IPVideoFrame.h" 9 | 10 | 11 | namespace ofx { 12 | namespace HTTP { 13 | 14 | 15 | IPVideoFrameSettings::IPVideoFrameSettings() 16 | { 17 | } 18 | 19 | 20 | IPVideoFrameSettings::~IPVideoFrameSettings() 21 | { 22 | } 23 | 24 | 25 | void IPVideoFrameSettings::setWidth(int width) 26 | { 27 | _width = width; 28 | } 29 | 30 | 31 | int IPVideoFrameSettings::getWidth() const 32 | { 33 | return _width; 34 | } 35 | 36 | 37 | void IPVideoFrameSettings::setHeight(int height) 38 | { 39 | _height = height; 40 | } 41 | 42 | 43 | int IPVideoFrameSettings::getHeight() const 44 | { 45 | return _height; 46 | } 47 | 48 | 49 | void IPVideoFrameSettings::setFlipHorizontal(bool flipHorizontal) 50 | { 51 | _flipHorizontal = flipHorizontal; 52 | } 53 | 54 | 55 | bool IPVideoFrameSettings::getFlipHorizontal() const 56 | { 57 | return _flipHorizontal; 58 | } 59 | 60 | 61 | void IPVideoFrameSettings::setFlipVertical(bool flipVertical) 62 | { 63 | _flipVertical = flipVertical; 64 | } 65 | 66 | 67 | bool IPVideoFrameSettings::getFlipVertical() const 68 | { 69 | return _flipVertical; 70 | } 71 | 72 | 73 | void IPVideoFrameSettings::setQuality(ofImageQualityType quality) 74 | { 75 | _quality = quality; 76 | } 77 | 78 | 79 | ofImageQualityType IPVideoFrameSettings::getQuality() const 80 | { 81 | return _quality; 82 | } 83 | 84 | 85 | IPVideoFrame::IPVideoFrame(const IPVideoFrameSettings& settings, 86 | uint64_t timestamp, 87 | const ofBuffer& buffer): 88 | _settings(settings), 89 | _timestamp(timestamp), 90 | _buffer(buffer) 91 | { 92 | } 93 | 94 | 95 | IPVideoFrame::~IPVideoFrame() 96 | { 97 | } 98 | 99 | 100 | const IPVideoFrameSettings& IPVideoFrame::settings() const 101 | { 102 | return _settings; 103 | } 104 | 105 | 106 | uint64_t IPVideoFrame::timestamp() const 107 | { 108 | return _timestamp; 109 | } 110 | 111 | 112 | ofBuffer& IPVideoFrame::buffer() 113 | { 114 | return _buffer; 115 | } 116 | 117 | 118 | } } // namespace ofx::HTTP 119 | -------------------------------------------------------------------------------- /libs/ofxHTTP/src/JSONRequest.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofx/HTTP/JSONRequest.h" 9 | #include "Poco/StreamCopier.h" 10 | 11 | 12 | namespace ofx { 13 | namespace HTTP { 14 | 15 | 16 | const std::string JSONRequest::JSON_MEDIA_TYPE = "application/json"; 17 | 18 | 19 | JSONRequest::JSONRequest(const std::string& uri, 20 | const std::string& httpVersion): 21 | JSONRequest(uri, ofJson(), httpVersion) 22 | { 23 | } 24 | 25 | 26 | JSONRequest::JSONRequest(const std::string& uri, 27 | const ofJson& json, 28 | const std::string& httpVersion): 29 | Request(Poco::Net::HTTPRequest::HTTP_POST, uri, httpVersion), 30 | _json(json) 31 | { 32 | setContentType(JSON_MEDIA_TYPE); 33 | } 34 | 35 | 36 | JSONRequest::~JSONRequest() 37 | { 38 | } 39 | 40 | 41 | void JSONRequest::setJSON(const ofJson& json) 42 | { 43 | _json = json; 44 | } 45 | 46 | 47 | const ofJson& JSONRequest::getJSON() const 48 | { 49 | return _json; 50 | } 51 | 52 | 53 | void JSONRequest::prepareRequest() 54 | { 55 | _outBuffer.clear(); 56 | _outBuffer << getJSON(); // Call a subclass if needed. 57 | setContentLength(_outBuffer.str().length()); 58 | } 59 | 60 | 61 | void JSONRequest::writeRequestBody(std::ostream& requestStream) 62 | { 63 | Poco::StreamCopier::copyStream(_outBuffer, requestStream); 64 | } 65 | 66 | 67 | } } // namespace ofx::HTTP 68 | -------------------------------------------------------------------------------- /libs/ofxHTTP/src/OAuth10HTTPClient.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofx/HTTP/OAuth10HTTPClient.h" 9 | 10 | 11 | namespace ofx { 12 | namespace HTTP { 13 | 14 | 15 | OAuth10HTTPClient::OAuth10HTTPClient(): OAuth10HTTPClient(OAuth10Credentials()) 16 | { 17 | } 18 | 19 | 20 | OAuth10HTTPClient::OAuth10HTTPClient(const OAuth10Credentials& credentials) 21 | { 22 | setCredentials(credentials); 23 | } 24 | 25 | 26 | OAuth10HTTPClient::~OAuth10HTTPClient() 27 | { 28 | } 29 | 30 | 31 | void OAuth10HTTPClient::setCredentials(const OAuth10Credentials& credentials) 32 | { 33 | _oAuth10RequestFilter.setCredentials(credentials); 34 | } 35 | 36 | 37 | OAuth10Credentials OAuth10HTTPClient::getCredentials() const 38 | { 39 | return _oAuth10RequestFilter.getCredentials(); 40 | } 41 | 42 | 43 | void OAuth10HTTPClient::requestFilter(Context& context, Request& request) const 44 | { 45 | _oAuth10RequestFilter.requestFilter(context, request); 46 | } 47 | 48 | 49 | } } // namespace ofx::HTTP 50 | -------------------------------------------------------------------------------- /libs/ofxHTTP/src/OAuth10RequestFilter.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofx/HTTP/OAuth10RequestFilter.h" 9 | #include "Poco/Net/OAuth10Credentials.h" 10 | #include "ofx/HTTP/Request.h" 11 | #include "ofx/HTTP/HTTPUtils.h" 12 | 13 | 14 | namespace ofx { 15 | namespace HTTP { 16 | 17 | 18 | OAuth10RequestFilter::OAuth10RequestFilter() 19 | { 20 | } 21 | 22 | 23 | OAuth10RequestFilter::OAuth10RequestFilter(const OAuth10Credentials& credentials): 24 | _credentials(credentials) 25 | { 26 | } 27 | 28 | 29 | OAuth10RequestFilter::~OAuth10RequestFilter() 30 | { 31 | } 32 | 33 | 34 | void OAuth10RequestFilter::setCredentials(const OAuth10Credentials& credentials) 35 | { 36 | _credentials = credentials; 37 | } 38 | 39 | 40 | OAuth10Credentials OAuth10RequestFilter::getCredentials() const 41 | { 42 | return _credentials; 43 | } 44 | 45 | 46 | void OAuth10RequestFilter::requestFilter(Context& context, 47 | Request& request) const 48 | { 49 | Poco::Net::OAuth10Credentials credentials(_credentials.consumerKey(), 50 | _credentials.consumerSecret(), 51 | _credentials.accessToken(), 52 | _credentials.accessTokenSecret()); 53 | 54 | credentials.authenticate(request, 55 | Poco::URI(request.getURI()), 56 | request.form(), 57 | Poco::Net::OAuth10Credentials::SIGN_HMAC_SHA1); 58 | } 59 | 60 | 61 | } } // namespace ofx::OAuth 62 | -------------------------------------------------------------------------------- /libs/ofxHTTP/src/OAuth20Credentials.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofx/HTTP/OAuth20Credentials.h" 9 | 10 | 11 | namespace ofx { 12 | namespace HTTP { 13 | 14 | 15 | const std::string OAuth20Credentials::SCHEME = "Bearer"; 16 | 17 | 18 | OAuth20Credentials::OAuth20Credentials(): 19 | _scheme(SCHEME) 20 | { 21 | } 22 | 23 | 24 | OAuth20Credentials::OAuth20Credentials(const std::string& bearerToken): 25 | _bearerToken(bearerToken), 26 | _scheme(SCHEME) 27 | { 28 | } 29 | 30 | 31 | OAuth20Credentials::OAuth20Credentials(const std::string& bearerToken, 32 | const std::string& scheme): 33 | _bearerToken(bearerToken), 34 | _scheme(scheme) 35 | { 36 | } 37 | 38 | 39 | OAuth20Credentials::~OAuth20Credentials() 40 | { 41 | } 42 | 43 | 44 | void OAuth20Credentials::setBearerToken(const std::string& bearerToken) 45 | { 46 | _bearerToken = bearerToken; 47 | } 48 | 49 | 50 | const std::string& OAuth20Credentials::getScheme() const 51 | { 52 | return _scheme; 53 | } 54 | 55 | 56 | void OAuth20Credentials::setScheme(const std::string& scheme) 57 | { 58 | _scheme = scheme; 59 | } 60 | 61 | 62 | const std::string& OAuth20Credentials::getBearerToken() const 63 | { 64 | return _bearerToken; 65 | } 66 | 67 | 68 | } } // namespace Poco::Net 69 | -------------------------------------------------------------------------------- /libs/ofxHTTP/src/OAuth20HTTPClient.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofx/HTTP/OAuth20HTTPClient.h" 9 | 10 | 11 | namespace ofx { 12 | namespace HTTP { 13 | 14 | 15 | OAuth20HTTPClient::OAuth20HTTPClient(): OAuth20HTTPClient(OAuth20Credentials()) 16 | { 17 | } 18 | 19 | 20 | OAuth20HTTPClient::OAuth20HTTPClient(const OAuth20Credentials& credentials) 21 | { 22 | setCredentials(credentials); 23 | } 24 | 25 | 26 | OAuth20HTTPClient::~OAuth20HTTPClient() 27 | { 28 | } 29 | 30 | 31 | void OAuth20HTTPClient::setCredentials(const OAuth20Credentials& credentials) 32 | { 33 | _oAuth20RequestFilter.setCredentials(credentials); 34 | } 35 | 36 | 37 | OAuth20Credentials OAuth20HTTPClient::getCredentials() const 38 | { 39 | return _oAuth20RequestFilter.getCredentials(); 40 | } 41 | 42 | 43 | void OAuth20HTTPClient::requestFilter(Context& context, Request& request) const 44 | { 45 | _oAuth20RequestFilter.requestFilter(context, request); 46 | } 47 | 48 | 49 | } } // namespace ofx::HTTP 50 | -------------------------------------------------------------------------------- /libs/ofxHTTP/src/OAuth20RequestFilter.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofx/HTTP/OAuth20RequestFilter.h" 9 | #include "Poco/Net/OAuth20Credentials.h" 10 | #include "ofx/HTTP/Request.h" 11 | #include "ofx/HTTP/HTTPUtils.h" 12 | 13 | 14 | namespace ofx { 15 | namespace HTTP { 16 | 17 | 18 | OAuth20RequestFilter::OAuth20RequestFilter() 19 | { 20 | } 21 | 22 | 23 | OAuth20RequestFilter::OAuth20RequestFilter(const OAuth20Credentials& credentials): 24 | _credentials(credentials) 25 | { 26 | } 27 | 28 | 29 | OAuth20RequestFilter::~OAuth20RequestFilter() 30 | { 31 | } 32 | 33 | 34 | void OAuth20RequestFilter::setCredentials(const OAuth20Credentials& credentials) 35 | { 36 | _credentials = credentials; 37 | } 38 | 39 | 40 | OAuth20Credentials OAuth20RequestFilter::getCredentials() const 41 | { 42 | return _credentials; 43 | } 44 | 45 | 46 | void OAuth20RequestFilter::requestFilter(Context& context, 47 | Request& request) const 48 | { 49 | Poco::Net::OAuth20Credentials credentials(_credentials.getBearerToken(), 50 | _credentials.getScheme()); 51 | 52 | credentials.authenticate(request); 53 | } 54 | 55 | 56 | } } // namespace ofx::OAuth 57 | -------------------------------------------------------------------------------- /libs/ofxHTTP/src/PostRequest.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofx/HTTP/PostRequest.h" 9 | #include "Poco/CountingStream.h" 10 | #include "Poco/StreamCopier.h" 11 | #include "Poco/Net/FilePartSource.h" 12 | #include "Poco/Net/PartSource.h" 13 | #include "Poco/Net/StringPartSource.h" 14 | 15 | 16 | namespace ofx { 17 | namespace HTTP { 18 | 19 | 20 | PostRequest::PostRequest(const std::string& uri, 21 | const std::string& httpVersion): 22 | FormRequest(Poco::Net::HTTPRequest::HTTP_POST, uri, httpVersion) 23 | { 24 | } 25 | 26 | 27 | PostRequest::~PostRequest() 28 | { 29 | } 30 | 31 | 32 | void PostRequest::setFormEncoding(FormEncoding formEncoding) 33 | { 34 | if (formEncoding == FORM_ENCODING_URL) 35 | { 36 | _form.setEncoding(Poco::Net::HTMLForm::ENCODING_URL); 37 | } 38 | else 39 | { 40 | _form.setEncoding(Poco::Net::HTMLForm::ENCODING_MULTIPART); 41 | } 42 | } 43 | 44 | 45 | PostRequest::FormEncoding PostRequest::getFormEncoding() const 46 | { 47 | if (_form.getEncoding() == Poco::Net::HTMLForm::ENCODING_URL) 48 | { 49 | return FORM_ENCODING_URL; 50 | } 51 | else 52 | { 53 | return FORM_ENCODING_MULTIPART; 54 | } 55 | } 56 | 57 | 58 | Poco::Net::HTMLForm& PostRequest::form() 59 | { 60 | return _form; 61 | } 62 | 63 | 64 | void PostRequest::addFormPart(const FormPart& part) 65 | { 66 | switch (part.type()) 67 | { 68 | case FormPart::Type::STRING: 69 | { 70 | // _form takes ownership of StringPartSource. 71 | _form.addPart(part.name(), new Poco::Net::StringPartSource(part.value(), 72 | part.mediaType())); 73 | break; 74 | } 75 | case FormPart::Type::FILE: 76 | { 77 | try 78 | { 79 | // _form takes ownership of FilePartSource. 80 | _form.addPart(part.name(), new Poco::Net::FilePartSource(ofToDataPath(part.value(), true), 81 | part.mediaType())); 82 | } 83 | catch (const Poco::FileNotFoundException& exc) 84 | { 85 | ofLogError("PostRequest::addFile") << exc.displayText(); 86 | } 87 | catch (const Poco::OpenFileException& exc) 88 | { 89 | ofLogError("PostRequest::addFile") << exc.displayText(); 90 | } 91 | 92 | break; 93 | } 94 | } 95 | 96 | // We must set encoding to multipart. 97 | _form.setEncoding(Poco::Net::HTMLForm::ENCODING_MULTIPART); 98 | } 99 | 100 | 101 | void PostRequest::addFormParts(const std::vector& parts) 102 | { 103 | for (auto& part: parts) 104 | { 105 | addFormPart(part); 106 | } 107 | } 108 | 109 | 110 | void PostRequest::addFormFile(const std::string& name, 111 | const std::string& path, 112 | const std::string& mediaType) 113 | { 114 | addFormPart(FormPart(FormPart::Type::FILE, 115 | name, 116 | path, 117 | mediaType)); 118 | } 119 | 120 | 121 | void PostRequest::addFormString(const std::string& name, 122 | const std::string& buffer, 123 | const std::string& mediaType) 124 | { 125 | addFormPart(FormPart(FormPart::Type::STRING, 126 | name, 127 | buffer, 128 | mediaType)); 129 | } 130 | 131 | 132 | } } // namespace ofx::HTTP 133 | -------------------------------------------------------------------------------- /libs/ofxHTTP/src/Progress.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofx/HTTP/Progress.h" 9 | #include "Poco/Net/HTTPMessage.h" 10 | #include "Poco/Timestamp.h" 11 | 12 | 13 | namespace ofx { 14 | namespace HTTP { 15 | 16 | 17 | const int64_t Progress::UNKNOWN_CONTENT_LENGTH = Poco::Net::HTTPMessage::UNKNOWN_CONTENT_LENGTH; 18 | 19 | 20 | Progress::Progress(int64_t totalBytes): _totalBytes(totalBytes) 21 | { 22 | } 23 | 24 | 25 | Progress::Progress() 26 | { 27 | } 28 | 29 | 30 | Progress::~Progress() 31 | { 32 | } 33 | 34 | 35 | int64_t Progress::getTotalBytesTranferred() const 36 | { 37 | return _totalBytesTransferred; 38 | } 39 | 40 | 41 | void Progress::setTotalBytesTransferred(int64_t totalBytesTransferred) 42 | { 43 | _lastUpdateTime.update(); 44 | _totalBytesTransferred = totalBytesTransferred; 45 | } 46 | 47 | 48 | 49 | int64_t Progress::getTotalBytes() const 50 | { 51 | return _totalBytes; 52 | } 53 | 54 | 55 | void Progress::setTotalBytes(int64_t totalBytes) 56 | { 57 | _startTime.update(); 58 | _totalBytes = totalBytes; 59 | } 60 | 61 | 62 | float Progress::progress() const 63 | { 64 | if (_totalBytes == 0) 65 | { 66 | return 1.0; 67 | } 68 | else if (_totalBytes > 0) 69 | { 70 | double totalBytesTransferred = static_cast(_totalBytesTransferred); 71 | double totalBytes = static_cast(_totalBytes); 72 | return static_cast(totalBytesTransferred / totalBytes); 73 | } 74 | else return UNKNOWN_CONTENT_LENGTH; 75 | } 76 | 77 | 78 | float Progress::bytesPerSecond() const 79 | { 80 | return _totalBytesTransferred / (_startTime.elapsed() / 1000000.0); 81 | } 82 | 83 | 84 | Poco::Timestamp Progress::lastUpdateTime() const 85 | { 86 | return _lastUpdateTime; 87 | } 88 | 89 | 90 | Poco::Timestamp Progress::startTime() const 91 | { 92 | return _startTime; 93 | } 94 | 95 | 96 | } } // namespace ofx::HTTP 97 | -------------------------------------------------------------------------------- /libs/ofxHTTP/src/ProxySettings.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofx/HTTP/ProxySettings.h" 9 | 10 | 11 | namespace ofx { 12 | namespace HTTP { 13 | 14 | 15 | const std::string ProxySettings::DEFAULT_PROXY_HOST = ""; 16 | const uint16_t ProxySettings::DEFAULT_PROXY_PORT = 0; 17 | 18 | 19 | ProxySettings::ProxySettings(): 20 | _host(DEFAULT_PROXY_HOST), 21 | _port(DEFAULT_PROXY_PORT) 22 | { 23 | } 24 | 25 | 26 | ProxySettings::ProxySettings(const std::string& host, 27 | uint16_t port): 28 | _host(host), 29 | _port(port) 30 | { 31 | } 32 | 33 | 34 | ProxySettings::ProxySettings(const std::string& username, 35 | const std::string& password, 36 | const std::string& host, 37 | uint16_t port): 38 | Credentials(username, password), 39 | _host(host), 40 | _port(port) 41 | { 42 | } 43 | 44 | 45 | ProxySettings::~ProxySettings() 46 | { 47 | } 48 | 49 | 50 | void ProxySettings::clear() 51 | { 52 | Credentials::clear(); 53 | _host = DEFAULT_PROXY_HOST; 54 | _port = DEFAULT_PROXY_PORT; 55 | } 56 | 57 | 58 | std::string ProxySettings::getHost() const 59 | { 60 | return _host; 61 | } 62 | 63 | 64 | void ProxySettings::setHost(const std::string& host) 65 | { 66 | _host = host; 67 | } 68 | 69 | 70 | uint16_t ProxySettings::getPort() const 71 | { 72 | return _port; 73 | } 74 | 75 | 76 | void ProxySettings::setPort(uint16_t port) 77 | { 78 | _port = port; 79 | } 80 | 81 | 82 | } } // namespace ofx::HTTP 83 | -------------------------------------------------------------------------------- /libs/ofxHTTP/src/PutRequest.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakercp/ofxHTTP/fa65775e68a0ef8885a257a5ea055993342721a9/libs/ofxHTTP/src/PutRequest.cpp -------------------------------------------------------------------------------- /libs/ofxHTTP/src/RequestHandlerAdapter.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofx/HTTP/RequestHandlerAdapter.h" 9 | 10 | 11 | namespace ofx { 12 | namespace HTTP { 13 | 14 | 15 | RequestHandlerAdapter::RequestHandlerAdapter(Poco::Net::HTTPRequestHandler& handler): 16 | _handler(handler) 17 | { 18 | // std::cout << "CREATE RequestHandlerAdapter handling ..." << std::endl; 19 | } 20 | 21 | 22 | RequestHandlerAdapter::~RequestHandlerAdapter() 23 | { 24 | // std::cout << "DESTROY RequestHandlerAdapter handling ..." << std::endl; 25 | } 26 | 27 | 28 | void RequestHandlerAdapter::handleRequest(Poco::Net::HTTPServerRequest& request, 29 | Poco::Net::HTTPServerResponse& response) 30 | { 31 | // std::cout << "RequestHandlerAdapter handling ..." << std::endl; 32 | 33 | try 34 | { 35 | _handler.handleRequest(request, response); 36 | } 37 | catch (...) 38 | { 39 | // std::cout << "CAUGHT AN EXEPTION HERE!" << std::endl; 40 | } 41 | } 42 | 43 | 44 | } } // namespace ofx::HTTP 45 | -------------------------------------------------------------------------------- /libs/ofxHTTP/src/SSEFrame.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofx/HTTP/SSEFrame.h" 9 | 10 | 11 | namespace ofx { 12 | namespace HTTP { 13 | 14 | 15 | SSEFrame::SSEFrame(const std::string& data): 16 | SSEFrame("", data) 17 | { 18 | } 19 | 20 | 21 | SSEFrame::SSEFrame(const std::string& event, const std::string& data): 22 | _event(event), 23 | _data(data) 24 | { 25 | } 26 | 27 | 28 | SSEFrame::~SSEFrame() 29 | { 30 | } 31 | 32 | 33 | std::string SSEFrame::event() const 34 | { 35 | return _event; 36 | } 37 | 38 | 39 | std::string SSEFrame::data() const 40 | { 41 | return _data; 42 | } 43 | 44 | 45 | IndexedSSEFrame::IndexedSSEFrame(const SSEFrame& frame, uint64_t index): 46 | _frame(frame), 47 | _index(index) 48 | { 49 | } 50 | 51 | 52 | const SSEFrame& IndexedSSEFrame::frame() const 53 | { 54 | return _frame; 55 | } 56 | 57 | 58 | uint64_t IndexedSSEFrame::index() const 59 | { 60 | return _index; 61 | } 62 | 63 | 64 | } } // namespace ofx::HTTP 65 | -------------------------------------------------------------------------------- /libs/ofxHTTP/src/Session.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofx/HTTP/Session.h" 9 | #include "Poco/UUIDGenerator.h" 10 | 11 | 12 | namespace ofx { 13 | namespace HTTP { 14 | 15 | 16 | const std::string BaseSession::KEY_LAST_MODIFIED = "last_modified"; 17 | 18 | 19 | BaseSession::BaseSession(const std::string sessionId): _sessionId(sessionId) 20 | { 21 | } 22 | 23 | 24 | BaseSession::~BaseSession() 25 | { 26 | } 27 | 28 | 29 | std::string BaseSession::getId() const 30 | { 31 | std::unique_lock lock(_mutex); 32 | return _sessionId; 33 | } 34 | 35 | 36 | std::string BaseSession::generateId() 37 | { 38 | return Poco::UUIDGenerator::defaultGenerator().createRandom().toString(); 39 | } 40 | 41 | 42 | SimpleSession::SimpleSession(const std::string& sessionId): 43 | BaseSession(sessionId) 44 | { 45 | } 46 | 47 | 48 | SimpleSession::~SimpleSession() 49 | { 50 | } 51 | 52 | 53 | bool SimpleSession::has(const std::string& key) const 54 | { 55 | std::unique_lock lock(_mutex); 56 | return _sessionDict.find(key) != _sessionDict.end(); 57 | } 58 | 59 | 60 | void SimpleSession::put(const std::string& key, const std::string& value) 61 | { 62 | std::unique_lock lock(_mutex); 63 | _sessionDict[key] = value; 64 | } 65 | 66 | 67 | std::string SimpleSession::get(const std::string& key, 68 | const std::string& defaultValue) const 69 | { 70 | std::unique_lock lock(_mutex); 71 | 72 | std::map::const_iterator iter = _sessionDict.find(key); 73 | 74 | if (iter != _sessionDict.end()) 75 | { 76 | return iter->second; 77 | } 78 | else 79 | { 80 | return defaultValue; 81 | } 82 | } 83 | 84 | 85 | std::string SimpleSession::get(const std::string& key) const 86 | { 87 | std::unique_lock lock(_mutex); 88 | 89 | std::map::const_iterator iter = _sessionDict.find(key); 90 | 91 | if (iter != _sessionDict.end()) 92 | { 93 | return iter->second; 94 | } 95 | else 96 | { 97 | throw Poco::InvalidAccessException("No key: " + key); 98 | } 99 | } 100 | 101 | 102 | void SimpleSession::remove(const std::string& key) 103 | { 104 | std::unique_lock lock(_mutex); 105 | _sessionDict.erase(_sessionDict.find(key)); 106 | } 107 | 108 | 109 | void SimpleSession::clear() 110 | { 111 | std::unique_lock lock(_mutex); 112 | _sessionDict.clear(); 113 | } 114 | 115 | 116 | } } // namespace ofx::HTTP 117 | -------------------------------------------------------------------------------- /libs/ofxHTTP/src/SimpleClient.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofx/HTTP/SimpleClient.h" 9 | 10 | 11 | namespace ofx { 12 | namespace HTTP { 13 | 14 | 15 | SimpleClient::~SimpleClient() 16 | { 17 | } 18 | 19 | 20 | //std::unique_ptr> SimpleClient::get(const std::string& uri) 21 | //{ 22 | // return executeBuffered>(std::make_unique(uri)); 23 | //} 24 | 25 | 26 | } } // namespace ofx::HTTP 27 | -------------------------------------------------------------------------------- /libs/ofxHTTP/src/SimpleFileServer.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofx/HTTP/SimpleFileServer.h" 9 | 10 | 11 | namespace ofx { 12 | namespace HTTP { 13 | 14 | 15 | SimpleFileServer::SimpleFileServer(const Settings& settings): 16 | BaseServer_(settings), 17 | _fileSystemRoute(settings.fileSystemRouteSettings) 18 | { 19 | addRoute(&_fileSystemRoute); 20 | } 21 | 22 | 23 | SimpleFileServer::~SimpleFileServer() 24 | { 25 | removeRoute(&_fileSystemRoute); 26 | } 27 | 28 | 29 | void SimpleFileServer::setup(const Settings& settings) 30 | { 31 | BaseServer_::setup(settings); 32 | _fileSystemRoute.setup(settings.fileSystemRouteSettings); 33 | } 34 | 35 | 36 | FileSystemRoute& SimpleFileServer::fileSystemRoute() 37 | { 38 | return _fileSystemRoute; 39 | } 40 | 41 | 42 | } } // namespace ofx::HTTP 43 | -------------------------------------------------------------------------------- /libs/ofxHTTP/src/SimpleIPVideoServer.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofx/HTTP/SimpleIPVideoServer.h" 9 | 10 | 11 | namespace ofx { 12 | namespace HTTP { 13 | 14 | 15 | SimpleIPVideoServer::SimpleIPVideoServer(const Settings& settings): 16 | BaseServer_(settings), 17 | _fileSystemRoute(settings.fileSystemRouteSettings), 18 | _postRoute(settings.postRouteSettings), 19 | _ipVideoRoute(settings.ipVideoRouteSettings) 20 | { 21 | addRoute(&_fileSystemRoute); 22 | addRoute(&_postRoute); 23 | addRoute(&_ipVideoRoute); 24 | } 25 | 26 | 27 | SimpleIPVideoServer::~SimpleIPVideoServer() 28 | { 29 | removeRoute(&_ipVideoRoute); 30 | removeRoute(&_postRoute); 31 | removeRoute(&_fileSystemRoute); 32 | } 33 | 34 | 35 | void SimpleIPVideoServer::setup(const Settings& settings) 36 | { 37 | BaseServer_::setup(settings); 38 | _fileSystemRoute.setup(settings.fileSystemRouteSettings); 39 | _postRoute.setup(settings.postRouteSettings); 40 | _ipVideoRoute.setup(settings.ipVideoRouteSettings); 41 | } 42 | 43 | 44 | void SimpleIPVideoServer::send(const ofPixels& pix) 45 | { 46 | _ipVideoRoute.send(pix); 47 | } 48 | 49 | 50 | std::size_t SimpleIPVideoServer::numConnections() const 51 | { 52 | return _ipVideoRoute.numConnections(); 53 | } 54 | 55 | 56 | FileSystemRoute& SimpleIPVideoServer::fileSystemRoute() 57 | { 58 | return _fileSystemRoute; 59 | } 60 | 61 | 62 | PostRoute& SimpleIPVideoServer::postRoute() 63 | { 64 | return _postRoute; 65 | } 66 | 67 | 68 | IPVideoRoute& SimpleIPVideoServer::ipVideoRoute() 69 | { 70 | return _ipVideoRoute; 71 | } 72 | 73 | 74 | } } // namespace ofx::HTTP 75 | -------------------------------------------------------------------------------- /libs/ofxHTTP/src/SimplePostServer.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofx/HTTP/SimplePostServer.h" 9 | 10 | 11 | namespace ofx { 12 | namespace HTTP { 13 | 14 | 15 | SimplePostServer::SimplePostServer(const Settings& settings): 16 | BaseServer_(settings), 17 | _fileSystemRoute(settings.fileSystemRouteSettings), 18 | _postRoute(settings.postRouteSettings) 19 | { 20 | addRoute(&_fileSystemRoute); 21 | addRoute(&_postRoute); 22 | } 23 | 24 | 25 | SimplePostServer::~SimplePostServer() 26 | { 27 | removeRoute(&_postRoute); 28 | removeRoute(&_fileSystemRoute); 29 | } 30 | 31 | 32 | void SimplePostServer::setup(const Settings& settings) 33 | { 34 | BaseServer_::setup(settings); 35 | _fileSystemRoute.setup(settings.fileSystemRouteSettings); 36 | _postRoute.setup(settings.postRouteSettings); 37 | } 38 | 39 | 40 | PostRoute& SimplePostServer::postRoute() 41 | { 42 | return _postRoute; 43 | } 44 | 45 | 46 | } } // namespace ofx::HTTP 47 | -------------------------------------------------------------------------------- /libs/ofxHTTP/src/SimpleSSEServer.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofx/HTTP/SimpleSSEServer.h" 9 | 10 | 11 | namespace ofx { 12 | namespace HTTP { 13 | 14 | 15 | SimpleSSEServer::SimpleSSEServer(const Settings& settings): 16 | BaseServer_(settings), 17 | _fileSystemRoute(settings.fileSystemRouteSettings), 18 | _sseRoute(settings.sseRouteSettings) 19 | { 20 | addRoute(&_fileSystemRoute); 21 | addRoute(&_sseRoute); 22 | } 23 | 24 | 25 | SimpleSSEServer::~SimpleSSEServer() 26 | { 27 | removeRoute(&_sseRoute); 28 | removeRoute(&_fileSystemRoute); 29 | } 30 | 31 | 32 | void SimpleSSEServer::setup(const Settings& settings) 33 | { 34 | BaseServer_::setup(settings); 35 | _fileSystemRoute.setup(settings.fileSystemRouteSettings); 36 | _sseRoute.setup(settings.sseRouteSettings); 37 | } 38 | 39 | 40 | FileSystemRoute& SimpleSSEServer::fileSystemRoute() 41 | { 42 | return _fileSystemRoute; 43 | } 44 | 45 | 46 | SSERoute& SimpleSSEServer::sseRoute() 47 | { 48 | return _sseRoute; 49 | } 50 | 51 | 52 | } } // namespace ofx::HTTP 53 | -------------------------------------------------------------------------------- /libs/ofxHTTP/src/SimpleWebSocketServer.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofx/HTTP/SimpleWebSocketServer.h" 9 | 10 | 11 | namespace ofx { 12 | namespace HTTP { 13 | 14 | 15 | SimpleWebSocketServer::SimpleWebSocketServer(const Settings& settings): 16 | BaseServer_(settings), 17 | _fileSystemRoute(settings.fileSystemRouteSettings), 18 | _webSocketRoute(settings.webSocketRouteSettings) 19 | { 20 | addRoute(&_fileSystemRoute); 21 | addRoute(&_webSocketRoute); 22 | } 23 | 24 | 25 | SimpleWebSocketServer::~SimpleWebSocketServer() 26 | { 27 | removeRoute(&_webSocketRoute); 28 | removeRoute(&_fileSystemRoute); 29 | } 30 | 31 | 32 | void SimpleWebSocketServer::setup(const Settings& settings) 33 | { 34 | BaseServer_::setup(settings); 35 | _fileSystemRoute.setup(settings.fileSystemRouteSettings); 36 | _webSocketRoute.setup(settings.webSocketRouteSettings); 37 | } 38 | 39 | 40 | FileSystemRoute& SimpleWebSocketServer::fileSystemRoute() 41 | { 42 | return _fileSystemRoute; 43 | } 44 | 45 | 46 | WebSocketRoute& SimpleWebSocketServer::webSocketRoute() 47 | { 48 | return _webSocketRoute; 49 | } 50 | 51 | 52 | } } // namespace ofx::HTTP 53 | -------------------------------------------------------------------------------- /libs/ofxHTTP/src/ThreadSettings.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofx/HTTP/ThreadSettings.h" 9 | 10 | 11 | namespace ofx { 12 | namespace HTTP { 13 | 14 | 15 | ThreadSettings::ThreadSettings(const std::string& name, 16 | const Poco::Thread::Priority& priority): 17 | _name(name), 18 | _priority(priority) 19 | { 20 | } 21 | 22 | 23 | ThreadSettings::~ThreadSettings() 24 | { 25 | } 26 | 27 | 28 | std::string ThreadSettings::getName() const 29 | { 30 | return _name; 31 | } 32 | 33 | 34 | void ThreadSettings::setName(const std::string& name) 35 | { 36 | _name = name; 37 | } 38 | 39 | 40 | Poco::Thread::Priority ThreadSettings::getPriority() const 41 | { 42 | return _priority; 43 | } 44 | 45 | 46 | void ThreadSettings::setPriority(const Poco::Thread::Priority& priority) 47 | { 48 | _priority = priority; 49 | } 50 | 51 | 52 | } } // namespace ofx::HTTP 53 | -------------------------------------------------------------------------------- /libs/ofxHTTP/src/URIBuilder.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #include "ofx/HTTP/URIBuilder.h" 9 | #include "ofx/HTTP/HTTPUtils.h" 10 | 11 | 12 | namespace ofx { 13 | namespace HTTP { 14 | 15 | 16 | URIBuilder::URIBuilder() 17 | { 18 | } 19 | 20 | 21 | URIBuilder::URIBuilder(const Poco::URI& uri): 22 | Poco::Net::NameValueCollection(HTTPUtils::getQueryMap(uri)) 23 | { 24 | _uri.setScheme(uri.getScheme()); 25 | _uri.setAuthority(uri.getAuthority()); 26 | _uri.setPath(uri.getPath()); 27 | _uri.setFragment(uri.getFragment()); 28 | } 29 | 30 | 31 | URIBuilder::~URIBuilder() 32 | { 33 | } 34 | 35 | 36 | Poco::URI URIBuilder::toURI() const 37 | { 38 | Poco::URI uri(_uri); 39 | uri.setRawQuery(HTTPUtils::makeQueryString(*this)); 40 | return uri; 41 | } 42 | 43 | 44 | void URIBuilder::set(const std::string& key, bool value, bool numerical) 45 | { 46 | if (numerical) 47 | { 48 | Poco::Net::NameValueCollection::set(key, value ? "1" : "0"); 49 | } 50 | else 51 | { 52 | Poco::Net::NameValueCollection::set(key, value ? "true" : "false"); 53 | } 54 | } 55 | 56 | 57 | void URIBuilder::add(const std::string& key, bool value, bool numerical) 58 | { 59 | if (numerical) 60 | { 61 | Poco::Net::NameValueCollection::add(key, value ? "1" : "0"); 62 | } 63 | else 64 | { 65 | Poco::Net::NameValueCollection::add(key, value ? "true" : "false"); 66 | } 67 | } 68 | 69 | 70 | std::string URIBuilder::toString() const 71 | { 72 | return toURI().toString(); 73 | } 74 | 75 | 76 | } } // namespace ofx::HTTP 77 | -------------------------------------------------------------------------------- /scripts/ci/install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) 5 | 6 | if ! [ -z ${OF_ROOT} ]; then 7 | OF_ROOT=$( cd "$( dirname "${BASH_SOURCE[0]}")/../../../.." ; pwd -P ) 8 | fi 9 | 10 | if ! [ -z ${ADDON_NAME} ]; then 11 | ADDON_NAME=$(basename $( cd "$( dirname "${BASH_SOURCE[0]}")/../.." ; pwd -P )) 12 | fi 13 | 14 | # Default addon github info. 15 | GH_USERNAME='bakercp' 16 | GH_BRANCH='master' 17 | GH_DEPTH=1 18 | 19 | # An array of required addons that will be gathered below. 20 | REQUIRED_ADDONS=() 21 | 22 | # Extract ADDON_DEPENDENCIES from addon_config.mk file. 23 | ADDON_CONFIG_MK=$OF_ROOT/addons/$ADDON_NAME/addon_config.mk 24 | 25 | echo "" 26 | echo "Running ${THIS_DIR}/install.sh" 27 | echo "---------------------------------" 28 | echo " OF_ROOT: ${OF_ROOT}" 29 | echo " ADDON_NAME: ${ADDON_NAME}" 30 | echo "ADDON_CONFIG_MK: ${ADDON_CONFIG_MK}" 31 | echo "" 32 | 33 | echo "Examining ${ADDON_CONFIG_MK} ..." 34 | if [ -f $ADDON_CONFIG_MK ]; then 35 | while read line; do 36 | if [[ $line == ADDON_DEPENDENCIES* ]] ; 37 | then 38 | line=${line#*=} 39 | IFS=' ' read -ra ADDR <<< "$line" 40 | for i in "${ADDR[@]}"; do 41 | REQUIRED_ADDONS+=($i) 42 | done 43 | fi 44 | done < $ADDON_CONFIG_MK 45 | else 46 | echo "No ${ADDON_CONFIG_MK} found, skipping." 47 | fi 48 | 49 | echo "Gathering addons from addons.make files ..." 50 | # Gather addons from all examples. 51 | for addons_make in $OF_ROOT/addons/$ADDON_NAME/example*/addons.make; do 52 | echo "Examining ${addons_make} ..." 53 | while read addon; do 54 | if [ ${addon} != ${ADDON_NAME} ] ; 55 | then 56 | REQUIRED_ADDONS+=($addon) 57 | fi 58 | done < $addons_make 59 | done 60 | 61 | # We aren't de-duplicating array to keep it pure bash. 62 | echo "Cloning addons ..." 63 | for addon in "${REQUIRED_ADDONS[@]}" 64 | do 65 | if [ ! -d ${OF_ROOT}/addons/${addon} ]; then 66 | echo "Cloning addon: ${addon}." 67 | git clone --depth=$GH_DEPTH https://github.com/$GH_USERNAME/$addon.git ${OF_ROOT}/addons/${addon} 68 | else 69 | echo "Addon: ${addon} already exists, skipping." 70 | fi 71 | done 72 | 73 | echo "Finished installing addon dependencies." 74 | -------------------------------------------------------------------------------- /src/ofxHTTP.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2013 Christopher Baker 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // 6 | 7 | 8 | #pragma once 9 | 10 | 11 | #include "ofSSLManager.h" 12 | #include "ofxIO.h" 13 | #include "ofxMediaType.h" 14 | #include "ofxNetworkUtils.h" 15 | #include "ofx/HTTP/AbstractClientTypes.h" 16 | #include "ofx/HTTP/AbstractServerTypes.h" 17 | #include "ofx/HTTP/BaseClient.h" 18 | #include "ofx/HTTP/Response.h" 19 | #include "ofx/HTTP/Request.h" 20 | #include "ofx/HTTP/ClientEvents.h" 21 | #include "ofx/HTTP/ClientSessionProvider.h" 22 | #include "ofx/HTTP/ClientState.h" 23 | #include "ofx/HTTP/Context.h" 24 | #include "ofx/HTTP/DefaultProxyProcessor.h" 25 | #include "ofx/HTTP/DefaultRedirectProcessor.h" 26 | #include "ofx/HTTP/DefaultClientHeaders.h" 27 | #include "ofx/HTTP/DefaultCookieProcessor.h" 28 | #include "ofx/HTTP/DefaultEncodingResponseStreamFilter.h" 29 | #include "ofx/HTTP/FormRequest.h" 30 | #include "ofx/HTTP/GetRequest.h" 31 | #include "ofx/HTTP/HeadRequest.h" 32 | #include "ofx/HTTP/HTTPClient.h" 33 | #include "ofx/HTTP/Client.h" 34 | #include "ofx/HTTP/GetRequestTask.h" 35 | //#include "ofx/HTTP/HTTPClientTask.h" 36 | #include "ofx/HTTP/HTTPUtils.h" 37 | #include "ofx/HTTP/JSONRequest.h" 38 | #include "ofx/HTTP/JSONWebToken.h" 39 | #include "ofx/HTTP/OAuth10Credentials.h" 40 | #include "ofx/HTTP/OAuth10RequestFilter.h" 41 | #include "ofx/HTTP/OAuth20Credentials.h" 42 | #include "ofx/HTTP/OAuth20RequestFilter.h" 43 | #include "ofx/HTTP/PostRequest.h" 44 | #include "ofx/HTTP/PutRequest.h" 45 | #include "ofx/HTTP/Session.h" 46 | #include "ofx/HTTP/SessionStore.h" 47 | #include "ofx/HTTP/SimpleFileServer.h" 48 | #include "ofx/HTTP/SimpleIPVideoServer.h" 49 | #include "ofx/HTTP/SimplePostServer.h" 50 | #include "ofx/HTTP/SimpleSSEServer.h" 51 | #include "ofx/HTTP/SimpleWebSocketServer.h" 52 | #include "ofx/HTTP/SSEEvents.h" 53 | #include "ofx/HTTP/SSEFrame.h" 54 | #include "ofx/HTTP/SSERoute.h" 55 | #include "ofx/HTTP/SSEConnection.h" 56 | #include "ofx/HTTP/URIBuilder.h" 57 | #include "ofx/HTTP/WebSocketEvents.h" 58 | #include "ofx/HTTP/WebSocketRoute.h" 59 | #include "ofx/HTTP/WebSocketFrame.h" 60 | #include "ofx/HTTP/WebSocketConnection.h" 61 | 62 | 63 | namespace ofxHTTP = ofx::HTTP; 64 | -------------------------------------------------------------------------------- /tests/client/synchronous/addons.make: -------------------------------------------------------------------------------- 1 | ofxHTTP 2 | ofxIO 3 | ofxMediaType 4 | ofxNetworkUtils 5 | ofxPoco 6 | ofxSSLManager 7 | ofxUnitTests 8 | -------------------------------------------------------------------------------- /tests/client/synchronous/bin/data/pixel.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakercp/ofxHTTP/fa65775e68a0ef8885a257a5ea055993342721a9/tests/client/synchronous/bin/data/pixel.gif --------------------------------------------------------------------------------