mint icon indicating copy to clipboard operation
mint copied to clipboard

Access to Http response headers

Open nozzlegear opened this issue 4 years ago • 1 comments

Hello, I'm rewriting a small application in Mint and have found that there's no way (as far as I can tell) to access the Http response headers when using the built-in Http module. For my use case, I need to know the content type of the response so I can decide how to parse it.

I've run into this not just in my application but also when I'm using mint start during development; when I test my Http client requests, the Mint server will return 200 OK response to any request at any URL, and the response will contain the HTML from index.html. If the server always returns 200 OK and I have no way to access the content-type header, it seems I have no choice but to blindly attempt to decode it as several different formats until one succeeds.

Thanks for your work on Mint! I'm really enjoying it as an alternative to React.

nozzlegear avatar Sep 29 '21 20:09 nozzlegear

there's no way (as far as I can tell) to access the Http response headers when using the built-in Http module.

The headers are missing from the Http.Response and Http.ErrorResponse records, they can easily be added using the https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/getAllResponseHeaders method.

I've run into this not just in my application but also when I'm using mint start during development; when I test my Http client requests, the Mint server will return 200 OK response to any request at any URL, and the response will contain the HTML from index.html.

Yes, that's because Mint is used to create single page applications, and it needs that to work. In theory, we could use the defined routes to only serve the index.html to them.

If the server always returns 200 OK and I have no way to access the content-type header, it seems I have no choice but to blindly attempt to decode it as several different formats until one succeeds.

I think that's a good workaround however, in production you can configure your server (whatever that may be) to return a different status code.

Thanks for your work on Mint! I'm really enjoying it as an alternative to React.

That's great to hear :hugs:

gdotdesign avatar Oct 04 '21 06:10 gdotdesign