Sunshine v2026.319.132152
Self-hosted game stream host for Moonlight.
confighttp.h File Reference

Declarations for the Web UI Config HTTP server. More...

#include <filesystem>
#include <memory>
#include <string>
#include <nlohmann/json.hpp>
#include <Simple-Web-Server/server_https.hpp>
#include "thread_safe.h"
Include dependency graph for confighttp.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define WEB_DIR   SUNSHINE_ASSETS_DIR "/web/"
 

Functions

bool confighttp::authenticate (const resp_https_t &response, const req_https_t &request)
 Authenticate the user.
 
void confighttp::bad_request (const resp_https_t &response, const req_https_t &request, const std::string &error_message)
 Send a 400 Bad Request response.
 
void confighttp::browseDirectory (const resp_https_t &response, const req_https_t &request)
 Browse the server filesystem.
 
nlohmann::json confighttp::build_browse_entries (const std::filesystem::path &dir_path, const std::string &type_str)
 Lists, filters, and sorts the entries of a directory for the browse API.
 
bool confighttp::check_app_index (const resp_https_t &response, const req_https_t &request, int index)
 Validates the application index and sends an error response if invalid.
 
bool confighttp::check_content_type (const resp_https_t &response, const req_https_t &request, const std::string_view &contentType)
 Validate the request content type and send a bad request when mismatched.
 
std::string confighttp::generate_csrf_token (const std::string &client_id)
 Generate a new CSRF token for a client.
 
std::string confighttp::get_client_id (const req_https_t &request)
 Get a unique client identifier for CSRF token management.
 
nlohmann::json confighttp::get_windows_drives ()
 Builds a JSON array of available Windows drive letters.
 
void confighttp::getAsset (const resp_https_t &response, const req_https_t &request)
 Get an asset.
 
void confighttp::getCSRFToken (const resp_https_t &response, const req_https_t &request)
 Get a CSRF token for the authenticated user.
 
void confighttp::getLocale (const resp_https_t &response, const req_https_t &request)
 Get the locale setting. This endpoint does not require authentication.
 
void confighttp::getPage (const resp_https_t &response, const req_https_t &request, const char *html_file, const bool require_auth, const bool redirect_if_username)
 Get an HTML page.
 
bool confighttp::is_browsable_executable (const std::filesystem::directory_entry &entry, const std::filesystem::file_status &status)
 Checks whether a directory entry qualifies as an executable file.
 
void confighttp::not_found (const resp_https_t &response, const req_https_t &request, const std::string &error_message)
 Send a 404 Not Found response.
 
void confighttp::print_req (const req_https_t &request)
 Log the request details.
 
void confighttp::send_redirect (const resp_https_t &response, const req_https_t &request, const char *path)
 Send a redirect response.
 
void confighttp::send_response (const resp_https_t &response, const nlohmann::json &output_tree)
 Send a response.
 
void confighttp::send_unauthorized (const resp_https_t &response, const req_https_t &request)
 Send a 401 Unauthorized response.
 
void confighttp::start ()
 
bool confighttp::validate_csrf_token (const resp_https_t &response, const req_https_t &request, const std::string &client_id)
 

Variables

const std::map< std::string, std::string > mime_types
 
constexpr auto confighttp::PORT_HTTPS = 1
 

Detailed Description

Declarations for the Web UI Config HTTP server.

Function Documentation

◆ authenticate()

bool confighttp::authenticate ( const resp_https_t & response,
const req_https_t & request )

Authenticate the user.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.
Returns
True if the user is authenticated, false otherwise.

◆ bad_request()

void confighttp::bad_request ( const resp_https_t & response,
const req_https_t & request,
const std::string & error_message )

Send a 400 Bad Request response.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.
error_messageThe error message to include in the response.

◆ browseDirectory()

void confighttp::browseDirectory ( const resp_https_t & response,
const req_https_t & request )

Browse the server filesystem.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.
Note
On Windows, an empty or root path returns the list of available drive letters.
On non-Windows, an empty path defaults to the filesystem root ("/").

◆ build_browse_entries()

nlohmann::json confighttp::build_browse_entries ( const std::filesystem::path & dir_path,
const std::string & type_str )

Lists, filters, and sorts the entries of a directory for the browse API.

Parameters
dir_pathThe directory to list.
type_strFilter type: "directory", "executable", "file", or "any".
Returns
Sorted JSON array of entry objects with name/type/path fields.

◆ check_app_index()

bool confighttp::check_app_index ( const resp_https_t & response,
const req_https_t & request,
int index )

Validates the application index and sends an error response if invalid.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.
indexThe application index/id.

◆ check_content_type()

bool confighttp::check_content_type ( const resp_https_t & response,
const req_https_t & request,
const std::string_view & contentType )

Validate the request content type and send a bad request when mismatched.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.
contentTypeThe expected content type

◆ generate_csrf_token()

std::string confighttp::generate_csrf_token ( const std::string & client_id)

Generate a new CSRF token for a client.

Parameters
client_idA unique identifier for the client (e.g., session ID or username).
Returns
The generated CSRF token.

◆ get_client_id()

std::string confighttp::get_client_id ( const req_https_t & request)

Get a unique client identifier for CSRF token management.

Parameters
requestThe HTTP request object.
Returns
A unique identifier based on username or IP address.

◆ get_windows_drives()

nlohmann::json confighttp::get_windows_drives ( )

Builds a JSON array of available Windows drive letters.

Returns
JSON array of drive-letter entries.

◆ getAsset()

void confighttp::getAsset ( const resp_https_t & response,
const req_https_t & request )

Get an asset.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

◆ getCSRFToken()

void confighttp::getCSRFToken ( const resp_https_t & response,
const req_https_t & request )

Get a CSRF token for the authenticated user.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

◆ getLocale()

void confighttp::getLocale ( const resp_https_t & response,
const req_https_t & request )

Get the locale setting. This endpoint does not require authentication.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

◆ getPage()

void confighttp::getPage ( const resp_https_t & response,
const req_https_t & request,
const char * html_file,
const bool require_auth,
const bool redirect_if_username )

Get an HTML page.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.
html_fileThe HTML file to serve (relative to WEB_DIR).
require_authWhether to require authentication (default: true).
redirect_if_usernameIf true, redirect to "/" when the username is set (for welcome page).

◆ is_browsable_executable()

bool confighttp::is_browsable_executable ( const std::filesystem::directory_entry & entry,
const std::filesystem::file_status & status )

Checks whether a directory entry qualifies as an executable file.

Parameters
entryThe directory entry to check.
statusThe cached file status for the entry.
Returns
True if the file should be included in an executable-type listing.

◆ not_found()

void confighttp::not_found ( const resp_https_t & response,
const req_https_t & request,
const std::string & error_message )

Send a 404 Not Found response.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.
error_messageThe error message to include in the response.

◆ print_req()

void confighttp::print_req ( const req_https_t & request)

Log the request details.

Parameters
requestThe HTTP request object.

◆ send_redirect()

void confighttp::send_redirect ( const resp_https_t & response,
const req_https_t & request,
const char * path )

Send a redirect response.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.
pathThe path to redirect to.

◆ send_response()

void confighttp::send_response ( const resp_https_t & response,
const nlohmann::json & output_tree )

Send a response.

Parameters
responseThe HTTP response object.
output_treeThe JSON tree to send.

◆ send_unauthorized()

void confighttp::send_unauthorized ( const resp_https_t & response,
const req_https_t & request )

Send a 401 Unauthorized response.

Parameters
responseThe HTTP response object.
requestThe HTTP request object.

Variable Documentation

◆ mime_types

const std::map<std::string, std::string> mime_types
Initial value:
= {
{"css", "text/css"},
{"gif", "image/gif"},
{"htm", "text/html"},
{"html", "text/html"},
{"ico", "image/x-icon"},
{"jpeg", "image/jpeg"},
{"jpg", "image/jpeg"},
{"js", "application/javascript"},
{"json", "application/json"},
{"png", "image/png"},
{"svg", "image/svg+xml"},
{"ttf", "font/ttf"},
{"txt", "text/plain"},
{"woff2", "font/woff2"},
{"xml", "text/xml"},
}