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

Proxy mode does not send headers to server when fetching .js files #49

Closed
fujifish opened this issue Mar 3, 2013 · 4 comments
Closed
Assignees
Labels

Comments

@fujifish
Copy link

fujifish commented Mar 3, 2013

When running JSCover in proxy mode, and a .js file is requested, the ProxyService class does not send the original request headers to the actual server, causing behavior changes and some times complete failure, especially if the "Cookie" header is involved.

I've changed the ProxyService#getUrl method to send all of the original request headers, (except for the "Accept-Encoding" header) and everything worked perfectly after that.
here is the modified method:

public String getUrl(HttpRequest request) throws IOException {
        URL url = request.getUrl();
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        Map<String, List<String>> clientHeaders = request.getHeaders();
        if (clientHeaders != null) {
            for (String header : clientHeaders.keySet()) {
                if (header.equalsIgnoreCase("accept-encoding")) {
                    continue;
                }
                List<String> values = clientHeaders.get(header);
                for (String value : values) {
                    conn.addRequestProperty(header, value);
                }
            }
        }
        return ioUtils.toString(conn.getInputStream());
    }
@tntim96
Copy link
Owner

tntim96 commented Mar 3, 2013

Thanks. I'll just need to add a test to release. Also, why do you need to ignore the "Accept-Encoding" header?

@fujifish
Copy link
Author

fujifish commented Mar 4, 2013

The "Accept-Encoding" header specifies to the server what type of encodings the client is willing to accept. An encoding is the format in which the response content is delivered, such as gzip.
If the "Accept-Encoding" header in the original request would contain for example "gzip" and the ProxyService would pass that along to the server, then the server would most likely respond with a content that is encoded in gzip. In such a case JSCover would have to unzip the content in order to instrument the .js file.
I thought it would just be easier to avoid all types of encodings altogether and receive the content as plain text.

@tntim96
Copy link
Owner

tntim96 commented Mar 4, 2013

Makes sense - have committed and built release. PS - you're now added to the contributors list :)

@tntim96 tntim96 closed this as completed Mar 4, 2013
@fujifish
Copy link
Author

fujifish commented Mar 4, 2013

Great, Thanks!

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

No branches or pull requests

2 participants