Skip to content

Conversation

@ywkaras
Copy link
Contributor

@ywkaras ywkaras commented Jul 16, 2024

Also includes new Au test coverage.

@ywkaras ywkaras self-assigned this Jul 16, 2024
@ywkaras ywkaras added header_rewrite header_rewrite plugin Cleanup labels Jul 16, 2024
@ywkaras ywkaras added this to the 10.0.1 milestone Jul 16, 2024
@ywkaras ywkaras linked an issue Jul 16, 2024 that may be closed by this pull request
@ywkaras ywkaras modified the milestones: 10.0.1, 10.1.0 Jul 16, 2024
@ywkaras ywkaras marked this pull request as draft July 22, 2024 16:01
@ywkaras ywkaras force-pushed the header_rewrite_redirect branch from 047630b to 3a2fd2f Compare July 22, 2024 21:23
{
add_allowed_hook(TS_HTTP_READ_RESPONSE_HDR_HOOK);
add_allowed_hook(TS_HTTP_SEND_RESPONSE_HDR_HOOK);
add_allowed_hook(TS_REMAP_PSEUDO_HOOK);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are the only 3 hooks on which this operator actually works currently. (By default, without a hook condition, operators execute on the READ_RESPONSE hook.)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you need to update the documentation?

@ywkaras ywkaras marked this pull request as ready for review July 22, 2024 21:57

ts.Disk.plugin_config.AddLine(f'header_rewrite.so {Test.RunDirectory}/glob_set_redirect.conf')

tr = Test.AddTestRun()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe add a comment saying what each test is checking

TSHttpTxnErrorBodySet(txnp, TSstrdup(msg.c_str()), msg.length(), TSstrdup("text/html"));
}

static int
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's no longer used.

tr.StillRunningAfter = ts
ts.Disk.traffic_out.Content = "gold/header_rewrite-tag.gold"

tr = Test.AddTestRun()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are both test cases the same?
Add a test case for if the redirect fails?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes they are the same but meet different ID:REQUEST conditions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don' t understand. You mean set proxy.config.http.number_of_redirections to non-zero?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I mean when the redirect returns an error code. Checking what the plugin does.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The plugin doesn't do the redirect. If the configured number of redirections is 0 (the default), the client is expected to do redirect to the URL in the response Location header. If redirections is greater than 0, maybe core ATS would do the redirection, but I'm not sure.

{
add_allowed_hook(TS_HTTP_READ_RESPONSE_HDR_HOOK);
add_allowed_hook(TS_HTTP_SEND_RESPONSE_HDR_HOOK);
add_allowed_hook(TS_REMAP_PSEUDO_HOOK);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you need to update the documentation?

@ywkaras ywkaras force-pushed the header_rewrite_redirect branch from 3a2fd2f to c47343d Compare July 31, 2024 01:36
@ywkaras ywkaras force-pushed the header_rewrite_redirect branch from c47343d to afeb0dd Compare July 31, 2024 14:56
const_cast<Resources &>(res).changed_url = true;
res._rri->redirect = 1;
} else {
Dbg(pi_dbg_ctl, "OperatorSetRedirect::exec() hook=%d", int(get_hook()));
Copy link
Collaborator

Choose a reason for hiding this comment

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

is logging the int meaningful? Would it be more readable to have the string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't have any trouble figuring it out, from looking at the code:

#define DERIVE_HOOK_VALUE_FROM_EVENT(COMMON) TS_HTTP_##COMMON##_HOOK = TS_EVENT_HTTP_##COMMON - TS_EVENT_HTTP_READ_REQUEST_HDR

@ywkaras ywkaras merged commit 94dfd0e into apache:master Aug 5, 2024
masaori335 pushed a commit to masaori335/trafficserver that referenced this pull request Dec 10, 2024
* Revert "Update set-custom-body response body to exclude headers (apache#780)"

This reverts commit cb552b6.

* Revert "Add set-body-custom to header_rewrite options"

This reverts commit 5bd9999.

* Add set-custom-body config item to header_rewrite (apache#11472)

* Add set-body-custom to header_rewrite options

(cherry picked from commit 5bd9999)
(cherry picked from commit 08c614ef0089b175a5b6cee205b748416efb87cd)

* Update set-custom-body response body to exclude headers (apache#780)

* Update response body to exclude headers

* Update tests to check both response with headers and response body only

* Update header_rewrite_custom_body.test.py

* Fix tests to check headers and body

(cherry picked from commit cb552b6)
(cherry picked from commit e12f4798d0d46bd90c810f8f3a7a067ea3b2c76f)

* Remove debug check due to known issue

(cherry picked from commit 964b12cc21a9a7c3f9d3fd50286e4cd2d2757bcc)

* Fix formatting

Remove whitespaces

doc formatting fix

Doc formatting fix

* Rename to set-body-from

* Add test for failed second call

* Add more test cases

* Clarify test cases

* Update tests

* Update header_rewrite.en.rst

* Fix flakey test

---------

Co-authored-by: Jasmine Emanouel <jemanouel@apple.com>
(cherry picked from commit 0d8a6ac)

* header_rewrite: Allow Txn reenable to be deferred. (apache#11658)

The SetBodyFrom operator needs to defer calling Txn reenable
until the fetch of the URL providing the response body
completes.

(cherry picked from commit 50f5f23)

* cherry-pick cleanup

* cherry-pick cleanup

* Cleanup of header_rewrite redirect operator when invoked globally. (apache#11551)

Also includes new Au test coverage.

(cherry picked from commit 94dfd0e)

* fix return value

---------

Co-authored-by: Jasmine Emanouel <40879549+jasmine-nahrain@users.noreply.github.com>
Co-authored-by: Walt Karas <wkaras@yahooinc.com>
masaori335 pushed a commit to masaori335/trafficserver that referenced this pull request May 29, 2025
* Add set-custom-body config item to header_rewrite (apache#11472)

* Add set-body-custom to header_rewrite options

(cherry picked from commit 5bd9999)
(cherry picked from commit 08c614ef0089b175a5b6cee205b748416efb87cd)

* Update set-custom-body response body to exclude headers (apache#780)

* Update response body to exclude headers

* Update tests to check both response with headers and response body only

* Update header_rewrite_custom_body.test.py

* Fix tests to check headers and body

(cherry picked from commit cb552b6)
(cherry picked from commit e12f4798d0d46bd90c810f8f3a7a067ea3b2c76f)

* Remove debug check due to known issue

(cherry picked from commit 964b12cc21a9a7c3f9d3fd50286e4cd2d2757bcc)

* Fix formatting

Remove whitespaces

doc formatting fix

Doc formatting fix

* Rename to set-body-from

* Add test for failed second call

* Add more test cases

* Clarify test cases

* Update tests

* Update header_rewrite.en.rst

* Fix flakey test

---------

Co-authored-by: Jasmine Emanouel <jemanouel@apple.com>
(cherry picked from commit 0d8a6ac)

* Cleanup of header_rewrite redirect operator when invoked globally. (apache#11551)

Also includes new Au test coverage.

(cherry picked from commit 94dfd0e)

* header_rewrite: Allow Txn reenable to be deferred. (apache#11658)

The SetBodyFrom operator needs to defer calling Txn reenable
until the fetch of the URL providing the response body
completes.

(cherry picked from commit 50f5f23)

---------

Co-authored-by: Jasmine Emanouel <40879549+jasmine-nahrain@users.noreply.github.com>
Co-authored-by: Walt Karas <wkaras@yahooinc.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Cleanup header_rewrite header_rewrite plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dubiously correct code in header_rewrite plugin.

3 participants