Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 17 additions & 30 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,24 @@
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
- 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:
- 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"
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 3 additions & 2 deletions package.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<package format="2">
<package format="3">
<name>async_web_server_cpp</name>
<version>0.0.3</version>
<description>Asynchronous Web/WebSocket Server in C++</description>
Expand All @@ -23,5 +23,6 @@
<test_depend>rostest</test_depend>
<test_depend>rospy</test_depend>
<test_depend>roslib</test_depend>
<test_depend>python-websocket</test_depend>
<test_depend condition="$ROS_PYTHON_VERSION==2">python-websocket</test_depend>
<test_depend condition="$ROS_PYTHON_VERSION==3">python3-websocket</test_depend>
</package>
1 change: 1 addition & 0 deletions src/http_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ void HttpConnection::write_pending()
void HttpConnection::handle_write(const boost::system::error_code &e,
std::vector<ResourcePtr> resources)
{
(void) resources;
boost::mutex::scoped_lock lock(write_mutex_);
write_in_progress_ = false;
if (!e)
Expand Down
10 changes: 7 additions & 3 deletions src/http_reply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ static bool serveFromFile(HttpReply::status_type status, const std::string& file
}
bool FileHttpRequestHandler::operator()(const HttpRequest &request, boost::shared_ptr<HttpConnection> connection, const char* begin, const char* end)
{
(void) request;
(void) begin;
(void) end;
return serveFromFile(status_, filename_, headers_, connection);
}

Expand Down Expand Up @@ -349,9 +352,7 @@ bool FilesystemHttpRequestHandler::operator()(const HttpRequest &request, boost:
return false;
}
}
else {
return false;
}
return false;
}


Expand Down Expand Up @@ -383,6 +384,9 @@ StaticHttpRequestHandler::StaticHttpRequestHandler(HttpReply::status_type status

bool StaticHttpRequestHandler::operator()(const HttpRequest &request, boost::shared_ptr<HttpConnection> connection, const char* begin, const char* end)
{
(void) request;
(void) begin;
(void) end;
reply_builder_.write(connection);
connection->write(content_string_);
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/http_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ bool HttpRequest::parse_uri()
BOOST_FOREACH(const std::string & pair_string, pair_strings)
{
std::vector<std::string> 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)
Expand Down
4 changes: 2 additions & 2 deletions src/http_request_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void HttpRequestHandlerGroup::addHandler(HandlerPredicate predicate, HttpServerR

bool HttpRequestHandlerGroup::operator()(const HttpRequest &request, boost::shared_ptr<HttpConnection> 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<HandlerPredicate, HttpServerRequestHandler> &handler = handlers_[i];
if (handler.first(request))
Expand Down Expand Up @@ -87,7 +87,7 @@ class BodyCollectingConnection : public boost::enable_shared_from_this<BodyColle
std::string chunk(begin, end-begin);
body_stream_ << chunk;
received_length_ += chunk.length();
if(received_length_ >= length_) {
if(received_length_ >= size_t(length_)) {
handler_(request_, connection_, body_stream_.str().substr(0, length_));
}
else {
Expand Down
2 changes: 1 addition & 1 deletion src/websocket_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
20 changes: 12 additions & 8 deletions test/simple_http_requests_test.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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("<html></html>\n", response.read())
self.assertEqual(b"<html></html>\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/")
Expand Down
8 changes: 4 additions & 4 deletions test/websocket_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down