From: Adam Dickmeiss Date: Tue, 21 Jan 2014 11:55:26 +0000 (+0100) Subject: SRU GET/Solr base URLs may hold additional ?args YAZ-729 X-Git-Tag: v5.0.12~3 X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=commitdiff_plain;h=09c113499ad3e65ca1679889c2a0165a52f1cb50 SRU GET/Solr base URLs may hold additional ?args YAZ-729 ZOOM option extraArgs already does this, though. It seems useful when dealing with Solr targets to limit by filter, eg. http://lui.indexdata.com:8080/solr4/select?fq=database:3902 --- diff --git a/src/solr.c b/src/solr.c index 4c77e6f..e9d3dcf 100644 --- a/src/solr.c +++ b/src/solr.c @@ -482,6 +482,7 @@ int yaz_solr_encode_request(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu, char *q; char *pos; char *cp; + const char *path_args = 0; int i = 0; z_HTTP_header_add_basic_auth(encode, &hreq->headers, @@ -580,8 +581,14 @@ int yaz_solr_encode_request(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu, path = (char *) odr_malloc(encode, strlen(hreq->path) + - strlen(uri_args) + strlen(solr_op) + 4); + strlen(uri_args) + strlen(solr_op) + 5); + cp = strchr(hreq->path, '?'); + if (cp) + { + *cp = '\0'; /* args in path */ + path_args = cp + 1; + } strcpy(path, hreq->path); cp = strrchr(path, '/'); if (cp) @@ -592,6 +599,11 @@ int yaz_solr_encode_request(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu, strcat(path, "/"); strcat(path, solr_op); strcat(path, "?"); + if (path_args) + { + strcat(path, path_args); + strcat(path, "&"); + } strcat(path, uri_args); hreq->path = path; diff --git a/src/srwutil.c b/src/srwutil.c index 7be212a..017ec5e 100644 --- a/src/srwutil.c +++ b/src/srwutil.c @@ -1064,7 +1064,8 @@ int yaz_sru_get_encode(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu, path = (char *) odr_malloc(encode, strlen(hreq->path) + strlen(uri_args) + 4); - sprintf(path, "%s?%s", hreq->path, uri_args); + sprintf(path, "%s%c%s", hreq->path, strchr(hreq->path, '?') ? '&' : '?', + uri_args); hreq->path = path; z_HTTP_header_add_content_type(encode, &hreq->headers,