X-Git-Url: http://www.dolda2000.com/gitweb/?a=blobdiff_plain;f=lib%2Fresp.c;h=2c0fa835daaf8a969f88cd36d509952a47d9f842;hb=51a4b1ad5f25ea29b94384e21c48152cce252b8b;hp=1b08b00c55cf1a8eb94382d25c9514e84162cb69;hpb=3095582d21be4087f774f5a68a2a9abfa37dd1ff;p=ashd.git diff --git a/lib/resp.c b/lib/resp.c index 1b08b00..2c0fa83 100644 --- a/lib/resp.c +++ b/lib/resp.c @@ -116,12 +116,13 @@ void simpleerror(int fd, int code, char *msg, char *fmt, ...) fwrite(buf.b, 1, buf.d, out); fclose(out); buffree(buf); + free(tmp); } void stdredir(struct hthead *req, int fd, int code, char *dst) { FILE *out; - char *sp, *cp, *ep, *path, *url, *adst, *proto, *host; + char *sp, *cp, *ep, *qs, *path, *url, *adst, *proto, *host; sp = strchr(dst, '/'); cp = strchr(dst, ':'); @@ -140,11 +141,14 @@ void stdredir(struct hthead *req, int fd, int code, char *dst) } else { if((*(url = req->url)) == '/') url++; - if((ep = strrchr(url, '/')) != NULL) - ep++; - else - ep = url; - path = sprintf2("%.*s%s", ep - url, url, dst); + if((ep = strchr(url, '?')) == NULL) { + ep = url + strlen(url); + qs = ""; + } else { + qs = ep; + } + for(; (ep > url) && (ep[-1] != '/'); ep--); + path = sprintf2("%.*s%s%s", ep - url, url, dst, qs); } adst = sprintf2("%s://%s/%s", proto, host, path); free(path);