You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by ig...@apache.org on 2012/10/24 20:46:43 UTC
git commit: remove MakeErrorBodyVA, enable body_factory by default
Updated Branches:
refs/heads/master c3c37e48d -> 962d86485
remove MakeErrorBodyVA, enable body_factory by default
We're getting rid of the hard-coded, HTML in C++ HTTP responses
and enabling the customizable body_factory by default.
Outstanding issues:
* Cache the documents so they don't have to
be loaded from the FS, everytime we access them.
* make "default" (the name of the body_factory) an actual
configuration item
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/962d8648
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/962d8648
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/962d8648
Branch: refs/heads/master
Commit: 962d864851332858a202f8c14a9ec671ec4e9a6c
Parents: c3c37e4
Author: Igor Galić <i....@brainsware.org>
Authored: Wed Oct 24 20:43:11 2012 +0200
Committer: Igor Galić <i....@brainsware.org>
Committed: Wed Oct 24 20:43:11 2012 +0200
----------------------------------------------------------------------
mgmt/RecordsConfig.cc | 2 +-
proxy/Transform.cc | 3 +-
proxy/config/records.config.default.in | 2 +-
proxy/http/HttpBodyFactory.cc | 16 +---
proxy/http/HttpMessageBody.cc | 128 ---------------------------
proxy/http/HttpMessageBody.h | 60 -------------
proxy/http/HttpTransact.cc | 7 +-
proxy/http/HttpTransactCache.cc | 1 -
proxy/http/HttpTransactHeaders.cc | 3 +-
proxy/http/Makefile.am | 2 -
10 files changed, 11 insertions(+), 213 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/962d8648/mgmt/RecordsConfig.cc
----------------------------------------------------------------------
diff --git a/mgmt/RecordsConfig.cc b/mgmt/RecordsConfig.cc
index 6027a22..ba983b0 100644
--- a/mgmt/RecordsConfig.cc
+++ b/mgmt/RecordsConfig.cc
@@ -750,7 +750,7 @@ RecordElement RecordsConfig[] = {
//# 0 - turn off customizable user response pages
//# 1 - enable customizable user response pages in only the "default" directory
//# 2 - enable language-targeted user response pages
- {RECT_CONFIG, "proxy.config.body_factory.enable_customizations", RECD_INT, "0", RECU_RESTART_TS, RR_NULL, RECC_INT, "[0-2]", RECA_NULL}
+ {RECT_CONFIG, "proxy.config.body_factory.enable_customizations", RECD_INT, "1", RECU_RESTART_TS, RR_NULL, RECC_INT, "[0-2]", RECA_NULL}
,
{RECT_CONFIG, "proxy.config.body_factory.enable_logging", RECD_INT, "0", RECU_RESTART_TS, RR_NULL, RECC_INT, "[0-1]", RECA_NULL}
,
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/962d8648/proxy/Transform.cc
----------------------------------------------------------------------
diff --git a/proxy/Transform.cc b/proxy/Transform.cc
index 8a71878..7bf0cf4 100644
--- a/proxy/Transform.cc
+++ b/proxy/Transform.cc
@@ -65,7 +65,6 @@
#include "P_Net.h"
#include "MimeTable.h"
#include "TransformInternal.h"
-#include "HttpMessageBody.h"
#include "HdrUtils.h"
#include "Log.h"
@@ -997,7 +996,7 @@ RangeTransform::change_response_header()
status_code = HTTP_STATUS_PARTIAL_CONTENT;
m_transform_resp->status_set(status_code);
- reason_phrase = (char *) (HttpMessageBody::StatusCodeName(status_code));
+ reason_phrase = (char *) (http_hdr_reason_lookup(status_code));
m_transform_resp->reason_set(reason_phrase, strlen(reason_phrase));
// set the right Content-Type for multiple entry Range
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/962d8648/proxy/config/records.config.default.in
----------------------------------------------------------------------
diff --git a/proxy/config/records.config.default.in b/proxy/config/records.config.default.in
index 48ee20a..33a16e2 100644
--- a/proxy/config/records.config.default.in
+++ b/proxy/config/records.config.default.in
@@ -282,7 +282,7 @@ CONFIG proxy.config.http.enable_http_stats INT 1
# 0 - turn off customizable user response pages
# 1 - enable customizable user response pages in only the "default" directory
# 2 - enable language-targeted user response pages
-CONFIG proxy.config.body_factory.enable_customizations INT 0
+CONFIG proxy.config.body_factory.enable_customizations INT 1
CONFIG proxy.config.body_factory.enable_logging INT 0
# 0 - never suppress generated responses
# 1 - always suppress generated responses
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/962d8648/proxy/http/HttpBodyFactory.cc
----------------------------------------------------------------------
diff --git a/proxy/http/HttpBodyFactory.cc b/proxy/http/HttpBodyFactory.cc
index 79a23cb..8c11a27 100644
--- a/proxy/http/HttpBodyFactory.cc
+++ b/proxy/http/HttpBodyFactory.cc
@@ -34,7 +34,6 @@
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
-#include "HttpMessageBody.h"
#include "URL.h"
#include <logging/Log.h>
#include <logging/LogAccess.h>
@@ -160,8 +159,8 @@ HttpBodyFactory::fabricate_with_old_api(const char *type, HttpTransact::State *
buffer = (char *)ats_free_null(buffer);
}
/////////////////////////////////////////////////////////////////////
- // handle return of instantiated template or internal default, and //
- // generate the content language and content type return values //
+ // handle return of instantiated template and generate the content //
+ // language and content type return values //
/////////////////////////////////////////////////////////////////////
if (buffer) { // got an instantiated template
@@ -180,17 +179,10 @@ HttpBodyFactory::fabricate_with_old_api(const char *type, HttpTransact::State *
set, type, set, "default", url, lang_ptr, charset_ptr);
}
}
- } else { // no template, using old style body
- buffer = HttpMessageBody::MakeErrorBodyVA(max_buffer_length, resulting_buffer_length,
- context->http_config_param, status_code, reason_or_null, format, ap);
+ } else { // no template
if (enable_logging) {
- if (enable_customizations) { // we wanted a template
- Log::error(("BODY_FACTORY: customization enabled "
- "but can't find templates '%s' or '%s', using hardcoded default body for url '%s'"),
+ Log::error(("BODY_FACTORY: can't find templates '%s' or '%s' for url `%s'"),
type, "default", url);
- } else { // we wanted an old-style body
- Log::error(("BODY_FACTORY: using hardcoded default '%s' body for url '%s'"), type, url);
- }
}
}
unlock();
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/962d8648/proxy/http/HttpMessageBody.cc
----------------------------------------------------------------------
diff --git a/proxy/http/HttpMessageBody.cc b/proxy/http/HttpMessageBody.cc
deleted file mode 100644
index 22380b7..0000000
--- a/proxy/http/HttpMessageBody.cc
+++ /dev/null
@@ -1,128 +0,0 @@
-/** @file
-
- Routines to construct and manipulate message bodies and format error responses
-
- @section license License
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
-
-#include "ink_unused.h" /* MAGIC_EDITING_TAG */
-#include "HttpMessageBody.h"
-#include "HttpConfig.h"
-
-/** This routine returns a constant string name for the status_code. */
-const char *
-HttpMessageBody::StatusCodeName(HTTPStatus status_code)
-{
- return http_hdr_reason_lookup(status_code);
-}
-
-/**
- This routine creates an HTTP error message body for the status code and
- printf format string format and args va, allocates a response buffer
- (using malloc), and places the result body in the buffer. The body
- will be NUL terminated.
-
- The caller must ats_free() the returned object when done.
-
- The reason string allows you to override the default reason phrase for
- the status code. If it is NULL, the default is used. If format is NULL
- or "", no additional text is added.
-
- NULL is returned if the resulting length exceeds max_buffer_length.
-
-*/
-char *
-HttpMessageBody::MakeErrorBodyVA(int64_t max_buffer_length,
- int64_t *resulting_buffer_length,
- const HttpConfigParams * config,
- HTTPStatus status_code, const char *reason, const char *format, va_list va)
-{
- NOWARN_UNUSED(config);
- char *p, *outbuf = NULL;
- char error_title[128];
- int pass;
- int64_t l, output_length;
-
- if (reason == NULL)
- reason = (char *) (StatusCodeName(status_code));
-
- output_length = 0;
- *resulting_buffer_length = 0;
-
- for (pass = 1; pass <= 2; pass++) {
- if (pass == 2) {
- ats_free(outbuf);
- if (output_length > max_buffer_length)
- return (NULL);
- else
- outbuf = (char *)ats_malloc(output_length);
- }
-
- l = 0;
- p = outbuf;
-
- ink_strlcpy(error_title, reason, sizeof(error_title));
-
- p = (pass == 1 ? (char *) NULL : &(outbuf[l]));
- l += ink_bsprintf(p, "<HEAD><TITLE>%s</TITLE></HEAD>\n", error_title) - 1;
-
- p = (pass == 1 ? (char *) NULL : &(outbuf[l]));
- l += ink_bsprintf(p, "<BODY BGCOLOR=\"white\" FGCOLOR=\"black\">") - 1;
-
- p = (pass == 1 ? (char *) NULL : &(outbuf[l]));
- //l += ink_bsprintf(p,"<H1>%s</H1><HR>\n",error_title) - 1;
- l += ink_bsprintf(p, "\n") - 1;
-
- p = (pass == 1 ? (char *) NULL : &(outbuf[l]));
- l += ink_bsprintf(p, "<FONT FACE=\"Helvetica,Arial\"><B>\n") - 1;
-
- if (format && *format) {
- p = (pass == 1 ? (char *) NULL : &(outbuf[l]));
- //l += ink_bsprintf(p,"Description: ") - 1;
- l += ink_bsprintf(p, " ") - 1;
-
- p = (pass == 1 ? (char *) NULL : &(outbuf[l]));
- l += ink_bvsprintf(p, format, va) - 1;
- }
-
- p = (pass == 1 ? (char *) NULL : &(outbuf[l]));
- l += ink_bsprintf(p, "</B></FONT>\n") - 1;
-
- p = (pass == 1 ? (char *) NULL : &(outbuf[l]));
- //l += ink_bsprintf(p,"<HR>\n") - 1;
- l += ink_bsprintf(p, "\n") - 1;
-
- // Moved trailing info into a comment
- p = (pass == 1 ? (char *) NULL : &(outbuf[l]));
- l += ink_bsprintf(p, "<!-- default \"%s\" response (%d) -->\n", reason, status_code) - 1;
-
- p = (pass == 1 ? (char *) NULL : &(outbuf[l]));
- l += ink_bsprintf(p, "</BODY>\n") - 1;
-
- l++; // leave room for trailing NUL
-
- if (pass == 2) {
- ink_release_assert(l == output_length);
- }
- output_length = l;
- }
-
- *resulting_buffer_length = output_length;
- return (outbuf);
-}
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/962d8648/proxy/http/HttpMessageBody.h
----------------------------------------------------------------------
diff --git a/proxy/http/HttpMessageBody.h b/proxy/http/HttpMessageBody.h
deleted file mode 100644
index ec94d04..0000000
--- a/proxy/http/HttpMessageBody.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/** @file
-
- Routines to construct and manipulate msg bodies and format err responses
-
- @section license License
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
-
-#ifndef _HttpMessageBody_h_
-#define _HttpMessageBody_h_
-
-#include "libts.h"
-#include "HTTP.h"
-#include "HttpConfig.h"
-#include "Error.h"
-#include "Main.h"
-
-class HttpMessageBody
-{
-public:
- static const char *StatusCodeName(HTTPStatus status_code);
-
- static char *MakeErrorBody(int64_t max_buffer_length,
- int64_t *resulting_buffer_length,
- const HttpConfigParams * config,
- HTTPStatus status_code, char *reason_or_null, char *format, ...)
- {
- va_list va;
- char *ret;
-
- va_start(va, format);
- ret = MakeErrorBodyVA(max_buffer_length, resulting_buffer_length,
- config, status_code, reason_or_null, format, va);
- va_end(va);
-
- return ret;
- }
-
- static char *MakeErrorBodyVA(int64_t max_buffer_length,
- int64_t *resulting_buffer_length,
- const HttpConfigParams * config,
- HTTPStatus status_code, const char *reason_or_null, const char *format, va_list va);
-};
-
-#endif
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/962d8648/proxy/http/HttpTransact.cc
----------------------------------------------------------------------
diff --git a/proxy/http/HttpTransact.cc b/proxy/http/HttpTransact.cc
index a894b6a..1d0e07a 100644
--- a/proxy/http/HttpTransact.cc
+++ b/proxy/http/HttpTransact.cc
@@ -35,7 +35,6 @@
#include "ParseRules.h"
#include "HTTP.h"
#include "HdrUtils.h"
-#include "HttpMessageBody.h"
#include "MimeTable.h"
#include "logging/Log.h"
#include "logging/LogUtils.h"
@@ -7863,7 +7862,7 @@ HttpTransact::build_response(State* s, HTTPHdr* base_response, HTTPHdr* outgoing
HTTPStatus status_code, const char *reason_phrase)
{
if (reason_phrase == NULL) {
- reason_phrase = HttpMessageBody::StatusCodeName(status_code);
+ reason_phrase = http_hdr_reason_lookup(status_code);
}
if (base_response == NULL) {
@@ -8099,7 +8098,7 @@ HttpTransact::build_error_response(State *s, HTTPStatus status_code, const char
}
va_start(ap, format);
- reason_phrase = (reason_phrase_or_null ? reason_phrase_or_null : (char *) (HttpMessageBody::StatusCodeName(status_code)));
+ reason_phrase = (reason_phrase_or_null ? reason_phrase_or_null : (char *) (http_hdr_reason_lookup(status_code)));
if (unlikely(!reason_phrase))
reason_phrase = "Unknown HTTP Status";
@@ -8224,7 +8223,7 @@ HttpTransact::build_redirect_response(State* s)
char body_language[256], body_type[256];
HTTPStatus status_code = HTTP_STATUS_MOVED_TEMPORARILY;
- char *reason_phrase = (char *) (HttpMessageBody::StatusCodeName(status_code));
+ char *reason_phrase = (char *) (http_hdr_reason_lookup(status_code));
build_response(s, &s->hdr_info.client_response, s->client_info.http_version, status_code, reason_phrase);
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/962d8648/proxy/http/HttpTransactCache.cc
----------------------------------------------------------------------
diff --git a/proxy/http/HttpTransactCache.cc b/proxy/http/HttpTransactCache.cc
index 5004c6e..fec89af 100644
--- a/proxy/http/HttpTransactCache.cc
+++ b/proxy/http/HttpTransactCache.cc
@@ -29,7 +29,6 @@
#include "time.h"
#include "HTTP.h"
#include "HttpCompat.h"
-#include "HttpMessageBody.h"
#include "Error.h"
#include "InkErrno.h"
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/962d8648/proxy/http/HttpTransactHeaders.cc
----------------------------------------------------------------------
diff --git a/proxy/http/HttpTransactHeaders.cc b/proxy/http/HttpTransactHeaders.cc
index c09d66a..5f112c3 100644
--- a/proxy/http/HttpTransactHeaders.cc
+++ b/proxy/http/HttpTransactHeaders.cc
@@ -27,7 +27,6 @@
#include "HTTP.h"
#include "HdrUtils.h"
#include "HttpCompat.h"
-#include "HttpMessageBody.h"
#include "I_Machine.h"
@@ -879,7 +878,7 @@ HttpTransactHeaders::convert_wuts_code_to_normal_reason(HTTPHdr *hdr)
if (!phrase || (length == 0 || (phrase[0] != '!')))
return;
- phrase = (const char *) HttpMessageBody::StatusCodeName(hdr->status_get());
+ phrase = (const char *) http_hdr_reason_lookup(hdr->status_get());
hdr->reason_set(phrase, strlen(phrase));
}
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/962d8648/proxy/http/Makefile.am
----------------------------------------------------------------------
diff --git a/proxy/http/Makefile.am b/proxy/http/Makefile.am
index ed4a2f8..f742c5d 100644
--- a/proxy/http/Makefile.am
+++ b/proxy/http/Makefile.am
@@ -51,8 +51,6 @@ libhttp_a_SOURCES = \
HttpConnectionCount.h \
HttpDebugNames.cc \
HttpDebugNames.h \
- HttpMessageBody.cc \
- HttpMessageBody.h \
HttpPages.cc \
HttpPages.h \
HttpProxyServerMain.cc \