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

Add Align to align HTTP headers #25

Merged
merged 1 commit into from
Sep 19, 2024
Merged

Add Align to align HTTP headers #25

merged 1 commit into from
Sep 19, 2024

Conversation

arp242
Copy link
Contributor

@arp242 arp242 commented Sep 19, 2024

IMHO this makes stuff rather more readable/scannable. Some people may not like it, so I added it as an option.

Will automatically align to the longest header; I modified the sortHeaderKeys() so we don't need to do an extra loop for it.

Also pass the Host header to printHeaders() so it's aligned too. Do some special-fu to make sure it still prints as the first.

Before;

* Request at 2024-09-19 15:19:15.459694244 +0100 IST m=+1.001660288
* Request to http://localhost:8081/api/3/ping
> GET /api/3/ping HTTP/1.1
> Host: localhost:8081
> Accept: application/json; charset=utf-8
> Authorization: ApiKey ████████████████████
> Content-Type: application/json; charset=utf-8
> User-Agent: alfred/

< HTTP/1.1 200 OK
< Cache-Control: no-store,no-cache
< Content-Length: 88
< Content-Security-Policy: default-src 'self'; img-src 'self' blob: data:;
< Content-Type: application/json; charset=utf-8
< Date: Thu, 19 Sep 2024 14:19:15 GMT
< Referrer-Policy: same-origin
< X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
< X-Powered-By: Alfred
< X-Xss-Protection: 1; mode=block

{
	"ftm_version": "3.7.0",
	"role": 4,
	"title": "Alfred",
	"version": "d67f396b"
}

* Request took 9.251101ms

After:

* Request at 2024-09-19 15:18:45.255328802 +0100 IST m=+1.001249794
* Request to http://localhost:8081/api/3/ping
> GET /api/3/ping HTTP/1.1
> Host:          localhost:8081
> Accept:        application/json; charset=utf-8
> Authorization: ApiKey ████████████████████
> Content-Type:  application/json; charset=utf-8
> User-Agent:    alfred/

< HTTP/1.1 200 OK
< Cache-Control:           no-store,no-cache
< Content-Length:          88
< Content-Security-Policy: default-src 'self'; img-src 'self' blob: data:;
< Content-Type:            application/json; charset=utf-8
< Date:                    Thu, 19 Sep 2024 14:18:45 GMT
< Referrer-Policy:         same-origin
< X-Content-Type-Options:  nosniff
< X-Frame-Options:         SAMEORIGIN
< X-Powered-By:            Alfred
< X-Xss-Protection:        1; mode=block

{
	"ftm_version": "3.7.0",
	"role": 4,
	"title": "Alfred",
	"version": "d67f396b"
}

* Request took 9.251101ms

IMHO this makes stuff rather more readable/scannable. Some people may
not like it, so I added it as an option.

Will automatically align to the longest header; I modified the
sortHeaderKeys() so we don't need to do an extra loop for it.

Also pass the Host header to printHeaders() so it's aligned too. Do some
special-fu to make sure it still prints as the first.

Before;

	* Request at 2024-09-19 15:19:15.459694244 +0100 IST m=+1.001660288
	* Request to http://localhost:8081/api/3/ping
	> GET /api/3/ping HTTP/1.1
	> Host: localhost:8081
	> Accept: application/json; charset=utf-8
	> Authorization: ApiKey ████████████████████
	> Content-Type: application/json; charset=utf-8
	> User-Agent: alfred/

	< HTTP/1.1 200 OK
	< Cache-Control: no-store,no-cache
	< Content-Length: 88
	< Content-Security-Policy: default-src 'self'; img-src 'self' blob: data:;
	< Content-Type: application/json; charset=utf-8
	< Date: Thu, 19 Sep 2024 14:19:15 GMT
	< Referrer-Policy: same-origin
	< X-Content-Type-Options: nosniff
	< X-Frame-Options: SAMEORIGIN
	< X-Powered-By: Alfred
	< X-Xss-Protection: 1; mode=block

	{
		"ftm_version": "3.7.0",
		"role": 4,
		"title": "Alfred",
		"version": "d67f396b"
	}

	* Request took 9.251101ms

After:

	* Request at 2024-09-19 15:18:45.255328802 +0100 IST m=+1.001249794
	* Request to http://localhost:8081/api/3/ping
	> GET /api/3/ping HTTP/1.1
	> Host:          localhost:8081
	> Accept:        application/json; charset=utf-8
	> Authorization: ApiKey ████████████████████
	> Content-Type:  application/json; charset=utf-8
	> User-Agent:    alfred/

	< HTTP/1.1 200 OK
	< Cache-Control:           no-store,no-cache
	< Content-Length:          88
	< Content-Security-Policy: default-src 'self'; img-src 'self' blob: data:;
	< Content-Type:            application/json; charset=utf-8
	< Date:                    Thu, 19 Sep 2024 14:18:45 GMT
	< Referrer-Policy:         same-origin
	< X-Content-Type-Options:  nosniff
	< X-Frame-Options:         SAMEORIGIN
	< X-Powered-By:            Alfred
	< X-Xss-Protection:        1; mode=block

	{
		"ftm_version": "3.7.0",
		"role": 4,
		"title": "Alfred",
		"version": "d67f396b"
	}

	* Request took 9.251101ms
@henvic henvic merged commit 962ad53 into henvic:main Sep 19, 2024
10 checks passed
@arp242 arp242 deleted the align branch September 19, 2024 18:17
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.

2 participants