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

krakend looses gzip encoding header when using plugin #272

Closed
hotlib opened this issue Jan 27, 2021 · 3 comments
Closed

krakend looses gzip encoding header when using plugin #272

hotlib opened this issue Jan 27, 2021 · 3 comments

Comments

@hotlib
Copy link

hotlib commented Jan 27, 2021

Describe the bug

I am experiencing strange behaviour. My setup is:

client ---> KrakenD + plugin (http/client/executor) ----> backend

When I request a gzip-ed response via the request header:

Accept-Encoding: gzip

The response does not contain the needed header:

Content-Encoding: gzip

which instructs the client to decode the gzip. Instead the response contains the header:

Content-Type: application/x-gzip

The plugin does nothing but forward the request as-is without changes and copies the response back.
Among the copied response headers in the plugin I see:

Content-Encoding: gzip

so the plugin behaves correctly, but when the response is returned from KrakenD this needed header "Content-Encoding: gzip" is gone and is replaced with:

Content-Type: application/x-gzip

which is incorrect.

When I remove the plugin, KrakenD works and the needed header "Content-Encoding: gzip" is present.

Configuration

In the endpoint section I set:

"output_encoding": "no-op"

and in the backend section I set:

"encoding": "no-op"

and the backend service is responsible for setting the headers which it does correctly (i.e. "Content-Encoding: gzip" is present and the plugin copies this header to into the response). Unfortunately when the response leaves KrakenD the header "Content-Encoding: gzip" is no longer present and is replaced by the (incorrect) header "Content-Type: application/x-gzip"
I can even hard-code the response header "Content-Encoding: gzip" via krakend-martian and then it works fine (which of course is a bad solution)

plugin snippet

           response, err := http.DefaultClient.Do(req)

	   if err != nil {
	     fmt.Fprintf(os.Stderr, "ERROR: unable to connect to backend, error: %v \n", err)
	    w.WriteHeader(500)
	    return
	  }

	defer response.Body.Close()

	bytes, err := ioutil.ReadAll(response.Body)

	if err != nil {
		fmt.Fprintf(os.Stderr, "ERROR: unable to process response from backend, error: %v \n", err)
	}

	w.WriteHeader(response.StatusCode)
	bytesWritten, err := w.Write(bytes)

	if bytesWritten != len(bytes) || err != nil {
			fmt.Fprintf(os.Stderr, "ERROR: unable to read the response from backend, error: %v bytes from backend %d bytes written %d \n", err, len(bytes), bytesWritten)
		}

	for key, vals := range response.Header {
		for _, val := range vals {
			w.Header().Add(key, val)
		}
	}

Expected behavior

KrakenD should not replace the correct header:

Content-Encoding: gzip

with the incorrect header:

Content-Type: application/x-gzip

Workaround

So far I am using a workaround which turns off gzip for responses (this solution works), but is not optimal. The configuration for turning off gzip at the endpoint is:

  {
     "header.Modifier": {
     "scope": ["request"],
     "name": "Accept-Encoding",
     "value": "identity"
     }
 }
@github-actions
Copy link

This issue is marked as stale because it has been open over 90 days with no activity. Remove the stale label or comment or this will be closed in 15 days.

@github-actions
Copy link

Hi, thank you for bringing this issue to our attention.

Many factors influence our product roadmaps and determine the features, fixes, and suggestions we implement.
When deciding what to prioritize and work on, we combine your feedback and suggestions with insights from our development team, product analytics, research findings, and more.

This information, combined with our product vision, determines what we implement and its priority order. Unfortunately, we don't foresee this issue progressing any further in the short-medium term, and we are closing it.

While this issue is now closed, we continue monitoring requests for our future roadmap, including this one.

If you have additional information you would like to provide, please share.


This is an automated comment. Responding to the bot or mentioning it won't have any effect

@github-actions
Copy link

This issue was marked as resolved a long time ago and now has been automatically locked as there has not been any recent activity after it. You can still open a new issue and reference this link.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants