From c04b7fd36c8d7be0f8eee6b82189f22b8941d6af Mon Sep 17 00:00:00 2001 From: Alexey Rogachevskiy Date: Mon, 17 Aug 2020 18:04:25 +0300 Subject: [PATCH 01/10] Update package.xml and CMakeLists for Noetic * package.xml updated to version 3 to allow conditional dependencies * CMakeLists: cmake_minimum_required set to 3.0.2 --- CMakeLists.txt | 2 +- package.xml | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 163132c..f433129 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.8.3) +cmake_minimum_required(VERSION 3.0.2) project(async_web_server_cpp) ## Find catkin macros and libraries diff --git a/package.xml b/package.xml index 882fbca..60c5640 100644 --- a/package.xml +++ b/package.xml @@ -1,4 +1,4 @@ - + async_web_server_cpp 0.0.3 Asynchronous Web/WebSocket Server in C++ @@ -23,5 +23,6 @@ rostest rospy roslib - python-websocket + python-websocket + python3-websocket From c12e54164e9f0705c7f1f966739c8e650364423c Mon Sep 17 00:00:00 2001 From: Alexey Rogachevskiy Date: Mon, 17 Aug 2020 18:05:43 +0300 Subject: [PATCH 02/10] test: Add catkin_INCLUDE_DIRS to tests --- test/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f42bd54..f127373 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,5 +1,6 @@ add_executable(test_web_server EXCLUDE_FROM_ALL test_web_server.cpp) target_link_libraries(test_web_server ${PROJECT_NAME} ${catkin_LIBRARIES}) +target_include_directories(test_web_server PRIVATE ${catkin_INCLUDE_DIRS}) if(TARGET tests) add_dependencies(tests From e2496ebc45e59a3c800f27e974bf793b1ae0045f Mon Sep 17 00:00:00 2001 From: Alexey Rogachevskiy Date: Mon, 17 Aug 2020 18:06:49 +0300 Subject: [PATCH 03/10] test: Update simple_http_request_test.py for Python 3 --- test/simple_http_requests_test.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/test/simple_http_requests_test.py b/test/simple_http_requests_test.py index 4a5e5f3..9d1e738 100755 --- a/test/simple_http_requests_test.py +++ b/test/simple_http_requests_test.py @@ -1,6 +1,10 @@ #! /usr/bin/env python -import httplib +import sys +if sys.version_info > (3,): + import http.client as httplib +else: + import httplib import rospy import unittest import time @@ -48,17 +52,17 @@ def test_default_action(self): self.conn.request("GET", "/a_static_response") response = self.conn.getresponse() self.assertEqual(200, response.status) - self.assertEqual("A RESPONSE", response.read()) + self.assertEqual(b"A RESPONSE", response.read()) def test_http_echo1(self): - test_content = "hello HELLO"*1000 # make sure to exceed MTU + test_content = b"hello HELLO"*1000 # make sure to exceed MTU self.conn.request("GET", "/http_body_echo", test_content) response = self.conn.getresponse() self.assertEqual(200, response.status) self.assertEqual(test_content, response.read()) def test_http_echo2(self): - test_content = "THIS is A test"*1000 # make sure to exceed MTU + test_content = b"THIS is A test"*1000 # make sure to exceed MTU self.conn.request("POST", "/http_body_echo", test_content) response = self.conn.getresponse() self.assertEqual(200, response.status) @@ -68,25 +72,25 @@ def test_http_path_echo(self): self.conn.request("GET", "/http_path_echo/this_is_a_test") response = self.conn.getresponse() self.assertEqual(200, response.status) - self.assertEqual("/http_path_echo/this_is_a_test", response.read()) + self.assertEqual(b"/http_path_echo/this_is_a_test", response.read()) def test_http_query_echo(self): self.conn.request("GET", "/http_query_echo?hello=1&b=test&c=10") response = self.conn.getresponse() self.assertEqual(200, response.status) - self.assertEqual("b=test\nc=10\nhello=1\n", response.read()) + self.assertEqual(b"b=test\nc=10\nhello=1\n", response.read()) def test_file(self): self.conn.request("GET", "/test_file") response = self.conn.getresponse() self.assertEqual(200, response.status) - self.assertEqual("\n", response.read()) + self.assertEqual(b"\n", response.read()) def test_file_from_filesystem(self): self.conn.request("GET", "/test_files/test_dir/test_file.txt") response = self.conn.getresponse() self.assertEqual(200, response.status) - self.assertEqual("test\n", response.read()) + self.assertEqual(b"test\n", response.read()) def test_directory_listing_forbidden_from_filesystem1(self): self.conn.request("GET", "/test_files/test_dir/") From d1b4a61eab4ddc18cf6d6aa7f0dc7ff19ed7d341 Mon Sep 17 00:00:00 2001 From: Alexey Rogachevskiy Date: Mon, 17 Aug 2020 18:07:15 +0300 Subject: [PATCH 04/10] test: Update websocket_test for Python 3 --- test/websocket_test.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/websocket_test.py b/test/websocket_test.py index 67516d9..71afb7f 100755 --- a/test/websocket_test.py +++ b/test/websocket_test.py @@ -20,15 +20,15 @@ def test_ok(self): self.ws.send("hi") self.assertEqual("hi", self.ws.recv()) - self.ws.ping("test ping") + self.ws.ping(b"test ping") ping_echo = self.ws.recv_frame() self.assertEqual(9, ping_echo.opcode) - self.assertEqual("test ping", ping_echo.data) + self.assertEqual(b"test ping", ping_echo.data) - self.ws.pong("test pong") + self.ws.pong(b"test pong") pong_echo = self.ws.recv_frame() self.assertEqual(10, pong_echo.opcode) - self.assertEqual("test pong", pong_echo.data) + self.assertEqual(b"test pong", pong_echo.data) if __name__ == '__main__': time.sleep(1) # ensure server is up From 36547b47d367bd0e5acf182523cf5654f42c3137 Mon Sep 17 00:00:00 2001 From: Alexey Rogachevskiy Date: Mon, 17 Aug 2020 18:15:50 +0300 Subject: [PATCH 05/10] http_reply: Always return value from function --- src/http_reply.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/http_reply.cpp b/src/http_reply.cpp index 92b6840..c6f2a39 100644 --- a/src/http_reply.cpp +++ b/src/http_reply.cpp @@ -350,8 +350,8 @@ bool FilesystemHttpRequestHandler::operator()(const HttpRequest &request, boost: } } else { - return false; - } + return false; +} } From b274f253ff9bf5697978a0599c33f5867f158d10 Mon Sep 17 00:00:00 2001 From: Alexey Rogachevskiy Date: Mon, 17 Aug 2020 18:17:09 +0300 Subject: [PATCH 06/10] http_connection, http_reply: Fix unused variable errors --- src/http_connection.cpp | 1 + src/http_reply.cpp | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/http_connection.cpp b/src/http_connection.cpp index 72e94e1..23e419b 100644 --- a/src/http_connection.cpp +++ b/src/http_connection.cpp @@ -134,6 +134,7 @@ void HttpConnection::write_pending() void HttpConnection::handle_write(const boost::system::error_code &e, std::vector resources) { + (void) resources; boost::mutex::scoped_lock lock(write_mutex_); write_in_progress_ = false; if (!e) diff --git a/src/http_reply.cpp b/src/http_reply.cpp index c6f2a39..56b3cee 100644 --- a/src/http_reply.cpp +++ b/src/http_reply.cpp @@ -279,6 +279,9 @@ static bool serveFromFile(HttpReply::status_type status, const std::string& file } bool FileHttpRequestHandler::operator()(const HttpRequest &request, boost::shared_ptr connection, const char* begin, const char* end) { + (void) request; + (void) begin; + (void) end; return serveFromFile(status_, filename_, headers_, connection); } @@ -383,6 +386,9 @@ StaticHttpRequestHandler::StaticHttpRequestHandler(HttpReply::status_type status bool StaticHttpRequestHandler::operator()(const HttpRequest &request, boost::shared_ptr connection, const char* begin, const char* end) { + (void) request; + (void) begin; + (void) end; reply_builder_.write(connection); connection->write(content_string_); return true; From 4f607a53b6fca087e3f5ee4f655301b127d34561 Mon Sep 17 00:00:00 2001 From: Alexey Rogachevskiy Date: Mon, 17 Aug 2020 18:19:19 +0300 Subject: [PATCH 07/10] Fix type comparisons --- src/http_request.cpp | 2 +- src/http_request_handler.cpp | 4 ++-- src/websocket_message.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/http_request.cpp b/src/http_request.cpp index 7fe52e6..ce696e2 100644 --- a/src/http_request.cpp +++ b/src/http_request.cpp @@ -23,7 +23,7 @@ bool HttpRequest::parse_uri() BOOST_FOREACH(const std::string & pair_string, pair_strings) { std::vector pair_data; - const int eq_index = pair_string.find_first_of('='); + const size_t eq_index = pair_string.find_first_of('='); if (eq_index == std::string::npos) { if (pair_string.size() > 0) diff --git a/src/http_request_handler.cpp b/src/http_request_handler.cpp index a949342..35d1e19 100644 --- a/src/http_request_handler.cpp +++ b/src/http_request_handler.cpp @@ -45,7 +45,7 @@ void HttpRequestHandlerGroup::addHandler(HandlerPredicate predicate, HttpServerR bool HttpRequestHandlerGroup::operator()(const HttpRequest &request, boost::shared_ptr connection, const char* begin, const char* end) { - for (int i = 0; i < handlers_.size(); ++i) + for (size_t i = 0; i < handlers_.size(); ++i) { std::pair &handler = handlers_[i]; if (handler.first(request)) @@ -87,7 +87,7 @@ class BodyCollectingConnection : public boost::enable_shared_from_this= length_) { + if(received_length_ >= size_t(length_)) { handler_(request_, connection_, body_stream_.str().substr(0, length_)); } else { diff --git a/src/websocket_message.cpp b/src/websocket_message.cpp index 038deb3..74a2609 100644 --- a/src/websocket_message.cpp +++ b/src/websocket_message.cpp @@ -194,7 +194,7 @@ boost::tribool WebsocketFrameParser::consume(WebsocketFrame& frame, char input) //unmask the frame if (frame.header.mask) { - for (int i = 0; i < frame.length; ++i) + for (uint64_t i = 0; i < frame.length; ++i) { frame.content[i] = frame.content[i] ^ frame.mask[i % 4]; } From 1ade8be15a8ce25344c91d4ef2f42e2c8d02fd6b Mon Sep 17 00:00:00 2001 From: Alexey Rogachevskiy Date: Mon, 17 Aug 2020 18:20:23 +0300 Subject: [PATCH 08/10] http_reply: Always return value from function, take two First commit did not have all changes --- src/http_reply.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/http_reply.cpp b/src/http_reply.cpp index 56b3cee..efd1990 100644 --- a/src/http_reply.cpp +++ b/src/http_reply.cpp @@ -352,10 +352,8 @@ bool FilesystemHttpRequestHandler::operator()(const HttpRequest &request, boost: return false; } } - else { return false; } -} HttpServerRequestHandler HttpReply::stock_reply(HttpReply::status_type status) From 5dbf05caed2a5dd1879997d3340124c3ce8b5452 Mon Sep 17 00:00:00 2001 From: Alexey Rogachevskiy Date: Mon, 17 Aug 2020 18:53:05 +0300 Subject: [PATCH 09/10] travis: Dockerize pipeline --- .travis.yml | 46 ++++++++++++++++------------------------------ 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7d16d0d..fc728ec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,37 +1,23 @@ -sudo: required -dist: trusty +os: linux +dist: bionic language: generic -compiler: - - gcc +services: + - docker env: - global: - - CATKIN_WS=~/catkin_ws - - CATKIN_WS_SRC=${CATKIN_WS}/src matrix: - - CI_ROS_DISTRO="indigo" - - CI_ROS_DISTRO="jade" - -branches: - only: - - master - - develop + - CI_ROS_DISTRO="kinetic" + - CI_ROS_DISTRO="melodic" + - CI_ROS_DISTRO="noetic" install: - - sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu trusty main" > /etc/apt/sources.list.d/ros-latest.list' - - wget http://packages.ros.org/ros.key -O - | sudo apt-key add - - - sudo apt-get update -qq - - sudo apt-get install -qq -y python-rosdep python-catkin-tools - - sudo rosdep init - - rosdep update - - rosdep install --from-paths ./ -i -y --rosdistro $CI_ROS_DISTRO + - docker pull ros:${CI_ROS_DISTRO}-ros-core + - docker run --name ci_runner -i -d --rm -v $(pwd):/catkin_ws/src ros:${CI_ROS_DISTRO}-ros-core + - if [ "${CI_ROS_DISTRO}" == "noetic" ]; then docker exec ci_runner /bin/bash -c "apt update; apt install -y python3-rosdep python3-catkin-tools python3-osrf-pycommon"; fi + - if [ "${CI_ROS_DISTRO}" != "noetic" ]; then docker exec ci_runner /bin/bash -c "apt update; apt install -y python-rosdep python-catkin-tools"; fi + - docker exec ci_runner /bin/bash -c "source ./ros_entrypoint.sh; rosdep init; rosdep update; rosdep install --from-paths /catkin_ws/src --ignore-src -y" script: - - source /opt/ros/$CI_ROS_DISTRO/setup.bash - - mkdir -p $CATKIN_WS_SRC - - ln -s $TRAVIS_BUILD_DIR $CATKIN_WS_SRC - - cd $CATKIN_WS - - catkin init - - catkin config --install - - catkin build --limit-status-rate 0.1 --no-notify -DCMAKE_BUILD_TYPE=Release - - catkin build --limit-status-rate 0.1 --no-notify --make-args tests - - catkin run_tests + - docker exec ci_runner /bin/bash -c "source ./ros_entrypoint.sh; cd /catkin_ws; catkin init; catkin config --install" + - docker exec ci_runner /bin/bash -c "source ./ros_entrypoint.sh; cd /catkin_ws; catkin build --limit-status-rate 0.1 --no-notify -DCMAKE_BUILD_TYPE=Release" + - docker exec ci_runner /bin/bash -c "source ./ros_entrypoint.sh; cd /catkin_ws; catkin build --limit-status-rate 0.1 --no-notify --make-args tests" + - docker exec ci_runner /bin/bash -c "source ./ros_entrypoint.sh; cd /catkin_ws; catkin run_tests" From 636c9e3de63f89c99b18c8cbbe2ec950e1d34785 Mon Sep 17 00:00:00 2001 From: Alexey Rogachevskiy Date: Mon, 17 Aug 2020 19:00:18 +0300 Subject: [PATCH 10/10] travis: Install compilers, etc --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index fc728ec..05fbc71 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,8 +12,9 @@ env: install: - docker pull ros:${CI_ROS_DISTRO}-ros-core - docker run --name ci_runner -i -d --rm -v $(pwd):/catkin_ws/src ros:${CI_ROS_DISTRO}-ros-core - - if [ "${CI_ROS_DISTRO}" == "noetic" ]; then docker exec ci_runner /bin/bash -c "apt update; apt install -y python3-rosdep python3-catkin-tools python3-osrf-pycommon"; fi - - if [ "${CI_ROS_DISTRO}" != "noetic" ]; then docker exec ci_runner /bin/bash -c "apt update; apt install -y python-rosdep python-catkin-tools"; fi + - docker exec ci_runner /bin/bash -c "apt update; apt install -y build-essential" + - if [ "${CI_ROS_DISTRO}" == "noetic" ]; then docker exec ci_runner /bin/bash -c "apt install -y python3-rosdep python3-catkin-tools python3-osrf-pycommon"; fi + - if [ "${CI_ROS_DISTRO}" != "noetic" ]; then docker exec ci_runner /bin/bash -c "apt install -y python-rosdep python-catkin-tools"; fi - docker exec ci_runner /bin/bash -c "source ./ros_entrypoint.sh; rosdep init; rosdep update; rosdep install --from-paths /catkin_ws/src --ignore-src -y" script: