X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fhttp.c;h=746f3e197c6aff9015140d8bc21c34c82150a994;hb=1b750a9f8ea0d258fde61f5bac2d5af5bd783eb0;hp=e4eecb9e2d81cda8c7b6a3588906791a72b66c46;hpb=afb059d3e508ad4fd38f4a9fd643a4bedf3e0b3f;p=yaz-moved-to-github.git diff --git a/src/http.c b/src/http.c index e4eecb9..746f3e1 100644 --- a/src/http.c +++ b/src/http.c @@ -219,6 +219,21 @@ void z_HTTP_header_set(ODR o, Z_HTTP_Header **hp, const char *n, (*hp)->next = 0; } +const char *z_HTTP_header_remove(Z_HTTP_Header **hp, const char *n) +{ + while (*hp) + { + if (!yaz_strcasecmp((*hp)->name, n)) + { + const char *v = (*hp)->value; + *hp = (*hp)->next; + return v; + } + hp = &(*hp)->next; + } + return 0; +} + const char *z_HTTP_header_lookup(const Z_HTTP_Header *hp, const char *n) { for (; hp; hp = hp->next) @@ -323,7 +338,7 @@ Z_GDU *z_get_HTTP_Request_uri(ODR odr, const char *uri, const char *args, return p; } -Z_GDU *z_get_HTTP_Response(ODR o, int code) +Z_GDU *z_get_HTTP_Response_details(ODR o, int code, const char *details) { Z_GDU *p = (Z_GDU *) odr_malloc(o, sizeof(*p)); Z_HTTP_Response *hres; @@ -340,7 +355,10 @@ Z_GDU *z_get_HTTP_Response(ODR o, int code) "YAZ/" YAZ_VERSION); if (code != 200) { - hres->content_buf = (char*) odr_malloc(o, 400); + const char *http_err = z_HTTP_errmsg(code); + size_t sz = 400 + strlen(http_err) + (details ? + strlen(details) : 0); + hres->content_buf = (char*) odr_malloc(o, sz); sprintf(hres->content_buf, "\n" @@ -352,16 +370,26 @@ Z_GDU *z_get_HTTP_Response(ODR o, int code) "

YAZ " YAZ_VERSION "

\n" "

Error: %d

\n" - "

Description: %.50s

\n" + "

Description: %s

\n", code, http_err); + if (details) + { + sprintf(hres->content_buf + strlen(hres->content_buf), + "

Details: %s

\n", details); + } + sprintf(hres->content_buf + strlen(hres->content_buf), " \n" - "\n", - code, z_HTTP_errmsg(code)); + "\n"); hres->content_len = strlen(hres->content_buf); z_HTTP_header_add(o, &hres->headers, "Content-Type", "text/html"); } return p; } +Z_GDU *z_get_HTTP_Response(ODR o, int code) +{ + return z_get_HTTP_Response_details(o, code, 0); +} + const char *z_HTTP_errmsg(int code) { switch (code)