HTTP_LONG_CONSTANT("HTTP_URL_STRIP_PATH", HTTP_URL_STRIP_PATH);
HTTP_LONG_CONSTANT("HTTP_URL_STRIP_QUERY", HTTP_URL_STRIP_QUERY);
HTTP_LONG_CONSTANT("HTTP_URL_STRIP_FRAGMENT", HTTP_URL_STRIP_FRAGMENT);
+ HTTP_LONG_CONSTANT("HTTP_URL_STRIP_ALL", HTTP_URL_STRIP_ALL);
return SUCCESS;
}
}
if (!url->scheme) {
+ zval *https = http_get_server_var("HTTPS");
+ if (https && !strcasecmp(Z_STRVAL_P(https), "ON")) {
+ url->scheme = estrndup("https", lenof("https"));
+ } else
switch (url->port)
{
case 443:
}
if (!url->path) {
- if (SG(request_info).request_uri && *SG(request_info).request_uri) {
+ if (SG(request_info).request_uri && SG(request_info).request_uri[0]) {
const char *q = strchr(SG(request_info).request_uri, '?');
if (q) {
} else {
url->path = estrndup("/", 1);
}
- } else if (*url->path != '/') {
- if (SG(request_info).request_uri && *SG(request_info).request_uri) {
- const char *q = strchr(SG(request_info).request_uri, '?');
- char *uri, *path;
- size_t len;
-
- if (q) {
- uri = estrndup(SG(request_info).request_uri, len = q - SG(request_info).request_uri);
- } else {
- uri = estrndup(SG(request_info).request_uri, len = strlen(SG(request_info).request_uri));
- }
-
- php_dirname(uri, len);
- spprintf(&path, 0, "%s/%s", uri, url->path);
- efree(uri);
- STR_SET(url->path, path);
- } else {
- char *uri;
-
- spprintf(&uri, 0, "/%s", url->path);
- STR_SET(url->path, uri);
+ } 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);
}
+
+ 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);
}
- if (url->path) {
+ /* replace directory references if path is not a single slash */
+ if (url->path[0] && (url->path[0] != '/' || url->path[1])) {
char *ptr, *end = url->path + strlen(url->path) + 1;
for (ptr = strstr(url->path, "/."); ptr; ptr = strstr(ptr, "/.")) {
#define HTTP_URL_STRIP_PATH 0x040
#define HTTP_URL_STRIP_QUERY 0x080
#define HTTP_URL_STRIP_FRAGMENT 0x100
+#define HTTP_URL_STRIP_ALL ( \
+ HTTP_URL_STRIP_AUTH | \
+ HTTP_URL_STRIP_PORT | \
+ HTTP_URL_STRIP_PATH | \
+ HTTP_URL_STRIP_QUERY | \
+ HTTP_URL_STRIP_FRAGMENT \
+)
#define http_build_url(f, o, n, p, s, l) _http_build_url((f), (o), (n), (p), (s), (l) TSRMLS_CC)
PHP_HTTP_API void _http_build_url(int flags, const php_url *old_url, const php_url *new_url, php_url **url_ptr, char **url_str, size_t *url_len TSRMLS_DC);