memchunk: Rename append_cstr as append
We may later add append(const T &), where we require T for .size() and .data(). We can coexist former append_cstr and new one. If we pass string literal, append(const (&)[N]) is selected.
This commit is contained in:
parent
5a93bedf72
commit
d174ffeb00
|
@ -156,7 +156,7 @@ template <typename Memchunk> struct Memchunks {
|
|||
|
||||
return all;
|
||||
}
|
||||
template <size_t N> size_t append_cstr(const char (&s)[N]) {
|
||||
template <size_t N> size_t append(const char (&s)[N]) {
|
||||
return append(s, N - 1);
|
||||
}
|
||||
size_t remove(void *data, size_t count) {
|
||||
|
|
|
@ -88,14 +88,14 @@ void test_memchunks_append(void) {
|
|||
MemchunkPool16 pool;
|
||||
Memchunks16 chunks(&pool);
|
||||
|
||||
chunks.append_cstr("012");
|
||||
chunks.append("012");
|
||||
|
||||
auto m = chunks.tail;
|
||||
|
||||
CU_ASSERT(3 == m->len());
|
||||
CU_ASSERT(13 == m->left());
|
||||
|
||||
chunks.append_cstr("3456789abcdef@");
|
||||
chunks.append("3456789abcdef@");
|
||||
|
||||
CU_ASSERT(16 == m->len());
|
||||
CU_ASSERT(0 == m->left());
|
||||
|
@ -129,7 +129,7 @@ void test_memchunks_drain(void) {
|
|||
MemchunkPool16 pool;
|
||||
Memchunks16 chunks(&pool);
|
||||
|
||||
chunks.append_cstr("0123456789");
|
||||
chunks.append("0123456789");
|
||||
|
||||
size_t nread;
|
||||
|
||||
|
|
|
@ -363,13 +363,13 @@ int HttpDownstreamConnection::push_upload_data_chunk(const uint8_t *data,
|
|||
if (chunked) {
|
||||
auto chunk_size_hex = util::utox(datalen);
|
||||
output->append(chunk_size_hex.c_str(), chunk_size_hex.size());
|
||||
output->append_cstr("\r\n");
|
||||
output->append("\r\n");
|
||||
}
|
||||
|
||||
output->append(data, datalen);
|
||||
|
||||
if (chunked) {
|
||||
output->append_cstr("\r\n");
|
||||
output->append("\r\n");
|
||||
}
|
||||
|
||||
signal_write();
|
||||
|
@ -383,7 +383,7 @@ int HttpDownstreamConnection::end_upload_data() {
|
|||
}
|
||||
|
||||
auto output = downstream_->get_request_buf();
|
||||
output->append_cstr("0\r\n\r\n");
|
||||
output->append("0\r\n\r\n");
|
||||
|
||||
signal_write();
|
||||
|
||||
|
|
|
@ -587,16 +587,16 @@ void HttpsUpstream::error_reply(unsigned int status_code) {
|
|||
|
||||
auto output = downstream->get_response_buf();
|
||||
|
||||
output->append_cstr("HTTP/1.1 ");
|
||||
output->append("HTTP/1.1 ");
|
||||
auto status_str = http2::get_status_string(status_code);
|
||||
output->append(status_str.c_str(), status_str.size());
|
||||
output->append_cstr("\r\nServer: ");
|
||||
output->append("\r\nServer: ");
|
||||
output->append(get_config()->server_name, strlen(get_config()->server_name));
|
||||
output->append_cstr("\r\nContent-Length: ");
|
||||
output->append("\r\nContent-Length: ");
|
||||
auto cl = util::utos(html.size());
|
||||
output->append(cl.c_str(), cl.size());
|
||||
output->append_cstr("\r\nContent-Type: text/html; "
|
||||
"charset=UTF-8\r\nConnection: close\r\n\r\n");
|
||||
output->append("\r\nContent-Type: text/html; "
|
||||
"charset=UTF-8\r\nConnection: close\r\n\r\n");
|
||||
output->append(html.c_str(), html.size());
|
||||
|
||||
downstream->add_response_sent_bodylen(html.size());
|
||||
|
@ -770,7 +770,7 @@ int HttpsUpstream::on_downstream_body(Downstream *downstream,
|
|||
downstream->add_response_sent_bodylen(len);
|
||||
|
||||
if (downstream->get_chunked_response()) {
|
||||
output->append_cstr("\r\n");
|
||||
output->append("\r\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -778,7 +778,7 @@ int HttpsUpstream::on_downstream_body(Downstream *downstream,
|
|||
int HttpsUpstream::on_downstream_body_complete(Downstream *downstream) {
|
||||
if (downstream->get_chunked_response()) {
|
||||
auto output = downstream->get_response_buf();
|
||||
output->append_cstr("0\r\n\r\n");
|
||||
output->append("0\r\n\r\n");
|
||||
}
|
||||
if (LOG_ENABLED(INFO)) {
|
||||
DLOG(INFO, downstream) << "HTTP response completed";
|
||||
|
|
Loading…
Reference in New Issue