Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple addFile function #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
7 changes: 7 additions & 0 deletions h2o-pp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ void H2OWebserver::addDirectory(const std::string_view path, const std::string_v
h2o_file_register(pathconf, &directory[0], NULL, NULL, 0);
}

void H2OWebserver::addFile(const std::string_view path, const std::string_view file, h2o_hostconf_t* hconf)
{
h2o_pathconf_t *pathconf = h2o_config_register_path(hconf ? hconf : d_hostconf, &path[0], 0);
h2o_mimemap_type_t *mimetype = h2o_mimemap_get_type_by_extension(d_hostconf->mimemap, h2o_get_filext(&file[0], strlen(&file[1])));
h2o_file_register_file(pathconf, &file[0], mimetype, 0);
}

std::string_view convert(const h2o_iovec_t& vec)
{
return std::string_view(vec.base, vec.len);
Expand Down
5 changes: 4 additions & 1 deletion h2o-pp.hh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#define H2O_USE_EPOLL 1
#include "h2o.h"
#include <h2o.h>
#include <string>
#include <functional>
#include "comboaddress.hh"
Expand Down Expand Up @@ -38,6 +38,9 @@ struct H2OWebserver
//! Add a directory to be served on a path. Defaults to adding it to the default host.
void addDirectory(const std::string_view path, const std::string_view directory, h2o_hostconf_t* hconf=0);

//! Add a file to be server on a path. Allows hosting of individual file on a virtual path. Defaults to add it to the default host.
void addFile(const std::string_view path, const std::string_view file, h2o_hostconf_t* hconf=0);

//! Call this to add a TLS context. Returns an accept context that can be used with addListener
h2o_accept_ctx_t* addSSLContext(const std::string_view certificate, const std::string_view key, const std::string_view ciphers="");

Expand Down