Artifactspublic-v0

curl

master
ply4 git calls25 ms288 KiB3 cachedprotocol v2
92 lines2.4 KiBRaw

NAME

curl_easy_escape - URL encode a string

SYNOPSIS

c
#include <curl/curl.h>

char *curl_easy_escape(CURL *curl, const char *string, int length);

DESCRIPTION

This function converts the given input string to a URL encoded string and returns that as a new allocated string. All input characters that are not a-z, A-Z, 0-9, '-', '.', '_' or '~' are converted to their "URL escaped" version (%NN where NN is a two-digit hexadecimal number). Although not constrained by its type, the returned string may not be altered.

If length is set to 0 (zero), curl_easy_escape(3) uses strlen() on the input string to find out the size.

You must curl_free(3) the returned string when you are done with it.

ENCODING

libcurl is typically not aware of, nor does it care about, character encodings. curl_easy_escape(3) encodes the data byte-by-byte into the URL encoded version without knowledge or care for what particular character encoding the application or the receiving server may assume that the data uses.

The caller of curl_easy_escape(3) must make sure that the data passed in to the function is encoded correctly.

URLs

URLs are by definition URL encoded. To create a proper URL from a set of components that may not be URL encoded already, you cannot URL encode the entire URL string with curl_easy_escape(3), because it then also converts colons, slashes and other symbols that you probably want untouched.

To create a proper URL from strings that are not already URL encoded, we recommend using libcurl's URL API: set the pieces with curl_url_set(3) and get the final correct URL with curl_url_get(3).

%PROTOCOLS%

EXAMPLE

c
int main(void)
{
  CURL *curl = curl_easy_init();
  if(curl) {
    char *output = curl_easy_escape(curl, "data to convert", 15);
    if(output) {
      printf("Encoded: %s\n", output);
      curl_free(output);
    }
    curl_easy_cleanup(curl);
  }
}

HISTORY

Since 7.82.0, the curl parameter is ignored. Prior to that there was per-handle character conversion support for some old operating systems such as TPF, but it was otherwise ignored.

%AVAILABILITY%

RETURN VALUE

A pointer to a null-terminated string or NULL if it failed.

1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: curl_easy_escape
5Section: 3
6Source: libcurl
7See-also:
8 - curl_easy_unescape (3)
9 - curl_url_set (3)
10 - curl_url_get (3)
11Protocol:
12 - All
13Added-in: 7.15.4
14---
16# NAME
18curl_easy_escape - URL encode a string
20# SYNOPSIS
22~~~c
23#include <curl/curl.h>
25char *curl_easy_escape(CURL *curl, const char *string, int length);
26~~~
28# DESCRIPTION
30This function converts the given input *string* to a URL encoded string and
31returns that as a new allocated string. All input characters that are not a-z,
32A-Z, 0-9, '-', '.', '_' or '~' are converted to their "URL escaped" version
33(**%NN** where **NN** is a two-digit hexadecimal number). Although not
34constrained by its type, the returned string may not be altered.
36If *length* is set to 0 (zero), curl_easy_escape(3) uses strlen() on the input
37*string* to find out the size.
39You must curl_free(3) the returned string when you are done with it.
41# ENCODING
43libcurl is typically not aware of, nor does it care about, character
44encodings. curl_easy_escape(3) encodes the data byte-by-byte into the
45URL encoded version without knowledge or care for what particular character
46encoding the application or the receiving server may assume that the data
47uses.
49The caller of curl_easy_escape(3) must make sure that the data passed in
50to the function is encoded correctly.
52# URLs
54URLs are by definition *URL encoded*. To create a proper URL from a set of
55components that may not be URL encoded already, you cannot URL encode the
56entire URL string with curl_easy_escape(3), because it then also converts
57colons, slashes and other symbols that you probably want untouched.
59To create a proper URL from strings that are not already URL encoded, we
60recommend using libcurl's URL API: set the pieces with curl_url_set(3) and get
61the final correct URL with curl_url_get(3).
63# %PROTOCOLS%
65# EXAMPLE
67~~~c
68int main(void)
70 CURL *curl = curl_easy_init();
71 if(curl) {
72 char *output = curl_easy_escape(curl, "data to convert", 15);
73 if(output) {
74 printf("Encoded: %s\n", output);
75 curl_free(output);
76 }
77 curl_easy_cleanup(curl);
78 }
80~~~
82# HISTORY
84Since 7.82.0, the **curl** parameter is ignored. Prior to that there was
85per-handle character conversion support for some old operating systems such as
86TPF, but it was otherwise ignored.
88# %AVAILABILITY%
90# RETURN VALUE
92A pointer to a null-terminated string or NULL if it failed.
Diagnostics4 git calls · 25 ms
CallStatusSizeTime025 ms
discover200152 B4 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 · hit3 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=149
git.response.cache=HIT
git.response.duration_ms=3
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 · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=19
git.response.bytes=293470
git.response.cache=HIT
git.response.duration_ms=2
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
fetch2001.3 KiB · hit19 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=1357
git.response.cache=HIT
git.response.duration_ms=19
git.fetch.wants=6ff7c5ac539cd8438d464b92d0b058c06503dae6
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=1357
git.pkt.payload.max=1336
git.sideband.band1.bytes=1335
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
a5e3553d4e85994c
Request
1c5d377d…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format