From bf197fd7eebcb3579dd659af35822ce88adc66c8 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 22 May 2014 05:29:47 -0400 Subject: http: extract type/subtype portion of content-type When we get a content-type from curl, we get the whole header line, including any parameters, and without any normalization (like downcasing or whitespace) applied. If we later try to match it with strcmp() or even strcasecmp(), we may get false negatives. This could cause two visible behaviors: 1. We might fail to recognize a smart-http server by its content-type. 2. We might fail to relay text/plain error messages to users (especially if they contain a charset parameter). This patch teaches the http code to extract and normalize just the type/subtype portion of the string. This is technically passing out less information to the callers, who can no longer see the parameters. But none of the current callers cares, and a future patch will add back an easier-to-use method for accessing those parameters. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/lib-httpd/error.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 't/lib-httpd') diff --git a/t/lib-httpd/error.sh b/t/lib-httpd/error.sh index 786f2816bb..23cec97cc3 100755 --- a/t/lib-httpd/error.sh +++ b/t/lib-httpd/error.sh @@ -3,6 +3,7 @@ printf "Status: 500 Intentional Breakage\n" printf "Content-Type: " +charset=iso-8859-1 case "$PATH_INFO" in *html*) printf "text/html" @@ -10,8 +11,13 @@ case "$PATH_INFO" in *text*) printf "text/plain" ;; +*charset*) + printf "text/plain; charset=utf-8" + charset=utf-8 + ;; esac printf "\n" printf "\n" -printf "this is the error message\n" +printf "this is the error message\n" | +iconv -f us-ascii -t $charset -- cgit v1.2.1