[PR #3242] [MERGED] refactor: move from network strategies to generic interceptor service #4298

Closed
opened 2026-03-17 01:50:50 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hoppscotch/hoppscotch/pull/3242
Author: @AndrewBastin
Created: 8/5/2023
Status: Merged
Merged: 8/21/2023
Merged by: @AndrewBastin

Base: release/2023.8.0Head: refactor/interceptor-service


📝 Commits (5)

  • 974a984 refactor: move from network strategies to generic interceptor service
  • eeee48a fix: currentInterceptorID cannot be set to null if there are interceptors
  • f870c57 chore: introduce tests for interceptor service
  • 9b969e4 feat: add ability for interceptors to subtitles on the selector
  • cc7f6cd chore: add comments to the new services

📊 Changes

33 files changed (+1468 additions, -1312 deletions)

View changed files

📝 packages/hoppscotch-common/locales/en.json (+1 -0)
📝 packages/hoppscotch-common/src/components.d.ts (+3 -0)
📝 packages/hoppscotch-common/src/components/app/Interceptor.vue (+26 -76)
📝 packages/hoppscotch-common/src/components/graphql/Request.vue (+5 -2)
📝 packages/hoppscotch-common/src/components/graphql/RequestOptions.vue (+5 -2)
📝 packages/hoppscotch-common/src/components/http/Request.vue (+14 -15)
packages/hoppscotch-common/src/components/interceptors/ExtensionSubtitle.vue (+39 -0)
packages/hoppscotch-common/src/components/settings/Extension.vue (+88 -0)
packages/hoppscotch-common/src/components/settings/Proxy.vue (+94 -0)
📝 packages/hoppscotch-common/src/helpers/GQLConnection.ts (+26 -7)
📝 packages/hoppscotch-common/src/helpers/RequestRunner.ts (+111 -88)
📝 packages/hoppscotch-common/src/helpers/network.ts (+71 -153)
packages/hoppscotch-common/src/helpers/strategies/AxiosStrategy.ts (+0 -163)
packages/hoppscotch-common/src/helpers/strategies/ExtensionStrategy.ts (+0 -128)
packages/hoppscotch-common/src/helpers/strategies/__tests__/AxiosStrategy-NoProxy.spec.js (+0 -76)
packages/hoppscotch-common/src/helpers/strategies/__tests__/AxiosStrategy-Proxy.spec.js (+0 -145)
packages/hoppscotch-common/src/helpers/strategies/__tests__/ExtensionStrategy-NoProxy.spec.js (+0 -212)
📝 packages/hoppscotch-common/src/helpers/types/HoppRESTResponse.ts (+1 -1)
packages/hoppscotch-common/src/modules/hoppExtension.ts (+0 -58)
packages/hoppscotch-common/src/modules/interceptors.ts (+46 -0)

...and 13 more files

📄 Description

Closes HFE-110

This PR intends to replace the Network Strategy system for implementing Interceptors with a generic Interceptor Service system. The new system intends to remove any 'special features' that the interceptors are provided and instead lets Hoppscotch Common codebase look at interceptors under a defined generic definition, with which, interceptor implementations are abstracted from the common codebase.

What's changed

  1. Introducing InterceptorService to which interceptors can be registered against and also keeps track of which is the currently selected interceptor.
  2. Changes to the Platform Definition where, platforms can add Interceptor objects or Interceptor interface implementing services as an argument in createHoppApp along with the ability to specify the default interceptor that should be activated.
  3. Interceptors are given the ability to be disabled (via the selectable field) and give the reason why they might not be selected.
  4. Replaced PROXY_ENABLED and EXTENSIONS_ENABLED field for CURRENT_INTERCEPTOR_ID field along with migrations on settings object for the same.
  5. Update analytics typing for HOPP_REQUEST_RUN to accept any arbitrary string for strategy field.
  6. Added interceptor definitions for Browser, Proxy and Extension and consolidated their related code (for example, extension has a HoppModule definition and similar bits) into the them.
  7. Update to createRESTNetworkStream and runRESTRequest$ along with similar functions on the network execution stack that we are working towards that.
  8. Updated settings page to use the Interceptor definition mechanism's ability to define custom Interceptor settings entry for each Interceptor as an optional feature. As part of this, the UI related to proxy and browser extension is removed from pages/settings into separate SettingsProxy and SettingsExtension components respectively.
  9. Updated request cancellation wiring to be independent and not global across all running requests. (NOTE: Although the new Interceptor Service and the requesting stack in general supports the individual cancellation mechanisms, some systems like extension doesn't play with it well and is universalised in cancellation as a half measure).

Checks

  • My pull request adheres to the code style of this project
  • My code requires changes to the documentation
  • I have updated the documentation as required
  • All the tests have passed

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/hoppscotch/hoppscotch/pull/3242 **Author:** [@AndrewBastin](https://github.com/AndrewBastin) **Created:** 8/5/2023 **Status:** ✅ Merged **Merged:** 8/21/2023 **Merged by:** [@AndrewBastin](https://github.com/AndrewBastin) **Base:** `release/2023.8.0` ← **Head:** `refactor/interceptor-service` --- ### 📝 Commits (5) - [`974a984`](https://github.com/hoppscotch/hoppscotch/commit/974a98490525e5fa03e8d0cd562f3c25d4ecac3f) refactor: move from network strategies to generic interceptor service - [`eeee48a`](https://github.com/hoppscotch/hoppscotch/commit/eeee48af9052734216e11eefbddd221a3d5e5da4) fix: currentInterceptorID cannot be set to null if there are interceptors - [`f870c57`](https://github.com/hoppscotch/hoppscotch/commit/f870c5714911fb40eaaa72f6f2155dd1befc0a9d) chore: introduce tests for interceptor service - [`9b969e4`](https://github.com/hoppscotch/hoppscotch/commit/9b969e4a4d8c329a0cc59c6c3761ae1741aac24e) feat: add ability for interceptors to subtitles on the selector - [`cc7f6cd`](https://github.com/hoppscotch/hoppscotch/commit/cc7f6cd479483ed6cd2c7a31cb90e8fff30a7407) chore: add comments to the new services ### 📊 Changes **33 files changed** (+1468 additions, -1312 deletions) <details> <summary>View changed files</summary> 📝 `packages/hoppscotch-common/locales/en.json` (+1 -0) 📝 `packages/hoppscotch-common/src/components.d.ts` (+3 -0) 📝 `packages/hoppscotch-common/src/components/app/Interceptor.vue` (+26 -76) 📝 `packages/hoppscotch-common/src/components/graphql/Request.vue` (+5 -2) 📝 `packages/hoppscotch-common/src/components/graphql/RequestOptions.vue` (+5 -2) 📝 `packages/hoppscotch-common/src/components/http/Request.vue` (+14 -15) ➕ `packages/hoppscotch-common/src/components/interceptors/ExtensionSubtitle.vue` (+39 -0) ➕ `packages/hoppscotch-common/src/components/settings/Extension.vue` (+88 -0) ➕ `packages/hoppscotch-common/src/components/settings/Proxy.vue` (+94 -0) 📝 `packages/hoppscotch-common/src/helpers/GQLConnection.ts` (+26 -7) 📝 `packages/hoppscotch-common/src/helpers/RequestRunner.ts` (+111 -88) 📝 `packages/hoppscotch-common/src/helpers/network.ts` (+71 -153) ➖ `packages/hoppscotch-common/src/helpers/strategies/AxiosStrategy.ts` (+0 -163) ➖ `packages/hoppscotch-common/src/helpers/strategies/ExtensionStrategy.ts` (+0 -128) ➖ `packages/hoppscotch-common/src/helpers/strategies/__tests__/AxiosStrategy-NoProxy.spec.js` (+0 -76) ➖ `packages/hoppscotch-common/src/helpers/strategies/__tests__/AxiosStrategy-Proxy.spec.js` (+0 -145) ➖ `packages/hoppscotch-common/src/helpers/strategies/__tests__/ExtensionStrategy-NoProxy.spec.js` (+0 -212) 📝 `packages/hoppscotch-common/src/helpers/types/HoppRESTResponse.ts` (+1 -1) ➖ `packages/hoppscotch-common/src/modules/hoppExtension.ts` (+0 -58) ➕ `packages/hoppscotch-common/src/modules/interceptors.ts` (+46 -0) _...and 13 more files_ </details> ### 📄 Description Closes HFE-110 This PR intends to replace the *Network Strategy* system for implementing Interceptors with a generic *Interceptor Service* system. The new system intends to remove any 'special features' that the interceptors are provided and instead lets Hoppscotch Common codebase look at interceptors under a defined generic definition, with which, interceptor implementations are abstracted from the common codebase. ### What's changed 1. Introducing `InterceptorService` to which interceptors can be registered against and also keeps track of which is the currently selected interceptor. 2. Changes to the Platform Definition where, platforms can add Interceptor objects or Interceptor interface implementing services as an argument in `createHoppApp` along with the ability to specify the default interceptor that should be activated. 3. Interceptors are given the ability to be `disabled` (via the `selectable` field) and give the reason why they might not be selected. 4. Replaced `PROXY_ENABLED` and `EXTENSIONS_ENABLED` field for `CURRENT_INTERCEPTOR_ID` field along with migrations on settings object for the same. 5. Update analytics typing for `HOPP_REQUEST_RUN` to accept any arbitrary string for `strategy` field. 6. Added interceptor definitions for Browser, Proxy and Extension and consolidated their related code (for example, extension has a `HoppModule` definition and similar bits) into the them. 7. Update to `createRESTNetworkStream` and `runRESTRequest$` along with similar functions on the network execution stack that we are working towards that. 8. Updated settings page to use the Interceptor definition mechanism's ability to define custom Interceptor settings entry for each Interceptor as an optional feature. As part of this, the UI related to proxy and browser extension is removed from `pages/settings` into separate `SettingsProxy` and `SettingsExtension` components respectively. 9. Updated request `cancellation` wiring to be independent and not global across all running requests. (NOTE: Although the new Interceptor Service and the requesting stack in general supports the individual cancellation mechanisms, some systems like extension doesn't play with it well and is universalised in cancellation as a half measure). ### Checks <!-- Make sure your pull request passes the CI checks and do check the following fields as needed - --> - [x] My pull request adheres to the code style of this project - [ ] My code requires changes to the documentation - [ ] I have updated the documentation as required - [ ] All the tests have passed --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-17 01:50:50 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hoppscotch#4298
No description provided.