From d174ffeb0096dbb1b080e848f03b733ef25ce364 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 22 Jan 2015 23:54:30 +0900 Subject: [PATCH] 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. --- src/memchunk.h | 2 +- src/memchunk_test.cc | 6 +++--- src/shrpx_http_downstream_connection.cc | 6 +++--- src/shrpx_https_upstream.cc | 14 +++++++------- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/memchunk.h b/src/memchunk.h index 533832dc..05923fc9 100644 --- a/src/memchunk.h +++ b/src/memchunk.h @@ -156,7 +156,7 @@ template struct Memchunks { return all; } - template size_t append_cstr(const char (&s)[N]) { + template size_t append(const char (&s)[N]) { return append(s, N - 1); } size_t remove(void *data, size_t count) { diff --git a/src/memchunk_test.cc b/src/memchunk_test.cc index 15317347..31761282 100644 --- a/src/memchunk_test.cc +++ b/src/memchunk_test.cc @@ -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; diff --git a/src/shrpx_http_downstream_connection.cc b/src/shrpx_http_downstream_connection.cc index 281288e1..85907a3b 100644 --- a/src/shrpx_http_downstream_connection.cc +++ b/src/shrpx_http_downstream_connection.cc @@ -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(); diff --git a/src/shrpx_https_upstream.cc b/src/shrpx_https_upstream.cc index f6be0aaa..fac33d81 100644 --- a/src/shrpx_https_upstream.cc +++ b/src/shrpx_https_upstream.cc @@ -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";