Merge branch 'jk/http-errors'
authorJunio C Hamano <gitster@pobox.com>
Mon, 16 Jun 2014 19:18:35 +0000 (12:18 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 16 Jun 2014 19:18:36 +0000 (12:18 -0700)
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

1  2 
Documentation/technical/api-strbuf.txt
strbuf.c
strbuf.h
t/lib-httpd.sh
index 50690186d3949de7168e579b0f7a54d6cb0dd8e5,9d28b034ad9a35108f8069557e194992f8e36b0f..077a7096a4ba3c47a0cbc8981abdde1b7b35d924
@@@ -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 c8217755e541f05281d10e07517602f0fdcbde42,fc7290f57a07353ab7bbf86b7c743ec913ee396c..ac62982e672c22457468f601b35716dc9a52a81c
+++ 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 25328b9e8193e9f56431450b6125d6ce7d667d91,4e9a2f88686e211b8610d72e18c02251c2dc8a92..e9ad03eabe72dc2ee6e7e0086baca71d343264ce
+++ 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 8b67021a6bb95c8a2e6ed2530267e338f2351082,f7640bee9a4564f3099b0751811e7cd6a41ecc09..272fceef96c06e6e104d6341f36b1764e7d0c8db
@@@ -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"