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

Fix header .Add functions #1036

Merged
merged 1 commit into from
Jun 1, 2021
Merged

Fix header .Add functions #1036

merged 1 commit into from
Jun 1, 2021

Conversation

erikdubbelboer
Copy link
Collaborator

@erikdubbelboer erikdubbelboer commented May 26, 2021

These functions should take the headers that are handled differently into account.

Fixes #1033

After this change it is not possible to have multiple
Content-Type, Content-Length, Connection, Server, Set-Cookie, Transfer-Encoding and Date headers. Having other headers multiple times is still fine. For these headers it should never happen anyways and I don't think we have any users who do this. But if they do it would break for then.

These functions should take the headers that are handled differently
into account.
@savsgio
Copy link
Contributor

savsgio commented May 28, 2021

LGTM!

@Fenny
Copy link
Contributor

Fenny commented Jun 1, 2021

Nice catch! Lgtm

@erikdubbelboer erikdubbelboer merged commit 6233fbc into master Jun 1, 2021
@erikdubbelboer erikdubbelboer deleted the fix-header-add branch June 1, 2021 08:52
@ReneWerner87
Copy link
Contributor

ReneWerner87 commented Jun 3, 2021

old code:

	case HeaderTransferEncoding:
		// Transfer-Encoding is managed automatically.
	case HeaderDate:
		// Date is managed automatically.
	default:
		h.h = setArgBytes(h.h, key, value, argsHasValue)

new code:

	case 't':
		if caseInsensitiveCompare(strTransferEncoding, key) {
			// Transfer-Encoding is managed automatically.
			return true
		}
		.....
	case 'd':
		if caseInsensitiveCompare(strDate, key) {
			// Date is managed automatically.
			return true
		}
	}
	
	....

@erikdubbelboer
i think there is a mistake here, the return value should be false, outside of that you break if you have the value true and don't set a header

and if we don't change the return value, we have to set it inside, because somewhere the header value should be set

also think you should rebuild the adjustment with the encoding in the adapter test, because exactly that would have shown you this error

if h.setSpecialHeader(key, value) {

if h.setSpecialHeader(key, value) {

i saw this, because of our tests
https://github.com/gofiber/adaptor/pull/66/checks?check_run_id=2734201815

we expect
https://github.com/gofiber/adaptor/blob/master/main_test.go#L29
https://github.com/gofiber/adaptor/blob/master/main_test.go#L66
https://github.com/gofiber/adaptor/blob/master/main_test.go#L110

@ReneWerner87
Copy link
Contributor

@erikdubbelboer

@erikdubbelboer
Copy link
Collaborator Author

To be honest I think your test is wrong. Transfer-Encoding can't just be set to something random like that. Transfer-Encoding control how the body is transferred between server and client which is something fasthttp controls itself. Otherwise you would be able to set Transfer-Encoding: chunked while fasthttp does an identity encoding and the whole thing fails.

@ReneWerner87
Copy link
Contributor

ok, thanks

then I will adjust our tests times, just wanted to be sure

you had that also in your tests and I thought it should be settable

thx

ReneWerner87 added a commit to gofiber/adaptor that referenced this pull request Jun 4, 2021
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.

1.25.0: fasthttpadaptor duplicate content-type with go stdlib embed
5 participants