[PR #4242] [MERGED] fix: ensure Content-Type header priority in the CLI #4721

Closed
opened 2026-03-17 02:14:02 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hoppscotch/hoppscotch/pull/4242
Author: @jamesgeorge007
Created: 8/6/2024
Status: Merged
Merged: 8/7/2024
Merged by: @jamesgeorge007

Base: patchHead: fix/cli-content-type-header-priority


📝 Commits (1)

  • d1f88e4 fix: ensure Content-Type header priority in the CLI

📊 Changes

11 files changed (+290 additions, -32 deletions)

View changed files

📝 packages/hoppscotch-cli/package.json (+1 -1)
📝 packages/hoppscotch-cli/src/__tests__/e2e/commands/test.spec.ts (+10 -0)
packages/hoppscotch-cli/src/__tests__/e2e/fixtures/collections/content-type-header-scenarios.json (+171 -0)
📝 packages/hoppscotch-cli/src/__tests__/unit/fixtures/workspace-access.mock.ts (+3 -3)
📝 packages/hoppscotch-cli/src/utils/pre-request.ts (+8 -2)
📝 packages/hoppscotch-cli/src/utils/request.ts (+17 -9)
📝 packages/hoppscotch-common/src/helpers/utils/contenttypes.ts (+2 -0)
📝 packages/hoppscotch-common/src/services/persistence/__tests__/__mocks__/index.ts (+8 -4)
📝 packages/hoppscotch-data/src/rest/content-types.ts (+4 -1)
📝 packages/hoppscotch-data/src/rest/index.ts (+17 -12)
packages/hoppscotch-data/src/rest/v/6.ts (+49 -0)

📄 Description

Description

The Content-Type header set takes priority over the value set at the request body in the app. However, this wasn't the behaviour in the CLI the respective header was set to the value specified in the request body. This PR aims to resolve this behaviour and ensure consistency between the app and the CLI.

Additionally, text/xml is added to the list of supported content types. It's now available to choose from the list of content types under the request body from the UI. The CLI will now recognise a collection export with a POST request having a content type set to the same.

image

Closes HFE-555, #4220 #4101

What's changed

  • Prevent adding a Content-Header header entry based on the content type set at the request body always and instead perform it conditionally accounting for a pre-existing header.
  • Relevant test case addition for the behaviour change with the respective collection entry under fixtures. Requests demonstrating various scenarios are added under the test fixture collection. For instance, the last occurrence is picked among multiple Content-Type header entries.
  • Bump CLI version to v0.10.2.
  • Resolve a few type errors.
  • Adds text/xml to the list of supported content types. It is added under the Text category similar to application/xml since it is focused more on structured data and used in data processing.
  • Introduces HoppRESTRequest schema v6 with text/xml added under the supported content types. HoppRESTReqBody is exported from the v6 schema instead of the v1 variant.

Note to reviewers

The collection added under e2e test fixtures can be used to test against while verifying the behaviour.


🔄 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/4242 **Author:** [@jamesgeorge007](https://github.com/jamesgeorge007) **Created:** 8/6/2024 **Status:** ✅ Merged **Merged:** 8/7/2024 **Merged by:** [@jamesgeorge007](https://github.com/jamesgeorge007) **Base:** `patch` ← **Head:** `fix/cli-content-type-header-priority` --- ### 📝 Commits (1) - [`d1f88e4`](https://github.com/hoppscotch/hoppscotch/commit/d1f88e49f5dc3029950462d44d19c45650caabd2) fix: ensure `Content-Type` header priority in the CLI ### 📊 Changes **11 files changed** (+290 additions, -32 deletions) <details> <summary>View changed files</summary> 📝 `packages/hoppscotch-cli/package.json` (+1 -1) 📝 `packages/hoppscotch-cli/src/__tests__/e2e/commands/test.spec.ts` (+10 -0) ➕ `packages/hoppscotch-cli/src/__tests__/e2e/fixtures/collections/content-type-header-scenarios.json` (+171 -0) 📝 `packages/hoppscotch-cli/src/__tests__/unit/fixtures/workspace-access.mock.ts` (+3 -3) 📝 `packages/hoppscotch-cli/src/utils/pre-request.ts` (+8 -2) 📝 `packages/hoppscotch-cli/src/utils/request.ts` (+17 -9) 📝 `packages/hoppscotch-common/src/helpers/utils/contenttypes.ts` (+2 -0) 📝 `packages/hoppscotch-common/src/services/persistence/__tests__/__mocks__/index.ts` (+8 -4) 📝 `packages/hoppscotch-data/src/rest/content-types.ts` (+4 -1) 📝 `packages/hoppscotch-data/src/rest/index.ts` (+17 -12) ➕ `packages/hoppscotch-data/src/rest/v/6.ts` (+49 -0) </details> ### 📄 Description ### Description The `Content-Type` header set takes priority over the value set at the request body in the app. However, this wasn't the behaviour in the CLI the respective header was set to the value specified in the request body. This PR aims to resolve this behaviour and ensure consistency between the app and the CLI. Additionally, `text/xml` is added to the list of supported content types. It's now available to choose from the list of content types under the request body from the UI. The CLI will now recognise a collection export with a `POST` request having a content type set to the same. <img width="300" alt="image" src="https://github.com/user-attachments/assets/2d923381-b446-4d0a-a9c4-9f1726816bf5"> Closes HFE-555, #4220 #4101 ### What's changed - Prevent adding a `Content-Header` header entry based on the content type set at the request body always and instead perform it conditionally accounting for a pre-existing header. - Relevant test case addition for the behaviour change with the respective collection entry under fixtures. Requests demonstrating various scenarios are added under the test fixture collection. For instance, the last occurrence is picked among multiple `Content-Type` header entries. - Bump CLI version to `v0.10.2`. - Resolve a few type errors. - Adds `text/xml` to the list of supported content types. It is added under the `Text` category similar to `application/xml` since it is focused more on structured data and used in data processing. - Introduces `HoppRESTRequest` schema `v6` with `text/xml` added under the supported content types. `HoppRESTReqBody` is exported from the `v6` schema instead of the `v1` variant. ### Note to reviewers The [collection](https://github.com/hoppscotch/hoppscotch/pull/4242/files#diff-c25f6d85c20f60f581b87b75705fb3a5bf632f8793fdbe7cef144c65cc1a6a41) added under e2e test fixtures can be used to test against while verifying the behaviour. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-17 02:14:02 +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#4721
No description provided.