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

Support modifying transport request objects before request is sent #324

Open
unematiii opened this issue Jun 28, 2017 · 5 comments
Open

Comments

@unematiii
Copy link

How to access superagent's request obj?

I need to call withCredentials() on the request obj to deal with CORS. How to do it without overriding all the methods that http-transport exports (delete, get, head, post, put)?

@unematiii
Copy link
Author

unematiii commented Jun 29, 2017

Workaround: Cloned the contents of http-transport.js + added defaults for superagent:

var agentDefaults = require( 'superagent-defaults' );
var agent = agentDefaults();
agent.withCredentials();

/**
 * Conditionally set basic authentication on a server request object
...

import transport from './http-transport'
const api = new WPAPI({ endpoint: 'example.com/wp-json', transport })

But... updates to lib most likely to break this anytime soon...

@kadamwhite kadamwhite added this to the 2.0 milestone Dec 21, 2018
@kadamwhite kadamwhite changed the title How to access superagent's request obj? Support modifying transport request objects before request is sent Jan 24, 2019
@kadamwhite
Copy link
Collaborator

Re-purposing this ticket to generically support a way to modify or call additional methods on the request object before it is sent. This should address the withCredentials example above, but also handle #396 by providing a generic way to call any methods on the agent's request object.

@kadamwhite
Copy link
Collaborator

A good solution to this problem should permit an application author to introduce any of the following into their request chain:

  • Proxy options
  • Credentials / CORS configuration
  • Request Logging

This may also be useful for custom authentication providers.

@joshlevinson
Copy link

@kadamwhite Your proposed solution sounds 💯. I see this "in progress" for the 2.0 project. Is there a WIP branch anywhere one could review? Or is this not quite started and open for contribution?

@kadamwhite
Copy link
Collaborator

@joshlevinson Sorry for the delayed response; between day job and the core WordPress REST API component, I haven't given this project as much love as it deserves this year. You're correct, I have yet to implement anything; I was focusing previously on figuring out how to introduce a new transport using fetch instead of superagent, which just merged in #432

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

No branches or pull requests

3 participants