From: Junio C Hamano Date: Mon, 16 Jun 2014 19:18:35 +0000 (-0700) Subject: Merge branch 'jk/http-errors' X-Git-Tag: v2.1.0-rc0~112 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/2075a0c27fa5cf4f9f03964d407dc015c1749a7e?ds=inline;hp=-c Merge branch 'jk/http-errors' Propagate the error messages from the webserver better to the client coming over the HTTP transport. * jk/http-errors: http: default text charset to iso-8859-1 remote-curl: reencode http error messages strbuf: add strbuf_reencode helper http: optionally extract charset parameter from content-type http: extract type/subtype portion of content-type t5550: test display of remote http error messages t/lib-httpd: use write_script to copy CGI scripts test-lib: preserve GIT_CURL_VERBOSE from the environment --- 2075a0c27fa5cf4f9f03964d407dc015c1749a7e diff --combined Documentation/technical/api-strbuf.txt index 50690186d3,9d28b034ad..077a7096a4 --- a/Documentation/technical/api-strbuf.txt +++ b/Documentation/technical/api-strbuf.txt @@@ -121,23 -121,15 +121,28 @@@ Function * Related to the contents of the buffer +`strbuf_trim`:: + + Strip whitespace from the beginning and end of a string. + Equivalent to performing `strbuf_rtrim()` followed by `strbuf_ltrim()`. + `strbuf_rtrim`:: Strip whitespace from the end of a string. +`strbuf_ltrim`:: + + Strip whitespace from the beginning of a string. + + `strbuf_reencode`:: + + Replace the contents of the strbuf with a reencoded form. Returns -1 + on error, 0 on success. + +`strbuf_tolower`:: + + Lowercase each character in the buffer using `tolower`. + `strbuf_cmp`:: Compare two buffers. Returns an integer less than, equal to, or greater diff --combined strbuf.c index c8217755e5,fc7290f57a..ac62982e67 --- a/strbuf.c +++ b/strbuf.c @@@ -1,5 -1,6 +1,6 @@@ #include "cache.h" #include "refs.h" + #include "utf8.h" int starts_with(const char *str, const char *prefix) { @@@ -78,8 -79,15 +79,8 @@@ void strbuf_grow(struct strbuf *sb, siz void strbuf_trim(struct strbuf *sb) { - char *b = sb->buf; - while (sb->len > 0 && isspace((unsigned char)sb->buf[sb->len - 1])) - sb->len--; - while (sb->len > 0 && isspace(*b)) { - b++; - sb->len--; - } - memmove(sb->buf, b, sb->len); - sb->buf[sb->len] = '\0'; + strbuf_rtrim(sb); + strbuf_ltrim(sb); } void strbuf_rtrim(struct strbuf *sb) { @@@ -99,13 -107,22 +100,29 @@@ void strbuf_ltrim(struct strbuf *sb sb->buf[sb->len] = '\0'; } + int strbuf_reencode(struct strbuf *sb, const char *from, const char *to) + { + char *out; + int len; + + if (same_encoding(from, to)) + return 0; + + out = reencode_string_len(sb->buf, sb->len, to, from, &len); + if (!out) + return -1; + + strbuf_attach(sb, out, len, len); + return 0; + } + +void strbuf_tolower(struct strbuf *sb) +{ + char *p = sb->buf, *end = sb->buf + sb->len; + for (; p < end; p++) + *p = tolower(*p); +} + struct strbuf **strbuf_split_buf(const char *str, size_t slen, int terminator, int max) { @@@ -570,16 -587,3 +587,16 @@@ int fprintf_ln(FILE *fp, const char *fm return -1; return ret + 1; } + +char *xstrdup_tolower(const char *string) +{ + char *result; + size_t len, i; + + len = strlen(string); + result = xmalloc(len + 1); + for (i = 0; i < len; i++) + result[i] = tolower(string[i]); + result[i] = '\0'; + return result; +} diff --combined strbuf.h index 25328b9e81,4e9a2f8868..e9ad03eabe --- a/strbuf.h +++ b/strbuf.h @@@ -45,7 -45,7 +45,8 @@@ static inline void strbuf_setlen(struc extern void strbuf_trim(struct strbuf *); extern void strbuf_rtrim(struct strbuf *); extern void strbuf_ltrim(struct strbuf *); + extern int strbuf_reencode(struct strbuf *sb, const char *from, const char *to); +extern void strbuf_tolower(struct strbuf *sb); extern int strbuf_cmp(const struct strbuf *, const struct strbuf *); /* @@@ -184,6 -184,4 +185,6 @@@ extern int printf_ln(const char *fmt, . __attribute__((format (printf,2,3))) extern int fprintf_ln(FILE *fp, const char *fmt, ...); +char *xstrdup_tolower(const char *); + #endif /* STRBUF_H */ diff --combined t/lib-httpd.sh index 8b67021a6b,f7640bee9a..272fceef96 --- a/t/lib-httpd.sh +++ b/t/lib-httpd.sh @@@ -37,11 -37,6 +37,11 @@@ the test_done fi +if ! test_have_prereq SANITY; then + test_skip_or_die $GIT_TEST_HTTPD \ + "Cannot run httpd tests as root" +fi + HTTPD_PARA="" for DEFAULT_HTTPD_PATH in '/usr/sbin/httpd' '/usr/sbin/apache2' @@@ -110,10 -105,15 +110,15 @@@ els "Could not identify web server at '$LIB_HTTPD_PATH'" fi + install_script () { + write_script "$HTTPD_ROOT_PATH/$1" <"$TEST_PATH/$1" + } + prepare_httpd() { mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH" cp "$TEST_PATH"/passwd "$HTTPD_ROOT_PATH" - cp "$TEST_PATH"/broken-smart-http.sh "$HTTPD_ROOT_PATH" + install_script broken-smart-http.sh + install_script error.sh ln -s "$LIB_HTTPD_MODULE_PATH" "$HTTPD_ROOT_PATH/modules"