Sunshine master
Self-hosted game stream host for Moonlight.
httpcommon.h File Reference

Declarations for common HTTP. More...

#include <curl/curl.h>
#include "network.h"
#include "thread_safe.h"
Include dependency graph for httpcommon.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int http::create_creds (const std::string &pkey, const std::string &cert)
 Generate HTTPS credential files from the provided key and certificate paths.
 
bool http::download_file (const std::string &url, const std::string &file, long ssl_version)
 Send a static file response for a Web UI request.
 
int http::init ()
 Load persisted HTTP credentials and initialize shared request state.
 
int http::reload_user_creds (const std::string &file)
 Reload the Web UI credentials from disk.
 
int http::save_user_creds (const std::string &file, const std::string &username, const std::string &password, bool run_our_mouth)
 Save user creds.
 
std::string http::url_escape (const std::string &url)
 Percent-encode URL data for use in HTTP query strings.
 
std::string http::url_get_host (const std::string &url)
 Extract the host component from a URL string.
 

Detailed Description

Declarations for common HTTP.

Function Documentation

◆ create_creds()

int http::create_creds ( const std::string & pkey,
const std::string & cert )

Generate HTTPS credential files from the provided key and certificate paths.

Parameters
pkeyPrivate key PEM data or private key file path.
certCertificate data or object used by the operation.
Returns
Created creds object or status.

◆ download_file()

bool http::download_file ( const std::string & url,
const std::string & file,
long ssl_version = CURL_SSLVERSION_TLSv1_2 )

Send a static file response for a Web UI request.

Download a URL to a local file using libcurl.

Parameters
urlURL used for the HTTP request.
fileDestination path for the downloaded content.
ssl_versionlibcurl TLS version selector for the request.
Returns
True when the file is downloaded successfully.

◆ init()

int http::init ( )

Load persisted HTTP credentials and initialize shared request state.

Initialize shared HTTP client state.

Returns
0 when HTTP state initializes successfully; nonzero on failure.

◆ reload_user_creds()

int http::reload_user_creds ( const std::string & file)

Reload the Web UI credentials from disk.

Reload Web UI user credentials from disk.

Parameters
fileDestination path for the downloaded content.
Returns
0 when credentials reload successfully; nonzero on failure.

◆ save_user_creds()

int http::save_user_creds ( const std::string & file,
const std::string & username,
const std::string & password,
bool run_our_mouth )

Save user creds.

Parameters
fileCredentials file path.
usernameUsername to save.
passwordPassword to save.
run_our_mouthWhether to log user-facing status messages.
Returns
0 on success, non-zero on failure.

◆ url_escape()

std::string http::url_escape ( const std::string & url)

Percent-encode URL data for use in HTTP query strings.

Percent-encode a string for safe inclusion in a URL.

Parameters
urlURL used for the HTTP request.
Returns
Percent-encoded URL component.

◆ url_get_host()

std::string http::url_get_host ( const std::string & url)

Extract the host component from a URL string.

Extract the host component from a URL.

Parameters
urlURL used for the HTTP request.
Returns
Host name parsed from the URL, or an empty string when none is present.