Comments (7)
Hey so I ran into this same issue. Conveniently enough the apollo-datasource-rest
uses node-fetch
under the hood, which actually has the ability to grab the all the headers of a specific key and return them as a string[]
.
Apollo doesn't have the method typed so you'll have to augment the types or cast it to any.
This worked for me:
response.headers.raw()['set-cookie']
from datasource-rest.
Hi, this is more about servers in general right?
Im doing the following in our http middleware proxy in some totally other server code but i think it should help you looking how to proceed. And its simple :)
const SetCookies = response.headers.get("set-cookie")
if (SetCookies) {
response.setHeader("set-cookie", Array.isArray(SetCookies) ? cookies : SetCookies.split(','));
}
from datasource-rest.
this is unpredictable as cookie value may contain ,
edit: not cookie value, I mean the set-cookie header might contain ,
from datasource-rest.
from datasource-rest.
Read a little bit further and you'll see there's expires=DATE where date contains a comma... so couple cookies joined with a , having optional expire value will case a problem
NAME=VALUE
This string is a sequence of characters excluding semi-colon, comma and white space. If there is a need to place such data in the name or value, some encoding method such as URL style %XX encoding is recommended, though no encoding is defined or required.
This is the only required attribute on the Set-Cookie header.
expires=DATE
The expires attribute specifies a date string that defines the valid life time of that cookie. Once the expiration date has been reached, the cookie will no longer be stored or given out.
The date string is formatted as:
Wdy, DD-Mon-YYYY HH:MM:SS GMT
Of course it can be solved by some regex matching etc.
from datasource-rest.
Ah oke now you edit :) that makes my response weird indeed :)
Hi Afzal, i will debug for you, since i have the code in production :) Internally i have:
Fri%2C%2029%20Jan%202021%2020%3A15%3A48%20GMT
from datasource-rest.
This is unfortunately not particularly fixable in a compelling way: we've chosen to orient this package around the Fetch API but the Fetch API does not let you differentiate between "a header showed up twice" and "the same thing but joined with comma-space". (This API was designed for browsers where it explicitly cannot see Set-Cookie headers!) Making RESTDataSource work with multiple Fetch implementations is a pretty key part of the design so we can't really rely on response.headers.raw() in our general implementation.
If you're sure you're using node-fetch then you can do what @cjonesdoordash showed and use response.headers.raw()
. However, if the operation ends up interacting with HTTPCache then the response will get cloned and that will fail. If it's not a GET (and you don't explicitly set ttl
via cacheOptions
or cacheOptionsFor
) then that clone won't happen, so the @cjonesdoordash method will work fine. I suspect many Set-Cookie responses are to POSTs anyway so that should be OK?
What I'd like to do is add a test that if you send a POST (with the default node-fetch
fetcher) that gets multiple set-cookie headers, you can use the raw()
trick on the response. For various reasons we should finish #110 first.
from datasource-rest.
Related Issues (20)
- Next release of package @apollo/datasource-rest HOT 2
- Type signature for params is too narrow HOT 4
- RESTDataSource’s willSendRequest parameter changes HOT 2
- Get/Set HTTP Status? HOT 1
- willSendRequest this.context does not exist on xxxxDataSource HOT 1
- `didReceiveResponse` hook no longer available, blocking Apollo v4 upgrade HOT 6
- Errors stop getting sent to client if the override of fetch includes a catch callback HOT 2
- Configuring external caching in Apollo v4 HOT 3
- Question related to changes in request parameters HOT 2
- RESTDataSource implementation issue with `willSendRequest` & `@apollo/utils.withrequired` is a devDependency HOT 4
- Apollo Datasource adds content-type: header when Content-Type (case sensitive) header is set HOT 3
- RESTDataSource no longer have access to all datasources through context HOT 2
- Document `contextValue` recipe for circular references in context object
- Posting FormData as body (for file uploads) not possible anymore HOT 7
- Forward all cache options to key value cache HOT 6
- Unable to connect to Localhost server HOT 1
- @apollo/datasource-rest willSendRequest param type missing `agent` HOT 7
- [apollo-datasource-rest] Handling 404 errors HOT 2
- Feature request - be able to tell if API was resolved by memory, cache, or source HOT 3
- RESTDataSource - body based cacheKeyFor POST request HOT 3
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 datasource-rest.