question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Docs bug: How to intercept *all* requests to x

See original GitHub issue

Here is what I see in the README:

var scope = nock('http://www.google.com')
   .get('/cat-poems')
   .reply(function(uri, requestBody) {
     console.log('path:', this.req.path);
     console.log('headers:', this.req.headers);
     // ...
   });

I am looking for something like this:

var scope = nock('http://www.google.com')
   .all()
   .reply(function(uri, requestBody) {

   });

or like this?

var scope = nock('http://www.google.com')
   .get('*')
   .post('*')
   .put('*')
   .head('*')
   .reply(function(uri, requestBody) {

   });

how do I setup a single handler that can intercept all requests to google.com? Seems like a common problem and I don’t see anything in the docs.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
ORESoftwarecommented, Jul 8, 2018

My original use case was for a proxy server, which would intercept everything, but what I had in mind changed, so I ended up using something very different so I never fully explored the nock API beyond this question.

1reaction
gr2mcommented, Jul 7, 2018

@ORESoftware does the above code work for you?

I could see how a .all() or .any() method would be helpful. The proper way would probably be to use lower-level APIs to intercept all requsets, it’s something we want to work on now. @n30n0v already created an interceptor library, maybe it’s a better solution for your case: https://github.com/n30n0v/nock-interceptor

Could explain your use case? Maybe there is a better solution to it than intercepting all requests?

@jlilja We will probably redo the README soon, it might be good to add a section that answers how to intercept all requests, so we incorporate it in the new documentation?

Read more comments on GitHub >

github_iconTop Results From Across the Web

intercept - Cypress Documentation
Spy and stub network requests and responses. Tip: We recommend you read the Network Requests guide first. All intercepts are automatically cleared before....
Read more >
Intercept HTTP requests - Mozilla - MDN Web Docs
To intercept HTTP requests, use the webRequest API. This API enables you to add listeners for various stages of making an HTTP request....
Read more >
Spring Boot Adding Http Request Interceptors - Stack Overflow
I have followed this way to intercept the signup requests come to my application in order to do some common validations. But the...
Read more >
Setting up Axios Interceptors for all HTTP calls in an application
Interceptors are a feature that allows an application to intercept requests or responses before they are handled by the .then() or the .catch() ......
Read more >
Advanced Usage — Requests 2.28.1 documentation
Any dictionaries that you pass to a request method will be merged with the session-level values that are set. The method-level parameters override...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found