Utility functions for URL decoding, form parsing, MIME type lookup, and IP address extraction. More...
#include <string>#include <unordered_map>#include <sstream>
Include dependency graph for url_utils.h:
This graph shows which files directly or indirectly include this file:Go to the source code of this file.
Functions | |
| std::string | trim (const std::string &s) |
| Trim whitespace from the beginning and end of a string. | |
| std::string | urlDecode (const std::string &src) |
| Decode a URL-encoded string (e.g., "a%20b+c" -> "a b c"). | |
| std::unordered_multimap< std::string, std::string > | parseUrlEncoded (const std::string &data) |
| Parse a URL-encoded key-value string into a map. | |
| std::string | getClientIpFromSocket (int sock) |
| Get the client IP address from a socket. | |
| std::string | getMimeType (const std::string &filePath) |
| Get the MIME type based on a file path's extension. | |
These functions support core HTTP functionality including decoding URL-encoded strings, parsing application/x-www-form-urlencoded bodies, detecting client IP addresses, and determining appropriate MIME types for static file serving.
Definition in file url_utils.h.
| std::string getClientIpFromSocket | ( | int | sock | ) |
Uses lwIP's lwip_getpeername() to extract the IP address of the remote peer.
| sock | The socket file descriptor. |
| std::string getMimeType | ( | const std::string & | filePath | ) |
Used when serving static files to determine the appropriate Content-Type.
| filePath | The file path (e.g., "/index.html"). |
Get the MIME type based on a file path's extension.
Get the MIME type based on a file path's extension.
Definition at line 105 of file url_utils.cpp.
Referenced by FileHandler::serveFile().
Here is the caller graph for this function:| std::unordered_multimap< std::string, std::string > parseUrlEncoded | ( | const std::string & | data | ) |
Converts data in the format "key1=value1&key2=value2" into a map. Both keys and values are URL-decoded.
| data | URL-encoded form data. |
Parse a URL-encoded key-value string into a map.
Parse a URL-encoded key-value string into a map.
Definition at line 67 of file url_utils.cpp.
References urlDecode().
Referenced by HttpRequest::getFormParams(), and HttpRequest::getQueryParams().
Here is the call graph for this function:
Here is the caller graph for this function:
|
inline |
| s | The input string. |
Definition at line 27 of file url_utils.h.
| std::string urlDecode | ( | const std::string & | src | ) |
Converts percent-encoded characters and replaces '+' with space.
| src | The URL-encoded input string. |
Decode a URL-encoded string (e.g., "a%20b+c" -> "a b c").
Decode a URL-encoded string (e.g., "a%20b+c" -> "a b c").
Definition at line 28 of file url_utils.cpp.
Referenced by HttpFileserver::handle_static_request(), Router::handleRequest(), and parseUrlEncoded().
Here is the caller graph for this function: