master
1#ifndef HEADER_CURL_HTTP_CHUNKS_H
2#define HEADER_CURL_HTTP_CHUNKS_H
3/***************************************************************************
4 * _ _ ____ _
5 * Project ___| | | | _ \| |
6 * / __| | | | |_) | |
7 * | (__| |_| | _ <| |___
8 * \___|\___/|_| \_\_____|
9 *
10 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
11 *
12 * This software is licensed as described in the file COPYING, which
13 * you should have received as part of this distribution. The terms
14 * are also available at https://curl.se/docs/copyright.html.
15 *
16 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17 * copies of the Software, and permit persons to whom the Software is
18 * furnished to do so, under the terms of the COPYING file.
19 *
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
22 *
23 * SPDX-License-Identifier: curl
24 *
25 ***************************************************************************/
26#include "curl_setup.h"
28#ifndef CURL_DISABLE_HTTP
30#include "curlx/dynbuf.h"
32struct connectdata;
34/*
35 * The longest possible hexadecimal number we support in a chunked transfer.
36 * Neither RFC2616 nor the later HTTP specs define a maximum chunk size. With
37 * the 64-bit curl_off_t we support 16 digits, excluding leading zeroes. But
38 * why would a sane server prefix with zeroes? Let's accept one.
39 */
40#define CHUNK_MAXNUM_LEN 17
42typedef enum {
43 /* await and buffer all hexadecimal digits until we get one that is not a
44 hexadecimal digit. When done, we go CHUNK_LF */
45 CHUNK_HEX,
47 /* wait for LF, ignore all else */
48 CHUNK_LF,
50 /* We eat the amount of data specified. When done, we move on to the
51 POST_CR state. */
52 CHUNK_DATA,
54 /* POSTLF should get a CR and then an LF and nothing else, then move back to
55 HEX as the CRLF combination marks the end of a chunk. A missing CR is no
56 big deal. */
57 CHUNK_POSTLF,
59 /* Used to mark that we are out of the game. NOTE: that there is a
60 'datasize' field in the struct that will tell how many bytes that were
61 not passed to the client in the end of the last buffer! */
62 CHUNK_STOP,
64 /* At this point optional trailer headers can be found, unless the next line
65 is CRLF */
66 CHUNK_TRAILER,
68 /* A trailer CR has been found - next state is CHUNK_TRAILER_POSTCR.
69 Next char must be an LF */
70 CHUNK_TRAILER_CR,
72 /* A trailer LF must be found now, otherwise CHUNKE_BAD_CHUNK will be
73 signalled If this is an empty trailer CHUNKE_STOP will be signalled.
74 Otherwise the trailer will be broadcasted via Curl_client_write() and the
75 next state will be CHUNK_TRAILER */
76 CHUNK_TRAILER_POSTCR,
78 /* Successfully de-chunked everything */
79 CHUNK_DONE,
81 /* Failed on seeing a bad or not correctly terminated chunk */
82 CHUNK_FAILED
83} ChunkyState;
85typedef enum {
86 CHUNKE_OK = 0,
87 CHUNKE_TOO_LONG_HEX = 1,
88 CHUNKE_ILLEGAL_HEX,
89 CHUNKE_BAD_CHUNK,
90 CHUNKE_BAD_ENCODING,
91 CHUNKE_OUT_OF_MEMORY,
92 CHUNKE_PASSTHRU_ERROR, /* Curl_httpchunk_read() returns a CURLcode to use */
93 CHUNKE_TRAILER_LIMIT /* Max header limit exceeded by trailers */
94} CHUNKcode;
96struct Curl_chunker {
97 curl_off_t datasize;
98 ChunkyState state;
99 CHUNKcode last_code;
100 struct dynbuf trailer; /* for chunked-encoded trailer */
101 unsigned char hexindex;
102 char hexbuffer[CHUNK_MAXNUM_LEN + 1]; /* +1 for null-terminator */
103 BIT(ignore_body); /* never write response body data */
104 BIT(in_connect); /* this is a CONNECT response body */
105};
107/* The following functions are defined in http_chunks.c */
108void Curl_httpchunk_init(struct Curl_easy *data, struct Curl_chunker *ch,
109 bool ignore_body, bool in_connect);
110void Curl_httpchunk_free(struct Curl_easy *data, struct Curl_chunker *ch);
111void Curl_httpchunk_reset(struct Curl_easy *data, struct Curl_chunker *ch,
112 bool ignore_body);
114/*
115 * Read BODY bytes in HTTP/1.1 chunked encoding from `buf` and return
116 * the amount of bytes consumed. The actual response bytes and trailer
117 * headers are written out to the client.
118 * On success, this will consume all bytes up to the end of the response,
119 * e.g. the last chunk, has been processed.
120 * @param data the transfer involved
121 * @param ch the chunker instance keeping state across calls
122 * @param buf the response data
123 * @param blen amount of bytes in `buf`
124 * @param pconsumed on successful return, the number of bytes in `buf`
125 * consumed
126 *
127 * This function always uses ASCII hex values to accommodate non-ASCII hosts.
128 * For example, 0x0d and 0x0a are used instead of '\r' and '\n'.
129 */
130CURLcode Curl_httpchunk_read(struct Curl_easy *data, struct Curl_chunker *ch,
131 char *buf, size_t blen, size_t *pconsumed);
133/**
134 * @return TRUE iff chunked decoded has finished successfully.
135 */
136bool Curl_httpchunk_is_done(struct Curl_easy *data, struct Curl_chunker *ch);
138extern const struct Curl_cwtype Curl_httpchunk_unencoder;
140extern const struct Curl_crtype Curl_httpchunk_encoder;
142/**
143 * Add a transfer-encoding "chunked" reader to the transfers reader stack
144 */
145CURLcode Curl_httpchunk_add_reader(struct Curl_easy *data);
147#endif /* !CURL_DISABLE_HTTP */
149#endif /* HEADER_CURL_HTTP_CHUNKS_H */
Diagnostics4 git calls · 55 ms
CallStatusSizeTime055 ms
discover200152 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 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 · hit4 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=48 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=4 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=86Open pack map
fetch2002.3 KiB · hit48 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=2361 git.response.cache=HIT git.response.duration_ms=48 git.fetch.wants=00a27cc807e990179d1520e07585b90e716f6a3e 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=2361 git.pkt.payload.max=2340 git.sideband.band1.bytes=2339 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
- a5e27f0a4a910555
- Request
- 0a0ff37e…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format