Comments (18)
Add the "Access-Control-Expose-Headers" header to response from server. To read from javaScript "content-disposition" header add to response on server this Access-Control-Expose-Headers:Content-Disposition
. Then this code will work: response.headers.get('content-disposition')
from isomorphic-fetch.
At least I don't believe that this is an issue of isomorpic-fetch oder fetch either.
We use a rails api backend and solved the issue with this in a cors initializer:
# Be sure to restart your server when you modify this file.
# Avoid CORS issues when API is called from the frontend app.
# Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin AJAX requests.
# Read more: https://github.com/cyu/rack-cors
if Rails.env == 'development'
Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins 'localhost:10020'
resource '*',
headers: :any,
methods: [:get, :post, :put, :patch, :delete, :options, :head],
expose: [
'X-Total',
'X-Total-Pages',
'X-Page',
'X-Per-Page',
'X-Next-Page',
'X-Prev-Page',
'X-Offset',
'X-Rdb-Lang'
]
end
end
end
As you can see, we are exposing explicitly needed headers. And so should you with content-disposition.
Although this is a rails example. You should be able to expose the headers in JavaScript also.
Hope this helps someone.
from isomorphic-fetch.
In C# you could do so by writing:
result.Content.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition");
At least it worked for me finally.
from isomorphic-fetch.
@malagant you're right! Even if the headers show in Chrome devtools they're not necessarily included in a CORS response. I explicitly exposed the Content-Disposition header server side and all worked. Cheers cheers!
from isomorphic-fetch.
I did set the response header mentioned by @Cherepanov6 in Express NodeJS with the below code.
res.setHeader('Access-Control-Expose-Headers','Content-Disposition');
Thanks @Cherepanov6 !
from isomorphic-fetch.
I have same issue, can see 'X-Total-Count' in Chrome devtool, but there is no such key in fetch's response headers.
from isomorphic-fetch.
If you are using django, you would add this to settings file:
CORS_EXPOSE_HEADERS =[
'content-disposition',
]
from isomorphic-fetch.
Since this is an issue with the browser side implementation (https://github.com/github/fetch) of this package, doesn't this issue belong there?
Also, i think my problems are probably caused by some missing CORS settings:
JakeChampion/fetch#399
from isomorphic-fetch.
Add the "Access-Control-Expose-Headers" header to response from server. To read from javaScript "content-disposition" header add to response on server this
Access-Control-Expose-Headers:Content-Disposition
. Then this code will work:response.headers.get('content-disposition')
thank you, You saved my day.
from isomorphic-fetch.
We are experiencing a similar issue. The response object coming back from fetch is missing headers besides content-type. In our case we are looking for X-Vcap-Request-Id.
we're able to see a number of headers in the network tab of chrome's devtools, but the only one that is available via the headers through this lib is response.headers.get('content-type')
from isomorphic-fetch.
Any news on this? I have the very same problem and I am getting nervous. ;)
from isomorphic-fetch.
I'm having a similar problem: the only headers i can see are: 'cache-control', 'content-type' and 'expires'.
I can see more headers in chrome devtools, too. And i really need to read those hawk headers...
from isomorphic-fetch.
Me too. Seeing the Content-Disposition header in Chrome devtools but response.headers.get('content-disposition') is null :s
from isomorphic-fetch.
Using isomorphic-fetch in Node/Express to request images from third party API (thus can't control certain CORs settings). Is there a way to get a full set of headers from Fetch/third party API? Using Node Request exposes all headers, Fetch does not.
Only headers returned in Fetch are:
cache-control
expires
content-type
content-length
from isomorphic-fetch.
No resolution to this yet?! :(
from isomorphic-fetch.
In C# you could do so by writing:
result.Content.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition");
At least it worked for me finally.
Step 1: first just check Content-Disposition in header response
step 2 : .WithExposedHeaders("Content-Disposition") as this in cors access or startup.cs class in a case of Asp.net core
Step 3 : ( blob).name = this.getResponseHeader('content-disposition').match(/filename=(.+);/)[1].replace(/(^")|("$)/g, '');
from isomorphic-fetch.
(file gets saved in binary format in the browser. the filename is in the client's Network/header/Content-Disposition, we need to fetch the filename)
In Server-side code:
node js code-
response.setHeader('Access-Control-Expose-Headers','Content-Disposition');
response.download(outputpath,fileName);
In client-side code:
1)appComponent.ts file
import { HttpHeaders } from '@angular/common/http';
this.reportscomponentservice.getReportsDownload(this.myArr).subscribe((event: any) => {
var contentDispositionData= event.headers.get('content-disposition');
let filename = contentDispositionData.split(";")[1].split("=")[1].split('"')[1].trim()
saveAs(event.body, filename);
});
2) service.ts file
import { HttpClient, HttpResponse } from '@angular/common/http';
getReportsDownload(myArr): Observable<HttpResponse> {
console.log('Service Page', myArr);
return this.http.post(PowerSimEndPoints.GET_DOWNLOAD_DATA.PROD, myArr, {
observe: 'response',
responseType: 'blob'
});
}
from isomorphic-fetch.
Does anybody know how to expose "Content-Disposition" header in Next-js. I tried editing the next.config.js file according to this article but with no luck.
/** @type {import('next').NextConfig} */
module.exports = {
reactStrictMode: true,
typescript: {
ignoreBuildErrors: true,
},
async headers() {
const securityHeaders = [
{
key: 'X-Content-Type-Options',
value: 'nosniff'
},
// here
{ key: "Access-Control-Expose-Headers", value: "Content-Disposition" },
]
return [
{
source: '/:path*', // req path
headers: securityHeaders
}
]
}
}
from isomorphic-fetch.
Related Issues (20)
- Upgrade node-fetch to >= 2.3.0 to fix semantic-release users that use styled-components HOT 2
- Fix version of whatwg-fetch HOT 1
- eiddccgeilvtdejdrvblujinlecirnvcbbnnnunegklr
- AbortController not working with this library HOT 4
- URLSearchParams in body doesn't set content-type to x-www-form-urlencoded
- Is this library still been maintained? HOT 4
- Tag a new version with the security fix HOT 11
- Add v3.0.0 release notes HOT 2
- How to handle error messages from server - Question HOT 1
- Node.js - realFetch.call is not a function HOT 8
- Isomorphic-fetch Typescript setup HOT 2
- Upgrade node-fetch to version 2.6.1 or 3.0.0-beta.9 HOT 1
- fetch api
- update node-fetch to v3.x HOT 7
- Security risk
- Found a possible security concern HOT 2
- Interceptors
- How to access the referer using isomorphic fetch library? An example would help!
- Dual Form
- Isomorphic fetch returns response with empty stream body HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from isomorphic-fetch.