|
|
@@ -195,6 +195,17 @@ char* hv_strnchr(const char* s, char c, size_t n) {
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
+char* hv_strnrchr(const char* s, char c, size_t n) {
|
|
|
+ assert(s != NULL);
|
|
|
+ const char* p = s;
|
|
|
+ const char* last = NULL;
|
|
|
+ while (*p != '\0' && n-- > 0) {
|
|
|
+ if (*p == c) last = p;
|
|
|
+ ++p;
|
|
|
+ }
|
|
|
+ return (char*)last;
|
|
|
+}
|
|
|
+
|
|
|
char* hv_strrchr_dir(const char* filepath) {
|
|
|
char* p = (char*)filepath;
|
|
|
while (*p) ++p;
|
|
|
@@ -474,7 +485,7 @@ int hv_parse_url(hurl_t* stURL, const char* strURL) {
|
|
|
host = pos + 1;
|
|
|
}
|
|
|
// port
|
|
|
- const char* port = hv_strnchr(host, ':', ep - host);
|
|
|
+ const char* port = hv_strnrchr(host, ':', ep - host);
|
|
|
if (port) {
|
|
|
stURL->fields[HV_URL_PORT].off = port + 1 - begin;
|
|
|
stURL->fields[HV_URL_PORT].len = ep - port - 1;
|
|
|
@@ -493,8 +504,14 @@ int hv_parse_url(hurl_t* stURL, const char* strURL) {
|
|
|
}
|
|
|
}
|
|
|
// host
|
|
|
+ unsigned short hostlen = port - host;
|
|
|
+ if (hostlen > 2 && host[0] == '[' && host[hostlen-1] == ']') {
|
|
|
+ // ipv6
|
|
|
+ host++;
|
|
|
+ hostlen -= 2;
|
|
|
+ }
|
|
|
stURL->fields[HV_URL_HOST].off = host - begin;
|
|
|
- stURL->fields[HV_URL_HOST].len = port - host;
|
|
|
+ stURL->fields[HV_URL_HOST].len = hostlen;
|
|
|
if (ep == end) return 0;
|
|
|
// /path
|
|
|
sp = ep;
|