|
121 | 121 | response.set_content(body, mime); \ |
122 | 122 | response.status = response_code |
123 | 123 |
|
| 124 | +// A special case of the 5 param log function for high density HTTP responses |
| 125 | +#define LOG_RESPONSE_5_HD(LOG_LEVEL, msg, response_code, body, mime) \ |
| 126 | + if (msg != body) LOG_F(LOG_LEVEL, "%s", msg); \ |
| 127 | + LOG_F(LOG_LEVEL, "HTTP %d: %s", response_code, HTTP_STATUS_TO_STRING(response_code)); \ |
| 128 | + LOG_F(LOG_LEVEL, "Response body: [%zu bytes] (truncated for brevity)", strlen(body)); \ |
| 129 | + response.set_content(body, mime); \ |
| 130 | + response.status = response_code |
| 131 | + |
124 | 132 | // Essentially a special case of the 5 param log function, where |
125 | 133 | // the message body is in plaintext and is also what you want to log |
126 | 134 | #define LOG_RESPONSE_3(LOG_LEVEL, msg, response_code) \ |
127 | 135 | LOG_RESPONSE_5(LOG_LEVEL, msg, response_code, msg, mime::plaintext) |
128 | 136 |
|
| 137 | +// A special case of the 3 param log function for high density HTTP responses |
| 138 | +#define LOG_RESPONSE_3_HD(LOG_LEVEL, msg, response_code) \ |
| 139 | + LOG_RESPONSE_5_HD(LOG_LEVEL, msg, response_code, msg, mime::plaintext) |
129 | 140 |
|
130 | 141 | // Logs important information about the HTTP request. There are two different |
131 | 142 | // ways to call: a 3 parameter version and a 5 parameter version. |
|
139 | 150 | #define LOG_RESPONSE(...) \ |
140 | 151 | GET_MACRO_5(__VA_ARGS__, LOG_RESPONSE_5, _4, LOG_RESPONSE_3)(__VA_ARGS__) |
141 | 152 |
|
| 153 | +// High-density version of LOG_RESPONSE that truncates large response bodies |
| 154 | +// in logs while still sending the full response to the client. |
| 155 | +// Usage is identical to LOG_RESPONSE but with _HD suffix: |
| 156 | +// |
| 157 | +// LOG_RESPONSE_HD(LOG_LEVEL, msg, response_code) |
| 158 | +// High-density version of 3-parameter LOG_RESPONSE |
| 159 | +// |
| 160 | +// LOG_RESPONSE_HD(LOG_LEVEL, msg, response_code, body, mime) |
| 161 | +// High-density version of 5-parameter LOG_RESPONSE |
| 162 | +#define LOG_RESPONSE_HD(...) \ |
| 163 | + GET_MACRO_5(__VA_ARGS__, LOG_RESPONSE_5_HD, _4, LOG_RESPONSE_3_HD)(__VA_ARGS__) |
| 164 | + |
142 | 165 | #endif // INCLUDE_NETWORK_GCS_MACROS_HPP_ |
0 commit comments