commit ce889b9

uint  ·  2026-01-31 04:37:26 +0000 UTC
parent 2fca692
capitalise reply_text responses
1 files changed,  +27, -27
+27, -27
  1@@ -399,7 +399,7 @@ static void reply(int c, const char* hdr, const char* status, const char* ctype,
  2 
  3 	if ((size_t)n >= sizeof(resp)) {
  4 		/* fail if header too large */
  5-		reply_text(c, hdr, HTTP_500, "server error\n");
  6+		reply_text(c, hdr, HTTP_500, "Server Error\n");
  7 		return;
  8 	}
  9 
 10@@ -465,7 +465,7 @@ static int stream_file(int c, const struct item* it, const char* hdr, int head_o
 11 	/* build absolute path */
 12 	if (join_path(full, sizeof(full), media_dir, it->path) < 0) {
 13 		LOG(verbose_log, "HTTP", "Stream FAILED      Path too long");
 14-		reply_text(c, hdr, HTTP_500, "Server error\n");
 15+		reply_text(c, hdr, HTTP_500, "Server Error\n");
 16 		return -1;
 17 	}
 18 
 19@@ -473,7 +473,7 @@ static int stream_file(int c, const struct item* it, const char* hdr, int head_o
 20 	int fd = open(full, O_RDONLY);
 21 	if (fd < 0) {
 22 		LOG(verbose_log, "HTTP", "Open FAILED        %s", it->path);
 23-		reply_text(c, hdr, HTTP_404, "Not found\n");
 24+		reply_text(c, hdr, HTTP_404, "Not Found\n");
 25 		return 0;
 26 	}
 27 
 28@@ -481,14 +481,14 @@ static int stream_file(int c, const struct item* it, const char* hdr, int head_o
 29 	struct stat st;
 30 	if (fstat(fd, &st) < 0) {
 31 		close(fd);
 32-		reply_text(c, hdr, HTTP_500, "Server error\n");
 33+		reply_text(c, hdr, HTTP_500, "Server Error\n");
 34 		return -1;
 35 	}
 36 
 37 	/* reject non-regular files */
 38 	if (!S_ISREG(st.st_mode)) {
 39 		close(fd);
 40-		reply_text(c, hdr, HTTP_404, "Not found\n");
 41+		reply_text(c, hdr, HTTP_404, "Not Found\n");
 42 		return 0;
 43 	}
 44 
 45@@ -500,20 +500,20 @@ static int stream_file(int c, const struct item* it, const char* hdr, int head_o
 46 	int partial = parse_range(hdr, total, &start, &end);
 47 	if (partial == RANGE_BAD) {
 48 		close(fd);
 49-		reply_text(c, hdr, HTTP_400, "bad range\n");
 50+		reply_text(c, hdr, HTTP_400, "Bad Range\n");
 51 		return 0;
 52 	}
 53 
 54 	if (partial == RANGE_UNSAT) {
 55 		close(fd);
 56-		reply_text(c, hdr, HTTP_416, "range not satisfiable\n");
 57+		reply_text(c, hdr, HTTP_416, "Range Not Satisfiable\n");
 58 		return 0;
 59 	}
 60 
 61 	if (partial == RANGE_OK) {
 62 		if (lseek(fd, (off_t)start, SEEK_SET) < 0) {
 63 			close(fd);
 64-			reply_text(c, hdr, HTTP_500, "server error\n");
 65+			reply_text(c, hdr, HTTP_500, "Server Error\n");
 66 			return -1;
 67 		}
 68 	}
 69@@ -526,7 +526,7 @@ static int stream_file(int c, const struct item* it, const char* hdr, int head_o
 70 
 71 	if (snprintf(ctype, sizeof(ctype), HTTP_CTYPE, type) >= (int)sizeof(ctype)) {
 72 		close(fd);
 73-		reply_text(c, hdr, HTTP_500, "Server error\n");
 74+		reply_text(c, hdr, HTTP_500, "Server Error\n");
 75 		return -1;
 76 	}
 77 
 78@@ -539,7 +539,7 @@ static int stream_file(int c, const struct item* it, const char* hdr, int head_o
 79 			start, end, total
 80 		) >= (int)sizeof(extra)) {
 81 			close(fd);
 82-			reply_text(c, hdr, HTTP_500, "Server error\n");
 83+			reply_text(c, hdr, HTTP_500, "Server Error\n");
 84 			return -1;
 85 		}
 86 
 87@@ -549,7 +549,7 @@ static int stream_file(int c, const struct item* it, const char* hdr, int head_o
 88 		/* non-partial */
 89 		if (snprintf(extra, sizeof(extra), HTTP_RANGE) >= (int)sizeof(extra)) {
 90 			close(fd);
 91-			reply_text(c, hdr, HTTP_500, "Server error\n");
 92+			reply_text(c, hdr, HTTP_500, "Server Error\n");
 93 			return -1;
 94 		}
 95 
 96@@ -615,7 +615,7 @@ int http_handle(int c)
 97 	hdr[0] = '\0';
 98 
 99 	if (read_request(c, method, sizeof(method), path, sizeof(path), hdr, sizeof(hdr)) < 0) {
100-		reply_text(c, hdr, HTTP_400, "bad request\n");
101+		reply_text(c, hdr, HTTP_400, "Bad Request\n");
102 		return -1;
103 	}
104 	LOG(verbose_log, "HTTP", "Request            %s %s", method, path);
105@@ -633,13 +633,13 @@ int http_handle(int c)
106 	}
107 	else {
108 		LOG(verbose_log, "HTTP", "Method forbidden   %s", method);
109-		reply_text(c, hdr, HTTP_405, "method not allowed\n");
110+		reply_text(c, hdr, HTTP_405, "Method Not Allowed\n");
111 		return 0;
112 	}
113 
114 	if (strcmp(path, "/ping") == 0) {
115 		LOG(verbose_log, "HTTP", "Route              /ping");
116-		reply_text(c, hdr, HTTP_200, "ok\n");
117+		reply_text(c, hdr, HTTP_200, "OK\n");
118 		return 0;
119 	}
120 
121@@ -668,7 +668,7 @@ int http_handle(int c)
122 				view.items = calloc(lib.len, sizeof(*view.items));
123 				if (!view.items) {
124 					pthread_rwlock_unlock(&lib_lock);
125-					reply_text(c, hdr, HTTP_500, "server error\n");
126+					reply_text(c, hdr, HTTP_500, "Server Error\n");
127 					return -1;
128 				}
129 			}
130@@ -688,7 +688,7 @@ int http_handle(int c)
131 			pthread_rwlock_unlock(&lib_lock);
132 
133 			LOG(verbose_log, "JSON", "Encode     FAILED");
134-			reply_text(c, hdr, HTTP_500, "json encode failed\n");
135+			reply_text(c, hdr, HTTP_500, "JSON Encode Failed\n");
136 			return -1;
137 		}
138 
139@@ -741,13 +741,13 @@ int http_handle(int c)
140 
141 		if (ok < 0) {
142 			LOG(true, "SCAN", "Rescan FAILED      %s (%ld ms)", media_dir, ms);
143-			reply_text(c, hdr, HTTP_500, "rescan failed\n");
144+			reply_text(c, hdr, HTTP_500, "Rescan Failed\n");
145 			return -1;
146 		}
147 
148 		LOG(true, "SCAN", "Rescan OK          %zu -> %zu (%ld ms)", before, after, ms);
149 
150-		reply_text(c, hdr, HTTP_200, "ok\n");
151+		reply_text(c, hdr, HTTP_200, "OK\n");
152 		return 0;
153 	}
154 
155@@ -756,18 +756,18 @@ int http_handle(int c)
156 
157 		uint64_t id;
158 		if (parse_hex64(path + 8, &id) < 0) {
159-			reply_text(c, hdr, HTTP_400, "bad request\n");
160+			reply_text(c, hdr, HTTP_400, "Bad Request\n");
161 			return 0;
162 		}
163 
164 		char rel[4096];
165 		int fr = item_path_for_id(rel, id, u);
166 		if (fr == 1) {
167-			reply_text(c, hdr, HTTP_404, "not found\n");
168+			reply_text(c, hdr, HTTP_404, "Not Found\n");
169 			return 0;
170 		}
171 		if (fr < 0) {
172-			reply_text(c, hdr, HTTP_500, "server error\n");
173+			reply_text(c, hdr, HTTP_500, "Server Error\n");
174 			return -1;
175 		}
176 
177@@ -783,19 +783,19 @@ int http_handle(int c)
178 
179 		uint64_t id;
180 		if (parse_hex64(path + 6, &id) < 0) {
181-			reply_text(c, hdr, HTTP_400, "bad request\n");
182+			reply_text(c, hdr, HTTP_400, "Bad Request\n");
183 			return 0;
184 		}
185 
186 		char rel[4096];
187 		int fr = item_path_for_id(rel, id, u);
188 		if (fr == 1) {
189-			reply_text(c, hdr, HTTP_404, "not found\n");
190+			reply_text(c, hdr, HTTP_404, "Not Found\n");
191 			return 0;
192 		}
193 
194 		if (fr < 0) {
195-			reply_text(c, hdr, HTTP_500, "server error\n");
196+			reply_text(c, hdr, HTTP_500, "Server Error\n");
197 			return -1;
198 		}
199 
200@@ -805,7 +805,7 @@ int http_handle(int c)
201 
202 		struct stat st;
203 		if (stat_item(&tmp, &st) < 0) {
204-			reply_text(c, hdr, HTTP_404, "not found\n");
205+			reply_text(c, hdr, HTTP_404, "Not Found\n");
206 			return 0;
207 		}
208 
209@@ -813,7 +813,7 @@ int http_handle(int c)
210 
211 		struct json j;
212 		if (json_meta(&j, &tmp, (size_t)st.st_size, (long)st.st_mtime, type) < 0) {
213-			reply_text(c, hdr, HTTP_500, "json failed\n");
214+			reply_text(c, hdr, HTTP_500, "JSON Failed\n");
215 			return -1;
216 		}
217 
218@@ -824,7 +824,7 @@ int http_handle(int c)
219 	}
220 
221 	LOG(verbose_log, "HTTP", "Route not found    %s", path);
222-	reply_text(c, hdr, HTTP_404, "not found\n");
223+	reply_text(c, hdr, HTTP_404, "Not Found\n");
224 
225 	return 0;
226 }