Sortix nightly manual
This manual documents Sortix nightly, a development build that has not been officially released. You can instead view this document in the latest official manual.
curl_url_set(3) | Library Functions Manual | curl_url_set(3) |
NAME
curl_url_set - set a URL partSYNOPSIS
#include <curl/curl.h>
CURLUcode curl_url_set(CURLU *url,
CURLUPart part,
const char *content,
unsigned int flags);
DESCRIPTION
The url handle to work on, passed in as the first argument, must be a handle previously created by curl_url(3) or curl_url_dup(3).PARTS
- CURLUPART_URL
-
Allows the full URL of the handle to be replaced. If the handle already is populated with a URL, the new URL can be relative to the previous.
- CURLUPART_SCHEME
- Scheme cannot be URL decoded on set. libcurl only accepts setting schemes up to 40 bytes long.
- CURLUPART_USER
- If only the user part is set and not the password, the URL is represented with a blank password.
- CURLUPART_PASSWORD
- If only the password part is set and not the user, the URL is represented with a blank user.
- CURLUPART_OPTIONS
- The options field is an optional field that might follow the password in the userinfo part. It is only recognized/used when parsing URLs for the following schemes: pop3, smtp and imap. This function however allows users to independently set this field.
- CURLUPART_HOST
-
The hostname. If it is International Domain Name (IDN) the string must then be encoded as your locale says or UTF-8 (when WinIDN is used). If it is a bracketed IPv6 numeric address it may contain a zone id (or you can use CURLUPART_ZONEID).
- CURLUPART_ZONEID
- If the hostname is a numeric IPv6 address, this field can also be set.
- CURLUPART_PORT
- The port number cannot be URL encoded on set. The given port number is provided as a string and the decimal number in it must be between 0 and 65535. Anything else returns an error.
- CURLUPART_PATH
- If a path is set in the URL without a leading slash, a slash is prepended automatically.
- CURLUPART_QUERY
-
The query part gets spaces converted to pluses when asked to URL encode on set with the CURLU_URLENCODE bit.
- CURLUPART_FRAGMENT
- The hash sign in the URL is not part of the actual fragment contents.
FLAGS
The flags argument is zero, one or more bits set in a bitmask.- CURLU_APPENDQUERY
-
Can be used when setting the CURLUPART_QUERY component. The provided new part is then appended at the end of the existing query - and if the previous part did not end with an ampersand (&), an ampersand gets inserted before the new appended part.
- CURLU_NON_SUPPORT_SCHEME
- If set, allows curl_url_set(3) to set a non-supported scheme. It then of course cannot know if the provided scheme is a valid one or not.
- CURLU_URLENCODE
-
When set, curl_url_set(3) URL encodes the part on entry, except for scheme, port and URL.
- CURLU_DEFAULT_SCHEME
- If set, allows the URL to be set without a scheme and then sets that to the default scheme: HTTPS. Overrides the CURLU_GUESS_SCHEME option if both are set.
- CURLU_GUESS_SCHEME
-
If set, allows the URL to be set without a scheme and it instead "guesses" which scheme that was intended based on the hostname. If the outermost subdomain name matches DICT, FTP, IMAP, LDAP, POP3 or SMTP then that scheme is used, otherwise it picks HTTP. Conflicts with the CURLU_DEFAULT_SCHEME option which takes precedence if both are set.
- CURLU_NO_AUTHORITY
- If set, skips authority checks. The RFC allows individual schemes to omit the host part (normally the only mandatory part of the authority), but libcurl cannot know whether this is permitted for custom schemes. Specifying the flag permits empty authority sections, similar to how file scheme is handled.
- CURLU_PATH_AS_IS
- When set for CURLUPART_URL, this skips the normalization of the path. That is the procedure where libcurl otherwise removes sequences of dot-slash and dot-dot etc. The same option used for transfers is called CURLOPT_PATH_AS_IS(3).
- CURLU_ALLOW_SPACE
- If set, the URL parser allows space (ASCII 32) where possible. The URL syntax does normally not allow spaces anywhere, but they should be encoded as %20 or '+'. When spaces are allowed, they are still not allowed in the scheme. When space is used and allowed in a URL, it is stored as-is unless CURLU_URLENCODE is also set, which then makes libcurl URL encode the space before stored. This affects how the URL is constructed when curl_url_get(3) is subsequently used to extract the full URL or individual parts. (Added in 7.78.0)
- CURLU_DISALLOW_USER
- If set, the URL parser does not accept embedded credentials for the CURLUPART_URL, and instead returns CURLUE_USER_NOT_ALLOWED for such URLs.
PROTOCOLS
This functionality affects all supported protocolsEXAMPLE
int main(void)
{
CURLUcode rc;
CURLU *url = curl_url();
rc = curl_url_set(url, CURLUPART_URL, "https://example.com", 0);
if(!rc) {
/* change it to an FTP URL */
rc = curl_url_set(url, CURLUPART_SCHEME, "ftp", 0);
}
curl_url_cleanup(url);
}
AVAILABILITY
Added in curl 7.78.0RETURN VALUE
Returns a CURLUcode error value, which is CURLUE_OK (0) if everything went fine. See the libcurl-errors(3) man page for the full list with descriptions.SEE ALSO
CURLOPT_CURLU(3), curl_url(3), curl_url_cleanup(3), curl_url_dup(3), curl_url_get(3), curl_url_strerror(3)2024-12-21 | libcurl |