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
20 changes: 14 additions & 6 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.57)
AC_PREREQ([2.71])
m4_define([libhttpserver_MAJOR_VERSION],[0])dnl
m4_define([libhttpserver_MINOR_VERSION],[19])dnl
m4_define([libhttpserver_REVISION],[0])dnl
m4_define([libhttpserver_PKG_VERSION],[libhttpserver_MAJOR_VERSION.libhttpserver_MINOR_VERSION.libhttpserver_REVISION])dnl
m4_define([libhttpserver_LDF_VERSION],[libhttpserver_MAJOR_VERSION:libhttpserver_MINOR_VERSION:libhttpserver_REVISION])dnl
AC_INIT([libhttpserver], libhttpserver_PKG_VERSION, [electrictwister2000@gmail.com])
AC_INIT([libhttpserver],[libhttpserver_PKG_VERSION],[electrictwister2000@gmail.com])
AM_INIT_AUTOMAKE([subdir-objects])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIR([m4])
Expand Down Expand Up @@ -83,7 +83,15 @@ case "$host" in
esac

# Checks for header files.
AC_HEADER_STDC
m4_warn([obsolete],
[The preprocessor macro `STDC_HEADERS' is obsolete.
Except in unusual embedded environments, you can safely include all
ISO C90 headers unconditionally.])dnl
# Autoupdate added the next two lines to ensure that your configure
# script's behavior did not change. They are probably safe to remove.
AC_CHECK_INCLUDES_DEFAULT
AC_PROG_EGREP

AC_CHECK_HEADER([stdint.h],[],[AC_MSG_ERROR("stdint.h not found")])
AC_CHECK_HEADER([inttypes.h],[],[AC_MSG_ERROR("inttypes.h not found")])
AC_CHECK_HEADER([errno.h],[],[AC_MSG_ERROR("errno.h not found")])
Expand Down Expand Up @@ -284,14 +292,14 @@ AC_CONFIG_FILES([examples/cert.pem:examples/cert.pem])
AC_CONFIG_FILES([examples/key.pem:examples/key.pem])
AC_CONFIG_FILES([examples/test_content:examples/test_content])

AC_OUTPUT(
libhttpserver.pc
AC_CONFIG_FILES([libhttpserver.pc
Makefile
doc/Makefile
src/Makefile
test/Makefile
examples/Makefile
)
])
AC_OUTPUT

AC_MSG_NOTICE([Configuration Summary:
Operating System: ${host_os}
Expand Down
4 changes: 2 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
AM_CPPFLAGS = -I../ -I$(srcdir)/httpserver/
METASOURCES = AUTO
lib_LTLIBRARIES = libhttpserver.la
libhttpserver_la_SOURCES = string_utilities.cpp webserver.cpp http_utils.cpp file_info.cpp http_request.cpp http_response.cpp string_response.cpp basic_auth_fail_response.cpp digest_auth_fail_response.cpp deferred_response.cpp file_response.cpp http_resource.cpp details/http_endpoint.cpp
libhttpserver_la_SOURCES = string_utilities.cpp webserver.cpp http_utils.cpp file_info.cpp http_request.cpp http_response.cpp string_response.cpp buffer_response.cpp basic_auth_fail_response.cpp digest_auth_fail_response.cpp deferred_response.cpp file_response.cpp http_resource.cpp details/http_endpoint.cpp
noinst_HEADERS = httpserver/string_utilities.hpp httpserver/details/modded_request.hpp gettext.h
nobase_include_HEADERS = httpserver.hpp httpserver/create_webserver.hpp httpserver/webserver.hpp httpserver/http_utils.hpp httpserver/file_info.hpp httpserver/details/http_endpoint.hpp httpserver/http_request.hpp httpserver/http_response.hpp httpserver/http_resource.hpp httpserver/string_response.hpp httpserver/basic_auth_fail_response.hpp httpserver/digest_auth_fail_response.hpp httpserver/deferred_response.hpp httpserver/file_response.hpp httpserver/http_arg_value.hpp
nobase_include_HEADERS = httpserver.hpp httpserver/create_webserver.hpp httpserver/webserver.hpp httpserver/http_utils.hpp httpserver/file_info.hpp httpserver/details/http_endpoint.hpp httpserver/http_request.hpp httpserver/http_response.hpp httpserver/http_resource.hpp httpserver/string_response.hpp httpserver/buffer_response.hpp httpserver/basic_auth_fail_response.hpp httpserver/digest_auth_fail_response.hpp httpserver/deferred_response.hpp httpserver/file_response.hpp httpserver/http_arg_value.hpp

AM_CXXFLAGS += -fPIC -Wall

Expand Down
35 changes: 35 additions & 0 deletions src/buffer_response.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
This file is part of libhttpserver
Copyright (C) 2011-2019 Sebastiano Merlino

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
*/

#include "httpserver/buffer_response.hpp"
#include <microhttpd.h>
#include <stddef.h>
#include <iosfwd>

struct MHD_Response;

namespace httpserver {

MHD_Response* buffer_response::get_raw_response() {
// Need to use a const cast here to satisfy MHD interface that requires a void*
return MHD_create_response_from_buffer(dataSize, reinterpret_cast<void*>(dataPtr.get()), MHD_RESPMEM_PERSISTENT);
}

} // namespace httpserver
1 change: 1 addition & 0 deletions src/httpserver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "httpserver/http_utils.hpp"
#include "httpserver/file_info.hpp"
#include "httpserver/string_response.hpp"
#include "httpserver/buffer_response.hpp"
#include "httpserver/webserver.hpp"

#endif // SRC_HTTPSERVER_HPP_
66 changes: 66 additions & 0 deletions src/httpserver/buffer_response.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
This file is part of libhttpserver
Copyright (C) 2011-2019 Sebastiano Merlino

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
*/

#if !defined (_HTTPSERVER_HPP_INSIDE_) && !defined (HTTPSERVER_COMPILATION)
#error "Only <httpserver.hpp> or <httpserverpp> can be included directly."
#endif

#ifndef SRC_HTTPSERVER_BUFFER_RESPONSE_HPP_
#define SRC_HTTPSERVER_BUFFER_RESPONSE_HPP_

#include <utility>
#include "httpserver/http_utils.hpp"
#include "httpserver/http_response.hpp"
#include <memory>

struct MHD_Response;

namespace httpserver {

class buffer_response : public http_response {
public:
buffer_response() = default;

explicit buffer_response(
std::unique_ptr<uint8_t[]>& data,
int size,
int response_code = http::http_utils::http_ok,
const std::string& content_type = http::http_utils::text_plain):
http_response(response_code, content_type),
dataPtr(std::move(data)),
dataSize(size) { }

buffer_response(const buffer_response& other) = default;
buffer_response(buffer_response&& other) noexcept = default;

buffer_response& operator=(const buffer_response& b) = default;
buffer_response& operator=(buffer_response&& b) = default;

~buffer_response() = default;

MHD_Response* get_raw_response();

private:
std::unique_ptr<uint8_t[]> dataPtr;
int dataSize = 0;
};

} // namespace httpserver
#endif // SRC_HTTPSERVER_BUFFER_RESPONSE_HPP_