cmcfarlen commented on code in PR #12494: URL: https://github.com/apache/trafficserver/pull/12494#discussion_r2353314785
########## plugins/esi/combo_handler.cc: ########## @@ -585,18 +597,21 @@ getClientRequest(TSHttpTxn txnp, TSMBuffer bufp, TSMLoc hdr_loc, TSMLoc url_loc, int query_len; const char *query = TSUrlHttpQueryGet(bufp, url_loc, &query_len); + // Get URL string for error reporting. + std::string url_string = getUrlString(bufp, url_loc); Review Comment: In the happy path, this is unused. Could move this call so it only happens when necessary. ########## plugins/esi/http_utils.cc: ########## @@ -0,0 +1,67 @@ +/** @file + + Implementation of HTTP utilities for ESI plugins. + + @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 "http_utils.h" + +#include <ts/ts.h> + +std::string +getRequestUrlString(TSHttpTxn txnp) +{ + std::string request_url = UNKNOWN_URL_STRING; + TSMBuffer req_bufp; + TSMLoc req_hdr_loc; + TSMLoc url_loc; + + if (TSHttpTxnClientReqGet(txnp, &req_bufp, &req_hdr_loc) == TS_SUCCESS) { + if (TSHttpTxnPristineUrlGet(txnp, &req_bufp, &url_loc) == TS_SUCCESS) { + int length = 0; + char *url_string = TSUrlStringGet(req_bufp, url_loc, &length); + if (url_string) { + request_url.assign(url_string, length); + TSfree(url_string); + } Review Comment: Seems like this could just call the new `getUrlString`. Consider returning `std::optional<std::string>` instead of a magic value if that seems appropriate. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
