aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorTor Brede Vekterli <vekterli@yahooinc.com>2023-02-28 13:54:43 +0000
committerTor Brede Vekterli <vekterli@yahooinc.com>2023-02-28 14:17:40 +0000
commit613e8879466573ad5a0ce3e594bfa51828110fc6 (patch)
treec99294658182173aa07bdd513c7509c6573b20c7 /vespalib
parent255207d9dff5ddde9f67c21abec6d5462e77bdc6 (diff)
Pass `stringref`s to Portal response rendering
Don't need to potentially instantiate temporaries since the data is always immediately committed to another buffer.
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/vespa/vespalib/portal/http_connection.cpp14
-rw-r--r--vespalib/src/vespa/vespalib/portal/http_connection.h6
-rw-r--r--vespalib/src/vespa/vespalib/portal/portal.cpp6
-rw-r--r--vespalib/src/vespa/vespalib/portal/portal.h6
4 files changed, 18 insertions, 14 deletions
diff --git a/vespalib/src/vespa/vespalib/portal/http_connection.cpp b/vespalib/src/vespa/vespalib/portal/http_connection.cpp
index 6ea56e2659c..3d8edf2fc2e 100644
--- a/vespalib/src/vespa/vespalib/portal/http_connection.cpp
+++ b/vespalib/src/vespa/vespalib/portal/http_connection.cpp
@@ -245,14 +245,16 @@ HttpConnection::handle_event(bool, bool)
}
void
-HttpConnection::respond_with_content(const vespalib::string &content_type,
- const vespalib::string &content)
+HttpConnection::respond_with_content(vespalib::stringref content_type,
+ vespalib::stringref content)
{
{
OutputWriter dst(_output, CHUNK_SIZE);
dst.printf("HTTP/1.1 200 OK\r\n");
dst.printf("Connection: close\r\n");
- dst.printf("Content-Type: %s\r\n", content_type.c_str());
+ dst.printf("Content-Type: ");
+ dst.write(content_type.data(), content_type.size());
+ dst.printf("\r\n");
dst.printf("Content-Length: %zu\r\n", content.size());
emit_http_security_headers(dst);
dst.printf("\r\n");
@@ -263,11 +265,13 @@ HttpConnection::respond_with_content(const vespalib::string &content_type,
}
void
-HttpConnection::respond_with_error(int code, const vespalib::string &msg)
+HttpConnection::respond_with_error(int code, vespalib::stringref msg)
{
{
OutputWriter dst(_output, CHUNK_SIZE);
- dst.printf("HTTP/1.1 %d %s\r\n", code, msg.c_str());
+ dst.printf("HTTP/1.1 %d ", code);
+ dst.write(msg.data(), msg.size());
+ dst.printf("\r\n");
dst.printf("Connection: close\r\n");
dst.printf("\r\n");
}
diff --git a/vespalib/src/vespa/vespalib/portal/http_connection.h b/vespalib/src/vespa/vespalib/portal/http_connection.h
index 03d23351e7d..8540cb87e1d 100644
--- a/vespalib/src/vespa/vespalib/portal/http_connection.h
+++ b/vespalib/src/vespa/vespalib/portal/http_connection.h
@@ -53,9 +53,9 @@ public:
// Precondition: handshake must have been completed
const net::ConnectionAuthContext &auth_context() const noexcept { return *_auth_ctx; }
- void respond_with_content(const vespalib::string &content_type,
- const vespalib::string &content);
- void respond_with_error(int code, const vespalib::string &msg);
+ void respond_with_content(vespalib::stringref content_type,
+ vespalib::stringref content);
+ void respond_with_error(int code, const vespalib::stringref msg);
};
} // namespace vespalib::portal
diff --git a/vespalib/src/vespa/vespalib/portal/portal.cpp b/vespalib/src/vespa/vespalib/portal/portal.cpp
index a98562f6504..691ddaef495 100644
--- a/vespalib/src/vespa/vespalib/portal/portal.cpp
+++ b/vespalib/src/vespa/vespalib/portal/portal.cpp
@@ -77,8 +77,8 @@ Portal::GetRequest::export_params() const
}
void
-Portal::GetRequest::respond_with_content(const vespalib::string &content_type,
- const vespalib::string &content)
+Portal::GetRequest::respond_with_content(vespalib::stringref content_type,
+ vespalib::stringref content)
{
assert(active());
_conn->respond_with_content(content_type, content);
@@ -86,7 +86,7 @@ Portal::GetRequest::respond_with_content(const vespalib::string &content_type,
}
void
-Portal::GetRequest::respond_with_error(int code, const vespalib::string &msg)
+Portal::GetRequest::respond_with_error(int code, vespalib::stringref msg)
{
assert(active());
_conn->respond_with_error(code, msg);
diff --git a/vespalib/src/vespa/vespalib/portal/portal.h b/vespalib/src/vespa/vespalib/portal/portal.h
index 314dd6e7de9..6954d800c91 100644
--- a/vespalib/src/vespa/vespalib/portal/portal.h
+++ b/vespalib/src/vespa/vespalib/portal/portal.h
@@ -65,9 +65,9 @@ public:
bool has_param(const vespalib::string &name) const;
const vespalib::string &get_param(const vespalib::string &name) const;
std::map<vespalib::string, vespalib::string> export_params() const;
- void respond_with_content(const vespalib::string &content_type,
- const vespalib::string &content);
- void respond_with_error(int code, const vespalib::string &msg);
+ void respond_with_content(vespalib::stringref content_type,
+ vespalib::stringref content);
+ void respond_with_error(int code, vespalib::stringref msg);
const net::ConnectionAuthContext &auth_context() const noexcept;
~GetRequest();
};