@@ -196,16 +196,52 @@ static int handle_http1_static_resource(
196196 ret; })
197197
198198#define RESPONSE_TEMPLATE_DYNAMIC_PART1 \
199- "HTTP/1.1 %d\r\n" \
199+ "HTTP/1.1 %d%s%s \r\n" \
200200 "Transfer-Encoding: chunked\r\n"
201201
202+ static const char * http_status_str (enum http_status status )
203+ {
204+ #if defined(CONFIG_HTTP_SERVER_COMPLETE_STATUS_PHRASES )
205+ switch (status ) {
206+ case HTTP_200_OK :
207+ return "OK" ;
208+ case HTTP_201_CREATED :
209+ return "Created" ;
210+ case HTTP_204_NO_CONTENT :
211+ return "No Content" ;
212+ case HTTP_400_BAD_REQUEST :
213+ return "Bad Request" ;
214+ case HTTP_401_UNAUTHORIZED :
215+ return "Unauthorized" ;
216+ case HTTP_403_FORBIDDEN :
217+ return "Forbidden" ;
218+ case HTTP_404_NOT_FOUND :
219+ return "Not Found" ;
220+ case HTTP_405_METHOD_NOT_ALLOWED :
221+ return "Method Not Allowed" ;
222+ case HTTP_500_INTERNAL_SERVER_ERROR :
223+ return "Internal Server Error" ;
224+ default :
225+ return "" ;
226+ }
227+ #endif
228+ return "" ;
229+ }
230+
231+ #if defined(CONFIG_HTTP_SERVER_COMPLETE_STATUS_PHRASES )
232+ #define REASON_PHRASE_MAX_LENGTH sizeof("Internal Server Error")
233+ #else
234+ #define REASON_PHRASE_MAX_LENGTH 0
235+ #endif
236+
202237static int http1_send_headers (struct http_client_ctx * client , enum http_status status ,
203238 const struct http_header * headers , size_t header_count ,
204239 struct http_resource_detail_dynamic * dynamic_detail )
205240{
206241 int ret ;
207242 bool content_type_sent = false;
208- char http_response [MAX (sizeof (RESPONSE_TEMPLATE_DYNAMIC_PART1 ) + sizeof ("xxx" ),
243+ char http_response [MAX (sizeof (RESPONSE_TEMPLATE_DYNAMIC_PART1 ) + sizeof ("xxx" ) +
244+ REASON_PHRASE_MAX_LENGTH ,
209245 CONFIG_HTTP_SERVER_MAX_HEADER_LEN + 2 )];
210246
211247 if (status < HTTP_100_CONTINUE || status > HTTP_511_NETWORK_AUTHENTICATION_REQUIRED ) {
@@ -219,7 +255,9 @@ static int http1_send_headers(struct http_client_ctx *client, enum http_status s
219255 }
220256
221257 /* Send response code and transfer encoding */
222- snprintk (http_response , sizeof (http_response ), RESPONSE_TEMPLATE_DYNAMIC_PART1 , status );
258+ snprintk (http_response , sizeof (http_response ), RESPONSE_TEMPLATE_DYNAMIC_PART1 , status ,
259+ IS_ENABLED (CONFIG_HTTP_SERVER_COMPLETE_STATUS_PHRASES ) ? " " : "" ,
260+ http_status_str (status ));
223261
224262 ret = http_server_sendall (client , http_response ,
225263 strnlen (http_response , sizeof (http_response ) - 1 ));
0 commit comments