Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: generate "X-Request-ID" header #801

Merged
merged 1 commit into from
Oct 30, 2023

Conversation

DudaGod
Copy link
Member

@DudaGod DudaGod commented Oct 23, 2023

BREAKING CHANGE: "headers" in the config are now an object with a "X-Request-ID" by default

@@ -169,6 +169,7 @@ module.exports = class ExistingBrowser extends Browser {
return {
pid: process.pid,
browserVersion: this.version,
"X-Request-Id": this._config.headers["X-Request-Id"],
Copy link
Member Author

Choose a reason for hiding this comment

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

Докидываю инфу в мету

parseEnv: JSON.parse,
parseCli: JSON.parse,
defaultValue: defaultFactory("headers"),
validate: value => utils.assertObject(value, "headers"),
Copy link
Member Author

Choose a reason for hiding this comment

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

Теперь только object. null юзать нельзя

parseCli: JSON.parse,
defaultValue: defaultFactory("headers"),
validate: value => utils.assertObject(value, "headers"),
map: value => (value["X-Request-Id"] ? value : { "X-Request-Id": uuid.v4(), ...value }),
Copy link
Member Author

Choose a reason for hiding this comment

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

Если пользователь выставил X-Request-Id, то свой не генерю.

Так же тут id-шник генерится и для воркеров и для мастер. Но у нас есть синхронизация конфигов и в итоге все запросы в selenoid/selenium/etc будут лететь с id от мастера. Генерация id занимает около 20мс.

Можно было бы немного упороться и прокидывать сгенеренный id в мастере во все воркеры. Но получилось бы довольно сложный код. Поэтому решил оставить так.

Copy link
Member

Choose a reason for hiding this comment

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

а если пользователь укажет 'x-request-id'? нужно этот вариант тоже обработать

Copy link
Member Author

Choose a reason for hiding this comment

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

а если пользователь укажет 'x-request-id'? нужно этот вариант тоже обработать

Так я же выше написал - "Если пользователь выставил X-Request-Id, то свой не генерю." Т.е. этот кейс я учел.

Copy link
Member Author

Choose a reason for hiding this comment

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

Обсудили в чате. Переименовал X-Request-Id в X-Request-ID, так как в спецификации именно так этот хедер называется.
Если пользователь добавит x-request-id или еще какую-то вариацию, то этот хедер полетит as is в запросе. Т.е. переопределить можно только если явно указать X-Request-ID.

assert.deepEqual(config.browsers.b1[option], { k1: "v1", k2: "v2" });
assert.typeOf(config.browsers.b1.headers["X-Request-Id"], "string");
assert.isAbove(config.browsers.b1.headers["X-Request-Id"].length, 20);
assert.equal(config.browsers.b1.headers.k1, "v1");
Copy link
Member Author

Choose a reason for hiding this comment

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

Тут используя sinon@4 невозможно застабать uuid.v4, так как это геттер. Нашел issue, что проблему починили в 15 версии. Но обновлять ее в рамках этого же PR не буду. Скорей всего куча тестов сломается.

Пробовал застабать и через proxyquire, но чтобы до этого uuid дотянутся из конфига нужно где-то тройную вложенность proxyquire написать. В итоге пока решил просто на длину проверять и наличие опции в хедере.

@DudaGod DudaGod force-pushed the HERMIONE-1228.add_x_req_id_header branch from f8305fe to 968d2f6 Compare October 30, 2023 12:08
@DudaGod DudaGod changed the title feat: generate "X-Request-Id" header feat: generate "X-Request-ID" header Oct 30, 2023
@DudaGod DudaGod force-pushed the HERMIONE-1228.add_x_req_id_header branch from 968d2f6 to df02533 Compare October 30, 2023 12:38
BREAKING CHANGE: "headers" in the config are now an object with a "X-Request-ID" by default
@DudaGod DudaGod force-pushed the HERMIONE-1228.add_x_req_id_header branch from df02533 to 35df5cc Compare October 30, 2023 13:06
@DudaGod DudaGod merged commit 0b78178 into master Oct 30, 2023
2 checks passed
@DudaGod DudaGod deleted the HERMIONE-1228.add_x_req_id_header branch October 30, 2023 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants