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

Method write_head

lib_acl_cpp/src/http/http_client.cpp:335–415  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

333}
334
335bool http_client::write_head(const http_header& header)
336{
337 if (head_sent_) {
338 return true;
339 }
340 head_sent_ = true;
341
342 // �ȱ����Ƿ�Ϊ�鴫���״̬
343 chunked_transfer_ = header.chunked_transfer();
344
345 // �����Ӧ����ʱ������ gzip ���䷽ʽ������Ҫ�ȳ�ʼ�� zlib ������
346 if (header.is_transfer_gzip()) {
347 delete zstream_;
348 zstream_ = NEW zlib_stream;
349 if (zstream_->zip_begin(zlib_default, -zlib_wbits_15,
350 zlib_mlevel_9)) {
351 // ��ʼ�� crc32 У���
352 gzip_crc32_ = zstream_->crc32_update(0, Z_NULL, 0);
353 } else {
354 logger_error("zip_begin error!");
355 delete zstream_;
356 zstream_ = NULL;
357
358 // �����ʼ�� zip ʧ�ܣ���ǿ��ת���ɷ� zip ģʽ
359 const_cast<http_header*>
360 (&header)->set_transfer_gzip(false);
361 }
362
363 // ��ʼ����ѹ�������ܳ���
364 gzip_total_in_ = 0;
365 }
366
367 // ���� HTTP ����/��Ӧͷ
368 string buf;
369 if (header.is_request()) {
370 header.build_request(buf);
371 } else {
372 header.build_response(buf);
373 }
374
375 ostream& out = get_ostream();
376
377 // ��д HTTP ͷ
378 if (out.write(buf.c_str(), buf.length(), true,
379 header.get_content_length() > 0) < 0) {
380
381 disconnected_ = true;
382 return false;
383 } else if (zstream_ == NULL) {
384 return true;
385 }
386
387 // ����Dz��� gzip ����ѹ����ʽ������Ҫ����� gzip ͷ
388
389 /**
390 * RFC 1952 Section 2.3 defines the gzip header:
391 * +---+---+---+---+---+---+---+---+---+---+
392 * |ID1|ID2|CM |FLG| MTIME |XFL|OS |

Callers 5

get_urlFunction · 0.45
http_requestMethod · 0.45
test2Function · 0.45
sendHeaderMethod · 0.45
responseMethod · 0.45

Calls 8

zip_beginMethod · 0.80
crc32_updateMethod · 0.80
is_requestMethod · 0.80
build_responseMethod · 0.80
build_requestMethod · 0.45
writeMethod · 0.45
c_strMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected