Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion doc/developer-guide/api/functions/TSUrlHostGet.en.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Synopsis

.. function:: const char * TSUrlHostGet(TSMBuffer bufp, TSMLoc offset, int * length)
.. function:: const char * TSUrlSchemeGet(TSMBuffer bufp, TSMLoc offset, int * length)
.. function:: const char * TSUrlRawSchemeGet(TSMBuffer bufp, TSMLoc offset, int * length)
.. function:: const char * TSUrlUserGet(TSMBuffer bufp, TSMLoc offset, int * length)
.. function:: const char * TSUrlPasswordGet(TSMBuffer bufp, TSMLoc offset, int* length)
.. function:: int TSUrlPortGet(TSMBuffer bufp, TSMLoc offset)
Expand All @@ -50,13 +51,17 @@ buffers. The URL functions can create, copy, retrieve or delete entire URLs,
and retrieve or modify parts of URLs, such as their host, port or scheme
information.

:func:`TSUrlSchemeGet`, :func:`TSUrlUserGet`, :func:`TSUrlPasswordGet`,
:func:`TSUrlSchemeGet`, :func:`TSUrlRawSchemeGet`, :func:`TSUrlUserGet`, :func:`TSUrlPasswordGet`,
:func:`TSUrlHostGet`, :func:`TSUrlPathGet`, :func:`TSUrlHttpParamsGet`, :func:`TSUrlHttpQueryGet`
and :func:`TSUrlHttpFragmentGet` each retrieve an internal pointer to the
specified portion of the URL from the marshall buffer :arg:`bufp`. The length
of the returned string is placed in :arg:`length` and a pointer to the URL
portion is returned.

If a request URL does not have a explicit scheme, :func:`TSUrlRawSchemeGet` will return null and
set :arg:`length` to zero. :func:`TSUrlSchemeGet`, will return the scheme corresponding to the
URL type (HTTP or HTTPS) if there is no explicit scheme.

:func:`TSUrlPortGet` retrieves the port number portion of the URL located at
:arg:`offset` within the marshal buffer :arg:`bufp`. If there is no explicit
port number in the URL, a canonicalized valued is returned based on the URL
Expand Down
7 changes: 4 additions & 3 deletions doc/developer-guide/plugins/http-headers/urls.en.rst
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,10 @@ one of the known values. If it is, then it stores a pointer into a
global table (instead of storing the known value in the marshal buffer).
The scheme values listed above are also pointers into this table. This
allows simple pointer comparison of the value returned from
``TSUrlSchemeGet`` with one of the values listed above. You should use
the Traffic Server-defined values when referring to one of the known
schemes, since doing so can prevent the possibility of spelling errors.
``TSUrlSchemeGet`` or ``TSUrlRawSchemeGet`` with one of the values
listed above. You should use the Traffic Server-defined values when
referring to one of the known schemes, since doing so can prevent the
possibility of spelling errors.

Traffic Server **URL functions** are listed below:

Expand Down
16 changes: 16 additions & 0 deletions include/ts/ts.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,22 @@ tsapi char *TSUrlStringGet(TSMBuffer bufp, TSMLoc offset, int *length);
@param length length of the returned string.
@return The scheme portion of the URL, as a string.

*/
tsapi const char *TSUrlRawSchemeGet(TSMBuffer bufp, TSMLoc offset, int *length);

/**
Retrieves the scheme portion of the URL located at url_loc within
the marshal buffer bufp. TSUrlSchemeGet() places the length of
the string in the length argument. If the length is NULL then no
attempt is made to dereference it. If there is no explicit scheme,
a scheme of http is returned if the URL type is HTTP, and a scheme
of https is returned if the URL type is HTTPS.

@param bufp marshal buffer storing the URL.
@param offset location of the URL within bufp.
@param length length of the returned string.
@return The scheme portion of the URL, as a string.

*/
tsapi const char *TSUrlSchemeGet(TSMBuffer bufp, TSMLoc offset, int *length);

Expand Down
25 changes: 24 additions & 1 deletion src/traffic_server/InkAPI.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2350,11 +2350,34 @@ URLPartSet(TSMBuffer bufp, TSMLoc obj, const char *value, int length, URLPartSet
}

const char *
TSUrlSchemeGet(TSMBuffer bufp, TSMLoc obj, int *length)
TSUrlRawSchemeGet(TSMBuffer bufp, TSMLoc obj, int *length)
{
return URLPartGet(bufp, obj, length, &URL::scheme_get);
}

const char *
TSUrlSchemeGet(TSMBuffer bufp, TSMLoc obj, int *length)
{
char const *data = TSUrlRawSchemeGet(bufp, obj, length);
if (data && *length) {
return data;
}
switch (reinterpret_cast<URLImpl *>(obj)->m_url_type) {
case URL_TYPE_HTTP:
data = URL_SCHEME_HTTP;
*length = URL_LEN_HTTP;
break;
case URL_TYPE_HTTPS:
data = URL_SCHEME_HTTPS;
*length = URL_LEN_HTTPS;
break;
default:
*length = 0;
data = nullptr;
}
return data;
}

TSReturnCode
TSUrlSchemeSet(TSMBuffer bufp, TSMLoc obj, const char *value, int length)
{
Expand Down
1 change: 1 addition & 0 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ AM_LDFLAGS += -rpath $(abs_builddir)

include gold_tests/continuations/plugins/Makefile.inc
include gold_tests/chunked_encoding/Makefile.inc
include gold_tests/pluginTest/tsapi/Makefile.inc
include gold_tests/timeout/Makefile.inc
include gold_tests/tls/Makefile.inc
include tools/plugins/Makefile.inc
Expand Down
18 changes: 18 additions & 0 deletions tests/gold_tests/pluginTest/tsapi/Makefile.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 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.

noinst_LTLIBRARIES += gold_tests/pluginTest/tsapi/test_tsapi.la
gold_tests_pluginTest_tsapi_test_tsapi_la_SOURCES = gold_tests/pluginTest/tsapi/test_tsapi.cc
137 changes: 129 additions & 8 deletions tests/gold_tests/pluginTest/tsapi/log.gold
Original file line number Diff line number Diff line change
@@ -1,14 +1,135 @@
TSRemapNewInstance():
argv[0]=http://myhost.test/
argv[1]=http://127.0.0.1:SERVER_PORT/
TSRemapNewInstance():
argv[0]=http://myhost.test/
argv[1]=http://127.0.0.1:SERVER_PORT/
TSRemapNewInstance():
argv[0]=https://myhost.test:123/
argv[1]=http://127.0.0.1:SERVER_PORT/
TSRemapNewInstance():
argv[0]=https://myhost.test:123/
argv[1]=http://127.0.0.1:SERVER_PORT/
Global: event=TS_EVENT_HTTP_TXN_START
Global: event=TS_EVENT_HTTP_READ_REQUEST_HDR
TSHttpTxnEffectiveUrlStringGet(): http://mYhOsT.teSt:SERVER_PORT/
TSHttpHdrEffectiveUrlBufGet(): http://myhost.test:SERVER_PORT/
TSHttpTxnEffectiveUrlStringGet(): http://mYhOsT.teSt/
Client Request:
TSHttpHdrEffectiveUrlBufGet(): http://myhost.test/
TSUrlSchemeGet(): http
TSUrlRawSchemeGet(): http
TSUrlPortGet(): 80
Transaction: event=TS_EVENT_HTTP_READ_REQUEST_HDR
TSHttpTxnEffectiveUrlStringGet(): http://mYhOsT.teSt:SERVER_PORT/
TSHttpHdrEffectiveUrlBufGet(): http://myhost.test:SERVER_PORT/
TSHttpTxnEffectiveUrlStringGet(): http://mYhOsT.teSt/
Client Request:
TSHttpHdrEffectiveUrlBufGet(): http://myhost.test/
TSUrlSchemeGet(): http
TSUrlRawSchemeGet(): http
TSUrlPortGet(): 80
TSRemapDoRemap(): instance=0 redirect=0
Remap Request:
TSHttpHdrEffectiveUrlBufGet(): http://127.0.0.1:SERVER_PORT/
TSUrlSchemeGet(): http
TSUrlRawSchemeGet(): http
TSUrlPortGet(): SERVER_PORT
TSRemapDoRemap(): instance=1 redirect=0
Remap Request:
TSHttpHdrEffectiveUrlBufGet(): http://127.0.0.1:SERVER_PORT/
TSUrlSchemeGet(): http
TSUrlRawSchemeGet(): http
TSUrlPortGet(): SERVER_PORT
Global: event=TS_EVENT_HTTP_SEND_REQUEST_HDR
TSHttpTxnEffectiveUrlStringGet(): http://127.0.0.1:SERVER_PORT/
Request To Server:
TSHttpHdrEffectiveUrlBufGet(): 127.0.0.1:SERVER_PORT/
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be fixed in a future PR. Should include the implicit scheme.

TSUrlSchemeGet(): http
TSUrlRawSchemeGet(): failed to get raw URL scheme
TSUrlPortGet(): 80
Transaction: event=TS_EVENT_HTTP_SEND_REQUEST_HDR
TSHttpTxnEffectiveUrlStringGet(): http://127.0.0.1:SERVER_PORT/
Request To Server:
TSHttpHdrEffectiveUrlBufGet(): 127.0.0.1:SERVER_PORT/
TSUrlSchemeGet(): http
TSUrlRawSchemeGet(): failed to get raw URL scheme
TSUrlPortGet(): 80
Global: event=TS_EVENT_HTTP_TXN_START
Global: event=TS_EVENT_HTTP_READ_REQUEST_HDR
TSHttpTxnEffectiveUrlStringGet(): https://myhost.test:SERVER_PORT/
TSHttpHdrEffectiveUrlBufGet(): https://myhost.test:SERVER_PORT/
TSHttpTxnEffectiveUrlStringGet(): http://mYhOsT.teSt/xYz
Client Request:
TSHttpHdrEffectiveUrlBufGet(): http://myhost.test/xYz
TSUrlSchemeGet(): http
TSUrlRawSchemeGet(): http
TSUrlPortGet(): 80
Transaction: event=TS_EVENT_HTTP_READ_REQUEST_HDR
TSHttpTxnEffectiveUrlStringGet(): https://myhost.test:SERVER_PORT/
TSHttpHdrEffectiveUrlBufGet(): https://myhost.test:SERVER_PORT/
TSHttpTxnEffectiveUrlStringGet(): http://mYhOsT.teSt/xYz
Client Request:
TSHttpHdrEffectiveUrlBufGet(): http://myhost.test/xYz
TSUrlSchemeGet(): http
TSUrlRawSchemeGet(): http
TSUrlPortGet(): 80
TSRemapDoRemap(): instance=0 redirect=0
Remap Request:
TSHttpHdrEffectiveUrlBufGet(): http://127.0.0.1:SERVER_PORT/xYz
TSUrlSchemeGet(): http
TSUrlRawSchemeGet(): http
TSUrlPortGet(): SERVER_PORT
TSRemapDoRemap(): instance=1 redirect=0
Remap Request:
TSHttpHdrEffectiveUrlBufGet(): http://127.0.0.1:SERVER_PORT/xYz
TSUrlSchemeGet(): http
TSUrlRawSchemeGet(): http
TSUrlPortGet(): SERVER_PORT
Global: event=TS_EVENT_HTTP_SEND_REQUEST_HDR
TSHttpTxnEffectiveUrlStringGet(): http://127.0.0.1:SERVER_PORT/xYz
Request To Server:
TSHttpHdrEffectiveUrlBufGet(): 127.0.0.1:SERVER_PORT/xYz
TSUrlSchemeGet(): http
TSUrlRawSchemeGet(): failed to get raw URL scheme
TSUrlPortGet(): 80
Transaction: event=TS_EVENT_HTTP_SEND_REQUEST_HDR
TSHttpTxnEffectiveUrlStringGet(): http://127.0.0.1:SERVER_PORT/xYz
Request To Server:
TSHttpHdrEffectiveUrlBufGet(): 127.0.0.1:SERVER_PORT/xYz
TSUrlSchemeGet(): http
TSUrlRawSchemeGet(): failed to get raw URL scheme
TSUrlPortGet(): 80
Global: event=TS_EVENT_HTTP_TXN_START
Global: event=TS_EVENT_HTTP_READ_REQUEST_HDR
TSHttpTxnEffectiveUrlStringGet(): https://myhost.test:123/
Client Request:
TSHttpHdrEffectiveUrlBufGet(): https://myhost.test:123/
TSUrlSchemeGet(): https
TSUrlRawSchemeGet(): https
TSUrlPortGet(): 123
Transaction: event=TS_EVENT_HTTP_READ_REQUEST_HDR
TSHttpTxnEffectiveUrlStringGet(): https://myhost.test:123/
Client Request:
TSHttpHdrEffectiveUrlBufGet(): https://myhost.test:123/
TSUrlSchemeGet(): https
TSUrlRawSchemeGet(): https
TSUrlPortGet(): 123
TSRemapDoRemap(): instance=2 redirect=0
Remap Request:
TSHttpHdrEffectiveUrlBufGet(): http://127.0.0.1:SERVER_PORT/
TSUrlSchemeGet(): http
TSUrlRawSchemeGet(): http
TSUrlPortGet(): SERVER_PORT
TSRemapDoRemap(): instance=3 redirect=0
Remap Request:
TSHttpHdrEffectiveUrlBufGet(): http://127.0.0.1:SERVER_PORT/
TSUrlSchemeGet(): http
TSUrlRawSchemeGet(): http
TSUrlPortGet(): SERVER_PORT
Global: event=TS_EVENT_HTTP_SEND_REQUEST_HDR
TSHttpTxnEffectiveUrlStringGet(): http://127.0.0.1:SERVER_PORT/
Request To Server:
TSHttpHdrEffectiveUrlBufGet(): 127.0.0.1:SERVER_PORT/
TSUrlSchemeGet(): http
TSUrlRawSchemeGet(): failed to get raw URL scheme
TSUrlPortGet(): 80
Transaction: event=TS_EVENT_HTTP_SEND_REQUEST_HDR
TSHttpTxnEffectiveUrlStringGet(): http://127.0.0.1:SERVER_PORT/
Request To Server:
TSHttpHdrEffectiveUrlBufGet(): 127.0.0.1:SERVER_PORT/
TSUrlSchemeGet(): http
TSUrlRawSchemeGet(): failed to get raw URL scheme
TSUrlPortGet(): 80
Loading