Skip to content

docs: add call condition note for TSUrlHostGet - #13313

Merged
cmcfarlen merged 21 commits into
apache:masterfrom
mmustafasenoglu:docs-tsurlhostget-condition
Jul 6, 2026
Merged

docs: add call condition note for TSUrlHostGet#13313
cmcfarlen merged 21 commits into
apache:masterfrom
mmustafasenoglu:docs-tsurlhostget-condition

Conversation

@mmustafasenoglu

Copy link
Copy Markdown
Contributor

Summary

Add a note to the TSUrlHostGet documentation indicating that it should only be called after TS_HTTP_POST_REMAP_HOOK.

Changes

  • Added a note explaining that TSUrlHostGet should only be called after TS_HTTP_POST_REMAP_HOOK
  • For earlier hooks like TS_HTTP_READ_REQUEST_HDR_HOOK, TSHttpHdrHostGet should be used instead

Why

Without this note, developers may try to use TSUrlHostGet in hook phases where it won't work correctly, leading to unexpected behavior.

Fixes #5742

Add a note to the TSUrlHostGet documentation indicating that it should
only be called after TS_HTTP_POST_REMAP_HOOK. For earlier hooks like
TS_HTTP_READ_REQUEST_HDR_HOOK, TSHttpHdrHostGet should be used instead.

Fixes apache#5742
@mmustafasenoglu

Copy link
Copy Markdown
Contributor Author

Hello! This is my first contribution to Apache Traffic Server. Could you please trigger CI for this documentation PR? Thank you!

@JosiahWI

Copy link
Copy Markdown
Contributor

@bneradt The Docs job failed due to warnings (warnings are treated as errors), but the warnings I found were related to env files. I'm not sure what the issue was. Could you take a look?

@bneradt

bneradt commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

From the docs build:

reading sources... [100%] release-notes/whats-new.en
/home/jenkins/workspace/Github_Builds/docs/src/doc/developer-guide/api/functions/TSUrlHostGet.en.rst:77: ERROR: Unknown interpreted text role "data". [docutils]
/home/jenkins/workspace/Github_Builds/docs/src/doc/developer-guide/api/functions/TSUrlHostGet.en.rst:77: ERROR: Unknown interpreted text role "data". [docutils]
looking for now-outdated files... none found
...
copying images... [100%] release-notes/images/roadmap.png
dumping search index in English (code: en)... done
dumping object inventory... done
build finished with problems, 2 warnings (with warnings treated as errors).
ninja: build stopped: subcommand failed.

@mmustafasenoglu

Copy link
Copy Markdown
Contributor Author

Hi, just checking in on this docs PR. It adds a call condition note for TSUrlHostGet. Would appreciate a review when you have time. Thanks!

@bneradt

bneradt commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Hi, just checking in on this docs PR. It adds a call condition note for TSUrlHostGet. Would appreciate a review when you have time. Thanks!

Thank you for contributing, however you likely won't get a review until the docs build passes. Please see my previous comment showing the failure output.

Replace :data: with double backticks for hook names, consistent
with the rest of the documentation.

Fixes apache#5742
@mmustafasenoglu

Copy link
Copy Markdown
Contributor Author

Hi @bneradt, I've fixed the :data role error by replacing it with double backticks for the hook names. Could you please trigger CI again? Thanks!

@JosiahWI

Copy link
Copy Markdown
Contributor

@mmustafasenoglu Once you are authorized to start Jenkins jobs (@bneradt added you to the whitelist) they will start automatically when you open a PR or push to it.

@mmustafasenoglu

Copy link
Copy Markdown
Contributor Author

Hi! Just following up on this documentation PR. Added a call condition note for TSUrlHostGet specifying it should only be called after TS_HTTP_POST_REMAP_HOOK.

Let me know if any adjustments are needed. Thanks!

@JosiahWI

Copy link
Copy Markdown
Contributor

I left a comment in the linked issue. @jpeach had expressed the understanding that TSUrlHostGet does work after hooks such as TS_HTTP_READ_REQUEST_HDR_HOOK. Please help us understand why that wouldn't work correctly.

@mmustafasenoglu

Copy link
Copy Markdown
Contributor Author

Hi @JosiahWI and @jpeach,

You are entirely correct that the TSUrlHostGet API itself can be called anytime as long as the provided TSMBuffer is properly populated with a host.

However, the confusion usually stems from the transaction lifecycle in a reverse proxy setup. When a client sends a standard relative URI request (e.g., GET /path HTTP/1.1) accompanied by a Host header, the request URL in the marshal buffer (retrieved via TSHttpTxnClientReqGet) does not have the host portion populated initially. If a plugin author calls TSUrlHostGet on this request URL during an early hook like TS_HTTP_READ_REQUEST_HDR_HOOK, they will get an empty result. The URL's host is typically only populated after the remap phase is complete (TS_HTTP_POST_REMAP_HOOK).

I can update the PR documentation to make this distinction clearer: that while the API operates on any valid buffer, extracting the host from a client request transaction may require waiting until post-remap if relying on the URL instead of the Host header. Let me know if you would like me to adjust the wording this way!

@mmustafasenoglu

Copy link
Copy Markdown
Contributor Author

Hi @bneradt, @JosiahWI

I noticed the docs build failed with Unknown interpreted text role "data" on line 77. Looking at my diff, I only used :func: roles in the note block, but the build error references :data:.

Could this be a pre-existing issue in the docs build environment, or should I change the RST syntax in the note? I can simplify it to use plain monospace text instead of :func: roles if that helps.

Also, I've responded to the technical question on #5742 about whether TSUrlHostGet actually has hook-phase restrictions.

@mmustafasenoglu

Copy link
Copy Markdown
Contributor Author

Hi @JosiahWI and @bryancall,

I see that #5742 has been closed as not planned. I understand that the premise of my docs change may no longer align with the project's understanding of the API.

I'm happy to close this PR if it's no longer needed. Thank you for taking the time to review it.

@bryancall
bryancall requested a review from JosiahWI June 29, 2026 22:42
@JosiahWI

Copy link
Copy Markdown
Contributor

@mmustafasenoglu Thank you for explaining the situation with the Host header. I am going to look into that.

@JosiahWI

Copy link
Copy Markdown
Contributor

@mmustafasenoglu A quick scan of our built-in plugins shows that we use TSUrlHostGet correctly, but we have an example plugin (redirect_1) which does not. As you said, the documentation is unclear about the behavior in the early hook scenarios.

Where I think we should go with this, if you are up for it:

  • Document TSHttpHdrUrlGet to clarify what parts of the URL are available at what hook
  • Fix the example plugin (probably to use TSHttpHdrHostGet)

It would be good for both the TSHttpHdrUrlGet and TSUrlHostGet docs to cross-reference TSHttpHdrHostGet.

…se TSHttpHdrHostGet

- TSHttpHdrUrlGet: add note that URL components may not be available at
  early hooks, recommend TSHttpHdrHostGet for reliable host retrieval
- TSUrlHostGet: add call condition note (TS_HTTP_POST_REMAP_HOOK onwards)
  and cross-reference to TSHttpHdrHostGet
- TSHttpHdrHostGet: add cross-references to TSHttpHdrUrlGet and TSUrlHostGet
- redirect_1: replace TSHttpHdrUrlGet+TSUrlHostGet with TSHttpHdrHostGet
  which works correctly at TS_HTTP_READ_REQUEST_HDR_HOOK
@JosiahWI

Copy link
Copy Markdown
Contributor

The docs build failed due to the following warnings:

/home/jenkins/workspace/Github_Builds/docs/src/doc/developer-guide/api/functions/TSHttpHdrHostGet.en.rst:48: WARNING: c:macro reference target not found: TS_HTTP_READ_REQUEST_HDR_HOOK [ref.macro]
/home/jenkins/workspace/Github_Builds/docs/src/doc/developer-guide/api/functions/TSHttpHdrUrlGet.en.rst:46: WARNING: c:macro reference target not found: TS_HTTP_READ_REQUEST_HDR_HOOK [ref.macro]
/home/jenkins/workspace/Github_Builds/docs/src/doc/developer-guide/api/functions/TSUrlHostGet.en.rst:76: WARNING: c:macro reference target not found: TS_HTTP_READ_REQUEST_HDR_HOOK [ref.macro]

@mmustafasenoglu

Copy link
Copy Markdown
Contributor Author

Hi @JosiahWI @bneradt,

I've fixed the docs build error by replacing all :c:macro:TS_HTTP_READ_REQUEST_HDR_HOOK references with double backticks (\`TS_HTTP_READ_REQUEST_HDR_HOOK``) in all three modified files:

  • TSHttpHdrHostGet.en.rst
  • TSHttpHdrUrlGet.en.rst
  • TSUrlHostGet.en.rst

This should resolve the c:macro reference target not found warning. Could you please trigger CI again?

Thank you!

@JosiahWI

Copy link
Copy Markdown
Contributor

There's a new docs warning:

/home/jenkins/workspace/Github_Builds/docs/src/doc/developer-guide/api/functions/index.en.rst:25: WARNING: toctree contains reference to document 'developer-guide/api/functions/TSHttpHdrHostGet.en' that doesn't have a title: no link will be generated [toc.no_title]

@JosiahWI

JosiahWI commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

It looks like TSHttpHdrHostGet.en.rst had its entire contents removed (this is also the reason the RAT license check failed).

You can run the formatter with the clang-format CMake target (or the broader format target). The only formatting issue is the missing newline at the end of the example plugin source file. The formatting targets should cover the example plugins, but I do not know for certain that we remembered that. :)

- Restored accidentally emptied TSHttpHdrHostGet.en.rst
- Added call condition note explaining TSHttpHdrHostGet vs TSUrlHostGet
- Added See Also cross-references to related APIs

Fixes docs build warning reported by JosiahWI
Copilot AI review requested due to automatic review settings July 2, 2026 07:42
@mmustafasenoglu

Copy link
Copy Markdown
Contributor Author

Hi @JosiahWI,

I've fixed the docs build issue. The TSHttpHdrHostGet.en.rst file had been accidentally emptied - I've restored the full content with:

  1. Original function documentation
  2. Added a call condition note explaining the difference between TSHttpHdrHostGet and TSUrlHostGet
  3. Added See Also cross-references to related APIs

The build warnings should now be resolved. Could you please re-trigger CI?

Thanks!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@JosiahWI JosiahWI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Changes look good! The only issue is the missing newline at the end of redirect_1.cc.

Comment thread example/plugins/c-api/redirect_1/redirect_1.cc Outdated
@mmustafasenoglu

Copy link
Copy Markdown
Contributor Author

Hi @JosiahWI, I've cleaned up the PR:

  • Restored upstream license header formatting in all files (was causing the Format CI failure)
  • Fixed the accidentally emptied TSHttpHdrHostGet.en.rst content
  • redirect_1.cc now uses only instead of +

The diff is now minimal — only the intended doc notes and the example plugin fix. Could you take another look? Thanks!

@JosiahWI JosiahWI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Everything looks good now. Thank you for working on this!

@cmcfarlen
cmcfarlen merged commit 16c434c into apache:master Jul 6, 2026
15 checks passed
cmcfarlen pushed a commit to cmcfarlen/trafficserver that referenced this pull request Jul 29, 2026
* docs: add call condition note for TSUrlHostGet

Add a note to the TSUrlHostGet documentation indicating that it should
only be called after TS_HTTP_POST_REMAP_HOOK. For earlier hooks like
TS_HTTP_READ_REQUEST_HDR_HOOK, TSHttpHdrHostGet should be used instead.

Fixes apache#5742

* docs: fix unknown interpreted text role data

Replace :data: with double backticks for hook names, consistent
with the rest of the documentation.

Fixes apache#5742

* docs: trigger CI for TSUrlHostGet call condition note

* docs: document TSHttpHdrUrlGet hook availability, fix redirect_1 to use TSHttpHdrHostGet

- TSHttpHdrUrlGet: add note that URL components may not be available at
  early hooks, recommend TSHttpHdrHostGet for reliable host retrieval
- TSUrlHostGet: add call condition note (TS_HTTP_POST_REMAP_HOOK onwards)
  and cross-reference to TSHttpHdrHostGet
- TSHttpHdrHostGet: add cross-references to TSHttpHdrUrlGet and TSUrlHostGet
- redirect_1: replace TSHttpHdrUrlGet+TSUrlHostGet with TSHttpHdrHostGet
  which works correctly at TS_HTTP_READ_REQUEST_HDR_HOOK

* fix(docs): replace :c:macro: with double backticks for TS_HTTP_READ_REQUEST_HDR_HOOK

* fix(docs): replace :c:macro: with double backticks for TS_HTTP_READ_REQUEST_HDR_HOOK

* fix(docs): replace :c:macro: with double backticks for TS_HTTP_READ_REQUEST_HDR_HOOK

* fix: restore TSHttpHdrHostGet docs content and add cross-references

- Restored accidentally emptied TSHttpHdrHostGet.en.rst
- Added call condition note explaining TSHttpHdrHostGet vs TSUrlHostGet
- Added See Also cross-references to related APIs

Fixes docs build warning reported by JosiahWI

* fix: add trailing newline to redirect_1.cc

* fix: restore upstream license header formatting

* fix: restore upstream license header formatting

* fix: restore upstream license header formatting

* fix: restore upstream license header in redirect_1.cc

* fix: restore license header and fix broken string literal

* fix: restore blank line after title underline

* fix: add blank line between title and Synopsis

* fix: apply code changes on top of upstream cleanly

* fix: restore redirect_1.cc with correct API changes

* fix: restore redirect_1.cc with correct TSHttpHdrHostGet usage

* fix: apply TSHttpHdrHostGet changes cleanly on upstream

* fix: restore blank line between title and Synopsis

---------

Co-authored-by: Mustafa Senoglu <mustafa@senoglu.local>
cmcfarlen pushed a commit to cmcfarlen/trafficserver that referenced this pull request Jul 29, 2026
* docs: add call condition note for TSUrlHostGet

Add a note to the TSUrlHostGet documentation indicating that it should
only be called after TS_HTTP_POST_REMAP_HOOK. For earlier hooks like
TS_HTTP_READ_REQUEST_HDR_HOOK, TSHttpHdrHostGet should be used instead.

Fixes apache#5742

* docs: fix unknown interpreted text role data

Replace :data: with double backticks for hook names, consistent
with the rest of the documentation.

Fixes apache#5742

* docs: trigger CI for TSUrlHostGet call condition note

* docs: document TSHttpHdrUrlGet hook availability, fix redirect_1 to use TSHttpHdrHostGet

- TSHttpHdrUrlGet: add note that URL components may not be available at
  early hooks, recommend TSHttpHdrHostGet for reliable host retrieval
- TSUrlHostGet: add call condition note (TS_HTTP_POST_REMAP_HOOK onwards)
  and cross-reference to TSHttpHdrHostGet
- TSHttpHdrHostGet: add cross-references to TSHttpHdrUrlGet and TSUrlHostGet
- redirect_1: replace TSHttpHdrUrlGet+TSUrlHostGet with TSHttpHdrHostGet
  which works correctly at TS_HTTP_READ_REQUEST_HDR_HOOK

* fix(docs): replace :c:macro: with double backticks for TS_HTTP_READ_REQUEST_HDR_HOOK

* fix(docs): replace :c:macro: with double backticks for TS_HTTP_READ_REQUEST_HDR_HOOK

* fix(docs): replace :c:macro: with double backticks for TS_HTTP_READ_REQUEST_HDR_HOOK

* fix: restore TSHttpHdrHostGet docs content and add cross-references

- Restored accidentally emptied TSHttpHdrHostGet.en.rst
- Added call condition note explaining TSHttpHdrHostGet vs TSUrlHostGet
- Added See Also cross-references to related APIs

Fixes docs build warning reported by JosiahWI

* fix: add trailing newline to redirect_1.cc

* fix: restore upstream license header formatting

* fix: restore upstream license header formatting

* fix: restore upstream license header formatting

* fix: restore upstream license header in redirect_1.cc

* fix: restore license header and fix broken string literal

* fix: restore blank line after title underline

* fix: add blank line between title and Synopsis

* fix: apply code changes on top of upstream cleanly

* fix: restore redirect_1.cc with correct API changes

* fix: restore redirect_1.cc with correct TSHttpHdrHostGet usage

* fix: apply TSHttpHdrHostGet changes cleanly on upstream

* fix: restore blank line between title and Synopsis

---------

Co-authored-by: Mustafa Senoglu <mustafa@senoglu.local>
(cherry picked from commit 16c434c)
@cmcfarlen cmcfarlen modified the milestones: 11.0.0, 10.2.0 Jul 29, 2026
@cmcfarlen cmcfarlen moved this to Picked v10.2.0 in ATS v10.2.x Jul 29, 2026
@github-project-automation github-project-automation Bot moved this from Picked v10.2.0 to For v10.2.0 in ATS v10.2.x Jul 29, 2026
@cmcfarlen cmcfarlen moved this from For v10.2.0 to Picked v10.2.0 in ATS v10.2.x Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Picked v10.2.0

Development

Successfully merging this pull request may close these issues.

Document how to obtain URL host correctly during early hooks

5 participants