trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject [trafficserver] branch master updated: TS-5025: Add "setHost" method to atscppapi::Request
Date Tue, 01 Nov 2016 20:33:24 GMT
This is an automated email from the ASF dual-hosted git repository.

amc pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

The following commit(s) were added to refs/heads/master by this push:
       new  a8ee66c   TS-5025: Add "setHost" method to atscppapi::Request
a8ee66c is described below

commit a8ee66c2be3aab7b972fe285f0026428a3a64fe7
Author: Alan M. Carroll <solidwallofcode@yahoo-inc.com>
AuthorDate: Tue Nov 1 09:29:00 2016 -0500

    TS-5025: Add "setHost" method to atscppapi::Request
---
 lib/cppapi/Request.cc                  | 17 +++++++++++++++++
 lib/cppapi/include/atscppapi/Request.h | 12 ++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/lib/cppapi/Request.cc b/lib/cppapi/Request.cc
index 37e69eb..03d5e0b 100644
--- a/lib/cppapi/Request.cc
+++ b/lib/cppapi/Request.cc
@@ -177,6 +177,23 @@ Request::getHeaders() const
   return state_->headers_;
 }
 
+void
+Request::setHost(std::string const &host)
+{
+  static const std::string HOST_FIELD_NAME(TS_MIME_FIELD_HOST, TS_MIME_LEN_HOST);
+
+  if (state_->hdr_buf_ && state_->hdr_loc_) {
+    Url &url = this->getUrl();
+
+    // Update the URL if it has a host currently.
+    if (!url.getHost().empty())
+      url.setHost(host);
+
+    // Force a HOST field.
+    this->getHeaders().set(HOST_FIELD_NAME, host);
+  }
+}
+
 Request::~Request()
 {
   if (state_->url_loc_) {
diff --git a/lib/cppapi/include/atscppapi/Request.h b/lib/cppapi/include/atscppapi/Request.h
index 25ab332..37990ee 100644
--- a/lib/cppapi/include/atscppapi/Request.h
+++ b/lib/cppapi/include/atscppapi/Request.h
@@ -59,6 +59,18 @@ public:
   /** @return Headers of the request */
   Headers &getHeaders() const;
 
+  /** Set the @a host for the request.
+
+      This sets all elements of the request related to the host. A @c
+      HOST header will be forced or updated, and the URL updated if it
+      already contains a host.
+
+      @note This is not the same as setting the @c HOST header
+      explicitly - that can lead to a malformed request where the host
+      in the method URL is different from the host in the HOST field.
+  */
+  void setHost(std::string const &host);
+
   ~Request();
 
 private:

-- 
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <commits@trafficserver.apache.org>'].

Mime
View raw message