- } else if (url->path[0] != '/' && SG(request_info).request_uri && SG(request_info).request_uri[0]) {
- size_t ulen = strlen(SG(request_info).request_uri);
- size_t plen = strlen(url->path);
- char *path;
-
- if (SG(request_info).request_uri[ulen-1] != '/') {
- for (--ulen; ulen && SG(request_info).request_uri[ulen - 1] != '/'; --ulen);
+ } else if (url->path[0] != '/') {
+ if (SG(request_info).request_uri && SG(request_info).request_uri[0]) {
+ size_t ulen = strlen(SG(request_info).request_uri);
+ size_t plen = strlen(url->path);
+ char *path;
+
+ if (SG(request_info).request_uri[ulen-1] != '/') {
+ for (--ulen; ulen && SG(request_info).request_uri[ulen - 1] != '/'; --ulen);
+ }
+
+ path = emalloc(ulen + plen + 1);
+ memcpy(path, SG(request_info).request_uri, ulen);
+ memcpy(path + ulen, url->path, plen);
+ path[ulen + plen] = '\0';
+ STR_SET(url->path, path);
+ } else {
+ size_t plen = strlen(url->path);
+ char *path = emalloc(plen + 1 + 1);
+
+ path[0] = '/';
+ memcpy(&path[1], url->path, plen + 1);
+ STR_SET(url->path, path);