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

Header Location ist not set propertly #222

Open
daria-graf opened this issue Jul 17, 2023 · 3 comments
Open

Header Location ist not set propertly #222

daria-graf opened this issue Jul 17, 2023 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@daria-graf
Copy link

daria-graf commented Jul 17, 2023

Describe the bug
When I set a "location" property in response headers, then it is shown in Browser Chrome DevTools -> Network/Headers, but when I try to get response.headers.location in Code or just console.log repsonse.headers it returns only content.type and content-lenght property

To Reproduce
Here is my code to reproduce. I have tried to only set Location directly in after HTTP and in {{#code}} block. Both return the same result.

HTTP/1.1 201 CREATED
Location: /api/file/download/{{capture from='query' key='userId'}}
Access-Control-Allow-Origin: *

{{#code}}
(()=>{
        return {
            status:201,
            headers: {
            'Content-Type': 'text/html',
             'Location': '/api/file/download/{{capture from='query' key='userId'}}'
            }
        };
})();
{{/code}}

Expected behavior
When calling response.headers.location it should NOT be undefined

Desktop:

  • OS: MacOS 13.4
  • Node: v16.20
  • Browser Chrome Version 114.0.5735.198
  • camouflage-server: v 0.13.0
@daria-graf daria-graf added the bug Something isn't working label Jul 17, 2023
@shubhendumadhukar
Copy link
Contributor

You seem to be using a capture helper within the code helper. Unfortunately code helper isn't intended to work in that manner. When you use code helper, you must prepare the response yourself (read more here)

For your use case, you can modify your mock file as follows:

HTTP/1.1 201 CREATED
Access-Control-Allow-Origin: *

{{#code}}
(()=>{
        return {
            status:201,
            headers: {
            'Content-Type': 'text/html',
             'Location': `/api/file/download/${request.query.userId}`
            }
        };
})();

{{/code}}

It seems to work as expected.
Screenshot 2023-07-18 at 9 50 07 AM

@daria-graf
Copy link
Author

daria-graf commented Jul 23, 2023

@shubhendumadhukar thank you very much for your example, I just tried it. Unfortunately, I have the same problem, in Browser DevTools I can see the 'location' to set correctly, but in the app code, it still not there:
Bildschirmfoto 2023-07-23 um 18 52 27

To fetch data I am using axios. The code looks like:

 this.file
        .download()
        .then((response) => {
        console.log(response.headers)
        });

The location property seems NOT to work locally (when using the Mock server), in DEV/STAGE/PROD there are no issues with the code above.

@shubhendumadhukar
Copy link
Contributor

I am unfortunately unable to reproduce it. I tried calling the mock using the axios code as follows:

const axios = require("axios");

const options = {
  method: "GET",
  url: "http://localhost:8080/test",
  params: { userId: "1212" },
  headers: { "user-agent": "vscode-restclient" },
};

axios
  .request(options)
  .then(function (response) {
    console.log(response.headers);
  })
  .catch(function (error) {
    console.error(error);
  });

These are the headers I could see in the console.

AxiosHeaders {
  'x-powered-by': 'Express',
  vary: 'Origin, Accept-Encoding',
  'access-control-allow-origin': '*',
  'content-type': 'text/html; charset=utf-8',
  location: '/api/file/download/1212',
  date: 'Fri, 28 Jul 2023 05:33:15 GMT',
  connection: 'close',
  'transfer-encoding': 'chunked'
}

Would you be able to share the complete set of response headers you receive when you call the actual API instead of the mock? If yes, please ensure that sensitive data, if any, are masked from the response before sharing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: In Progress
Development

No branches or pull requests

2 participants