Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

allow variables in the request protocol #30

Closed
wants to merge 1 commit into from

Conversation

mintbridge
Copy link

this allows variables e.g. {{protocol}} to be used in the request address, making switching between http and https in different environments easier for example, fixes #27

this allows variables e.g. {{protocol}} to be used in the request address, making switching between http and https in different environments easier for example, fixes grafana#27
@bookmoons
Copy link
Contributor

Thanks for the submission @mintbridge.

This doesn't quite seem to do it. It's replacing the URI#protocol method with a string, which seems to be ignored by the URI library.

const URI = require('urijs')
const address = new URI('example.com')
address.toString() // 'example.com'
address.protocol = 'ftp'
address.toString() // 'example.com'

I think in the case of an address starting with a variable that resolves at runtime without a protocol, this will leave it without a protocol.

@mintbridge
Copy link
Author

do you have an example?

@bookmoons
Copy link
Contributor

Here's a test case.

{
	"info": {
		"_postman_id": "58b9328f-6410-414b-a6c3-4c38bc618943",
		"name": "VariableStart",
		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
	},
	"item": [
		{
			"name": "TestRequest",
			"request": {
				"method": "GET",
				"header": [],
				"url": {
					"raw": "{{address}}",
					"host": [
						"{{address}}"
					]
				}
			},
			"response": []
		}
	],
	"variable": [
		{
			"id": "6ec78011-5d86-4e85-bdae-2fd71eeb478f",
			"key": "address",
			"value": "example.com",
			"type": "string"
		}
	]
}

The URL comes entirely from the address variable. The demonstration value is example.com, no protocol. Variable resolution happens at runtime. So you end up with an address with missing protocol.

Because it's not known until runtime whether the protocol is missing, there has to be some runtime parsing and manipulation of the URL.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for variables in protocol
2 participants