MCPcopy Create free account
hub / github.com/acl-dev/acl / save_range

Method save_range

lib_acl_cpp/src/http/http_download.cpp:159–211  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

157}
158
159bool http_download::save_range(const char* body, size_t len,
160 acl_int64 range_from, acl_int64 range_to)
161{
162 if (range_from < 0) {
163 logger_error("invalid range_from: %lld", range_from);
164 return false;
165 } else if (range_to >= 0 && range_to < range_from) {
166 logger_error("invalid, 0 <= range_to: %lld < range_from: %lld",
167 range_to, range_from);
168 return false;
169 }
170
171 http_method_t method = body && len > 0
172 ? HTTP_METHOD_POST : HTTP_METHOD_GET;
173
174 // ���ʹ� range �ֶε���������
175
176 // ���� HTTP ����ͷ��Ϣ
177 req_->request_header().set_method(method)
178 .set_range(range_from, range_to);
179
180 // ���� HTTP ��������
181 if (!req_->request(NULL, 0)) {
182 logger_error("send request error, url: %s", url_);
183 return false;
184 }
185
186 // ��������
187 acl_int64 length = req_->get_range_max();
188 if (length <= 0) {
189 // �����Ƿ�������֧�� range ���ܣ����Ի��ô�ͷ����
190 return false;
191 }
192
193 http_client* conn = req_->get_client();
194 if (conn == NULL) {
195 logger_fatal("no connect to server");
196 }
197
198 // �ص�������ӿ�ʵ��
199 if (!on_response(conn)) {
200 logger_error("deny url(%s)'s download", url_);
201 return false;
202 }
203
204 // �ص�������ӿ�ʵ��
205 if (!on_length(length)) {
206 logger_error("deny url(%s)'s download", url_);
207 return false;
208 }
209
210 return save(req_);
211}
212
213bool http_download::save(http_request* req)
214{

Callers

nothing calls this directly

Calls 5

set_rangeMethod · 0.80
request_headerMethod · 0.80
get_range_maxMethod · 0.80
requestMethod · 0.45
get_clientMethod · 0.45

Tested by

no test coverage detected