trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jpe...@apache.org
Subject git commit: TS-2064: authproxy plugin errors do not include a body
Date Wed, 24 Jul 2013 00:23:41 GMT
Updated Branches:
  refs/heads/master b72763925 -> 0257a617b


TS-2064: authproxy plugin errors do not include a body

Use TSHttpTxnErrorBodySet() to always set a response body when there
response status is not 2xx.


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/0257a617
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/0257a617
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/0257a617

Branch: refs/heads/master
Commit: 0257a617b74d618323b285290effbfea14aabb3b
Parents: b727639
Author: James Peach <jpeach@apache.org>
Authored: Tue Jul 23 17:18:06 2013 -0700
Committer: James Peach <jpeach@apache.org>
Committed: Tue Jul 23 17:18:06 2013 -0700

----------------------------------------------------------------------
 CHANGES                                     |  2 ++
 plugins/experimental/authproxy/authproxy.cc | 19 +++++++++++--------
 2 files changed, 13 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/0257a617/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 213b6a0..5597d10 100644
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,8 @@
 Changes with Apache Traffic Server 3.3.5
 
 
+  *) [TS-2064] Fix the authproxy plugin to send an error body.
+
   *) [TS-2041] Allow environment values to override records.config settings.
 
   *) [TS-2044] Avoid logging client running into DENY status infinitely.

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/0257a617/plugins/experimental/authproxy/authproxy.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/authproxy/authproxy.cc b/plugins/experimental/authproxy/authproxy.cc
index f6bb726..c4c939d 100644
--- a/plugins/experimental/authproxy/authproxy.cc
+++ b/plugins/experimental/authproxy/authproxy.cc
@@ -519,13 +519,13 @@ StateAuthProxySendResponse(AuthRequestContext * auth, void * /* edata
ATS_UNUSED
 {
     TSMBuffer mbuf;
     TSMLoc mhdr;
+    TSHttpStatus status;
+    char msg[128];
 
     // The auth proxy denied this request. We need to copy the auth proxy
     // response header to the client response header, then read any available
     // body data and copy that as well.
 
-    AuthLogDebug("sending auth proxy response");
-
     // There's only a client response if the auth proxy sent one. There
     TSReleaseAssert(
         TSHttpTxnClientRespGet(auth->txn, &mbuf, &mhdr) == TS_SUCCESS
@@ -535,6 +535,11 @@ StateAuthProxySendResponse(AuthRequestContext * auth, void * /* edata
ATS_UNUSED
         TSHttpHdrCopy(mbuf, mhdr, auth->rheader.buffer, auth->rheader.header) == TS_SUCCESS
     );
 
+    status = TSHttpHdrStatusGet(mbuf, mhdr),
+    snprintf(msg, sizeof(msg), "%d %s\n", status, TSHttpHdrReasonLookup(status));
+
+    TSHttpTxnErrorBodySet(auth->txn, TSstrdup(msg), strlen(msg), NULL);
+
     // We must not whack the content length for HEAD responses, since the
     // client already knows that there is no body. Forcing content length to
     // zero breaks hdiutil(1) on Mac OS X.
@@ -542,6 +547,8 @@ StateAuthProxySendResponse(AuthRequestContext * auth, void * /* edata
ATS_UNUSED
         HttpSetMimeHeader(mbuf, mhdr, TS_MIME_FIELD_CONTENT_LENGTH, 0u);
     }
 
+    AuthLogDebug("sending auth proxy response for status %d", status);
+
     TSHttpTxnReenable(auth->txn, TS_EVENT_HTTP_CONTINUE);
     TSHandleMLocRelease(mbuf, TS_NULL_MLOC, mhdr);
     return TS_EVENT_CONTINUE;
@@ -654,14 +661,10 @@ StateAuthProxyCompleteContent(AuthRequestContext * auth, void * /* edata
ATS_UNU
 static TSEvent
 StateUnauthorized(AuthRequestContext * auth, void *)
 {
-    AuthLogDebug("request denied");
+    static const char msg[] = "authorization denied\n";
 
     TSHttpTxnSetHttpRetStatus(auth->txn, TS_HTTP_STATUS_FORBIDDEN);
-
-    // XXX ATS doesn't actually send the response body when you set it like
-    // this. This is the pattern you would use for a remap plugin; seems like a
-    // bug ...
-    TSHttpTxnSetHttpRetBody(auth->txn, "authorization denied", 1 /* is plain text */);
+    TSHttpTxnErrorBodySet(auth->txn, TSstrdup(msg), sizeof(msg) - 1, NULL);
 
     TSHttpTxnReenable(auth->txn, TS_EVENT_HTTP_ERROR);
     return TS_EVENT_CONTINUE;


Mime
View raw message