Artifactspublic-v0

curl

master
ply4 git calls135 ms290 KiB2 cachedprotocol v2
249 lines7.2 KiBRaw

NAME

curl_url_get - extract a part from a URL

SYNOPSIS

c
#include <curl/curl.h>

CURLUcode curl_url_get(const CURLU *url,
                       CURLUPart part,
                       char **content,
                       unsigned int flags);

DESCRIPTION

Given a url handle of a URL object, this function extracts an individual piece or the full URL from it.

The part argument specifies which part to extract (see list below) and content points to a 'char *' to get updated to point to a newly allocated string with the contents.

The flags argument is a bitmask with individual features.

The returned content pointer must be freed with curl_free(3) after use. Although not constrained by its type, the pointed string may not be altered.

FLAGS

The flags argument is zero, one or more bits set in a bitmask.

CURLU_DEFAULT_PORT

If the handle has no port stored, this option makes curl_url_get(3) return the default port for the used scheme.

CURLU_DEFAULT_SCHEME

If the handle has no scheme stored, this option makes curl_url_get(3) return the default scheme instead of error.

CURLU_NO_DEFAULT_PORT

Instructs curl_url_get(3) to not return a port number if it matches the default port for the scheme.

CURLU_URLDECODE

Asks curl_url_get(3) to URL decode the contents before returning it. It does not decode the scheme, the port number or the full URL.

The query component also gets plus-to-space conversion as a bonus when this bit is set.

Note that this URL decoding is charset unaware and you get a null-terminated string back with data that could be intended for a particular encoding.

If there are byte values lower than 32 in the decoded string, the get operation returns an error instead.

CURLU_URLENCODE

If set, curl_url_get(3) URL encodes the hostname part when a full URL is retrieved. If not set (default), libcurl returns the URL with the hostname raw to support IDN names to appear as-is. IDN hostnames are typically using non-ASCII bytes that otherwise gets percent-encoded.

Note that even when not asking for URL encoding, the '%' (byte 37) is URL encoded to make sure the hostname remains valid.

CURLU_PUNYCODE

If set and CURLU_URLENCODE is not set, and asked to retrieve the CURLUPART_HOST or CURLUPART_URL parts, libcurl returns the host name in its punycode version if it contains any non-ASCII octets (and is an IDN name).

If libcurl is built without IDN capabilities, using this bit makes curl_url_get(3) return CURLUE_LACKS_IDN if the hostname contains anything outside the ASCII range.

(Added in curl 7.88.0)

CURLU_PUNY2IDN

If set and asked to retrieve the CURLUPART_HOST or CURLUPART_URL parts, libcurl returns the hostname in its IDN (International Domain Name) UTF-8 version if it otherwise is a punycode version. If the punycode name cannot be converted to IDN correctly, libcurl returns CURLUE_BAD_HOSTNAME.

If libcurl is built without IDN capabilities, using this bit makes curl_url_get(3) return CURLUE_LACKS_IDN if the hostname is using punycode.

(Added in curl 8.3.0)

CURLU_GET_EMPTY

When this flag is used in curl_url_get(), it makes the function return empty query and fragments parts or when used in the full URL. By default, libcurl otherwise considers empty parts non-existing.

An empty query part is one where this is nothing following the question mark (before the possible fragment). An empty fragments part is one where there is nothing following the hash sign.

(Added in curl 8.8.0)

CURLU_NO_GUESS_SCHEME

When this flag is used in curl_url_get(), it treats the scheme as non-existing if it was set as a result of a previous guess; when CURLU_GUESS_SCHEME was used parsing a URL.

Using this flag when getting CURLUPART_SCHEME if the scheme was set as the result of a guess makes curl_url_get() return CURLUE_NO_SCHEME.

Using this flag when getting CURLUPART_URL if the scheme was set as the result of a guess makes curl_url_get() return the full URL without the scheme component. Such a URL can then only be parsed with curl_url_set() if CURLU_GUESS_SCHEME is used.

(Added in curl 8.9.0)

PARTS

CURLUPART_URL

When asked to return the full URL, curl_url_get(3) returns a slightly cleaned up version of the complete URL using all available parts.

We advise using the CURLU_PUNYCODE option to get the URL as "normalized" as possible since IDN allows hostnames to be written in many different ways that still end up the same punycode version.

Zero-length queries and fragments are excluded from the URL unless CURLU_GET_EMPTY is set.

CURLUPART_SCHEME

Scheme cannot be URL decoded on get.

CURLUPART_USER

CURLUPART_PASSWORD

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. The URL API still allows users to set and get this field independently of scheme when not parsing full URLs.

CURLUPART_HOST

The hostname. If it is an IPv6 numeric address, the zone id is not part of it but is provided separately in CURLUPART_ZONEID. IPv6 numerical addresses are returned within brackets ([]).

IPv6 names are normalized when set, which should make them as short as possible while maintaining correct syntax.

CURLUPART_ZONEID

If the hostname is a numeric IPv6 address, this field might also be set.

CURLUPART_PORT

A port cannot be URL decoded on get. This number is returned in a string like all other parts. That string is guaranteed to hold a valid port number in ASCII using base 10.

CURLUPART_PATH

The part is always at least a slash ('/') even if no path was supplied in the URL. A URL path always starts with a slash.

CURLUPART_QUERY

The initial question mark that denotes the beginning of the query part is a delimiter only. It is not part of the query contents.

A not-present query returns part set to NULL.

A zero-length query returns part as NULL unless CURLU_GET_EMPTY is set.

The query part gets pluses converted to space when asked to URL decode on get with the CURLU_URLDECODE bit.

CURLUPART_FRAGMENT

The initial hash sign that denotes the beginning of the fragment is a delimiter only. It is not part of the fragment contents.

A not-present fragment returns part set to NULL.

A zero-length fragment returns part as NULL unless CURLU_GET_EMPTY is set.

%PROTOCOLS%

EXAMPLE

c
int main(void)
{
  CURLUcode rc;
  CURLU *url = curl_url();
  rc = curl_url_set(url, CURLUPART_URL, "https://example.com", 0);
  if(!rc) {
    char *scheme;
    rc = curl_url_get(url, CURLUPART_SCHEME, &scheme, 0);
    if(!rc) {
      printf("the scheme is %s\n", scheme);
      curl_free(scheme);
    }
    curl_url_cleanup(url);
  }
}

%AVAILABILITY%

RETURN 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.

If this function returns an error, no URL part is returned.

1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: curl_url_get
5Section: 3
6Source: libcurl
7See-also:
8 - CURLOPT_CURLU (3)
9 - curl_url (3)
10 - curl_url_cleanup (3)
11 - curl_url_dup (3)
12 - curl_url_set (3)
13 - curl_url_strerror (3)
14Protocol:
15 - All
16Added-in: 7.62.0
17---
19# NAME
21curl_url_get - extract a part from a URL
23# SYNOPSIS
25~~~c
26#include <curl/curl.h>
28CURLUcode curl_url_get(const CURLU *url,
29 CURLUPart part,
30 char **content,
31 unsigned int flags);
32~~~
34# DESCRIPTION
36Given a *url* handle of a URL object, this function extracts an individual
37piece or the full URL from it.
39The *part* argument specifies which part to extract (see list below) and
40*content* points to a 'char *' to get updated to point to a newly
41allocated string with the contents.
43The *flags* argument is a bitmask with individual features.
45The returned content pointer must be freed with curl_free(3) after use.
46Although not constrained by its type, the pointed string may not be altered.
48# FLAGS
50The flags argument is zero, one or more bits set in a bitmask.
52## CURLU_DEFAULT_PORT
54If the handle has no port stored, this option makes curl_url_get(3)
55return the default port for the used scheme.
57## CURLU_DEFAULT_SCHEME
59If the handle has no scheme stored, this option makes curl_url_get(3)
60return the default scheme instead of error.
62## CURLU_NO_DEFAULT_PORT
64Instructs curl_url_get(3) to not return a port number if it matches the
65default port for the scheme.
67## CURLU_URLDECODE
69Asks curl_url_get(3) to URL decode the contents before returning it. It
70does not decode the scheme, the port number or the full URL.
72The query component also gets plus-to-space conversion as a bonus when this
73bit is set.
75Note that this URL decoding is charset unaware and you get a null-terminated
76string back with data that could be intended for a particular encoding.
78If there are byte values lower than 32 in the decoded string, the get
79operation returns an error instead.
81## CURLU_URLENCODE
83If set, curl_url_get(3) URL encodes the hostname part when a full URL is
84retrieved. If not set (default), libcurl returns the URL with the hostname raw
85to support IDN names to appear as-is. IDN hostnames are typically using
86non-ASCII bytes that otherwise gets percent-encoded.
88Note that even when not asking for URL encoding, the '%' (byte 37) is URL
89encoded to make sure the hostname remains valid.
91## CURLU_PUNYCODE
93If set and *CURLU_URLENCODE* is not set, and asked to retrieve the
94**CURLUPART_HOST** or **CURLUPART_URL** parts, libcurl returns the host
95name in its punycode version if it contains any non-ASCII octets (and is an
96IDN name).
98If libcurl is built without IDN capabilities, using this bit makes
99curl_url_get(3) return *CURLUE_LACKS_IDN* if the hostname contains
100anything outside the ASCII range.
102(Added in curl 7.88.0)
104## CURLU_PUNY2IDN
106If set and asked to retrieve the **CURLUPART_HOST** or **CURLUPART_URL**
107parts, libcurl returns the hostname in its IDN (International Domain Name)
108UTF-8 version if it otherwise is a punycode version. If the punycode name
109cannot be converted to IDN correctly, libcurl returns
110*CURLUE_BAD_HOSTNAME*.
112If libcurl is built without IDN capabilities, using this bit makes
113curl_url_get(3) return *CURLUE_LACKS_IDN* if the hostname is using
114punycode.
116(Added in curl 8.3.0)
118## CURLU_GET_EMPTY
120When this flag is used in curl_url_get(), it makes the function return empty
121query and fragments parts or when used in the full URL. By default, libcurl
122otherwise considers empty parts non-existing.
124An empty query part is one where this is nothing following the question mark
125(before the possible fragment). An empty fragments part is one where there is
126nothing following the hash sign.
128(Added in curl 8.8.0)
130## CURLU_NO_GUESS_SCHEME
132When this flag is used in curl_url_get(), it treats the scheme as non-existing
133if it was set as a result of a previous guess; when CURLU_GUESS_SCHEME was
134used parsing a URL.
136Using this flag when getting CURLUPART_SCHEME if the scheme was set as the
137result of a guess makes curl_url_get() return CURLUE_NO_SCHEME.
139Using this flag when getting CURLUPART_URL if the scheme was set as the result
140of a guess makes curl_url_get() return the full URL without the scheme
141component. Such a URL can then only be parsed with curl_url_set() if
142CURLU_GUESS_SCHEME is used.
144(Added in curl 8.9.0)
146# PARTS
148## CURLUPART_URL
150When asked to return the full URL, curl_url_get(3) returns a slightly cleaned
151up version of the complete URL using all available parts.
153We advise using the *CURLU_PUNYCODE* option to get the URL as "normalized" as
154possible since IDN allows hostnames to be written in many different ways that
155still end up the same punycode version.
157Zero-length queries and fragments are excluded from the URL unless
158CURLU_GET_EMPTY is set.
160## CURLUPART_SCHEME
162Scheme cannot be URL decoded on get.
164## CURLUPART_USER
166## CURLUPART_PASSWORD
168## CURLUPART_OPTIONS
170The options field is an optional field that might follow the password in the
171userinfo part. It is only recognized/used when parsing URLs for the following
172schemes: pop3, smtp and imap. The URL API still allows users to set and get
173this field independently of scheme when not parsing full URLs.
175## CURLUPART_HOST
177The hostname. If it is an IPv6 numeric address, the zone id is not part of it
178but is provided separately in *CURLUPART_ZONEID*. IPv6 numerical addresses
179are returned within brackets ([]).
181IPv6 names are normalized when set, which should make them as short as
182possible while maintaining correct syntax.
184## CURLUPART_ZONEID
186If the hostname is a numeric IPv6 address, this field might also be set.
188## CURLUPART_PORT
190A port cannot be URL decoded on get. This number is returned in a string like
191all other parts. That string is guaranteed to hold a valid port number in
192ASCII using base 10.
194## CURLUPART_PATH
196The *part* is always at least a slash ('/') even if no path was supplied
197in the URL. A URL path always starts with a slash.
199## CURLUPART_QUERY
201The initial question mark that denotes the beginning of the query part is a
202delimiter only. It is not part of the query contents.
204A not-present query returns *part* set to NULL.
206A zero-length query returns *part* as NULL unless CURLU_GET_EMPTY is set.
208The query part gets pluses converted to space when asked to URL decode on get
209with the CURLU_URLDECODE bit.
211## CURLUPART_FRAGMENT
213The initial hash sign that denotes the beginning of the fragment is a
214delimiter only. It is not part of the fragment contents.
216A not-present fragment returns *part* set to NULL.
218A zero-length fragment returns *part* as NULL unless CURLU_GET_EMPTY is set.
220# %PROTOCOLS%
222# EXAMPLE
224~~~c
225int main(void)
227 CURLUcode rc;
228 CURLU *url = curl_url();
229 rc = curl_url_set(url, CURLUPART_URL, "https://example.com", 0);
230 if(!rc) {
231 char *scheme;
232 rc = curl_url_get(url, CURLUPART_SCHEME, &scheme, 0);
233 if(!rc) {
234 printf("the scheme is %s\n", scheme);
235 curl_free(scheme);
236 }
237 curl_url_cleanup(url);
238 }
240~~~
242# %AVAILABILITY%
244# RETURN VALUE
246Returns a CURLUcode error value, which is CURLUE_OK (0) if everything went
247fine. See the libcurl-errors(3) man page for the full list with descriptions.
249If this function returns an error, no URL part is returned.
Diagnostics4 git calls · 135 ms
CallStatusSizeTime0135 ms
discover200152 B2 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=152
git.server.agent=gitty/1.0
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch object-format
git.server.fetch=shallow filter sideband-all
git.protocol.version=2
git.pkt.frames=8
git.pkt.data=6
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=152
git.pkt.payload.max=34
ls-refs200149 B · hit2 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=149
git.response.cache=HIT
git.response.duration_ms=2
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=149
git.pkt.payload.max=78
git.ls_refs.count=2
git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=129
git.response.bytes=293470
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=blob:none
git.fetch.filter.requested=tree:0
git.fetch.filter.fallback=blob:none
git.fetch.filter.learned=false
git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=10
git.pkt.data=8
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=293470
git.pkt.payload.max=65516
git.sideband.band1.bytes=293354
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=87
git.pack.bytes=293354
git.pack.ofs_delta=0
git.pack.ref_delta=1
git.pack.chain.max=1
git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0
git.pack.full=86
Open pack map
fetch2003.0 KiB130 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=3097
git.response.cache=MISS
git.response.duration_ms=130
git.fetch.wants=9916166f97c58014fbcb016a4e9e91a9bc63183b
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=3097
git.pkt.payload.max=3076
git.sideband.band1.bytes=3075
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
Ref
refs/heads/master
Commit
31c911efe5652725e930f4d2e60c9060e5f6646d
cf-ray
a5e34729be8bf4d4
Request
1e14141a…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format