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

What if the server response timeOut or 404 #65

Open
aemonge opened this issue Nov 3, 2015 · 12 comments
Open

What if the server response timeOut or 404 #65

aemonge opened this issue Nov 3, 2015 · 12 comments

Comments

@aemonge
Copy link

aemonge commented Nov 3, 2015

How to control the server timeOut or statusCode === 404 in the 'response' phase ??

@greim
Copy link
Owner

greim commented Nov 4, 2015

You can check response.statusCode during the response phase.

@aemonge
Copy link
Author

aemonge commented Nov 4, 2015

I'm not getting any statusCode..... is their a timeOut setting to make it shorter. Or why am I not getting the statusCode ?

  function responseInterceptor(request, response) {
    console.log('+++++++++++++++++++ Response ++++++++++++++++++++');
    console.log(arguments, response.statusCode); // < === Not getting 404 nor timeOut
    console.log('+++++++++++++++++++++++++++++++++++++++++++++++++');
  }

  function requestInterceptor(request, response) {
    // .........
  }

  function attachInterceptors() {
    proxy.intercept({
      phase: 'request',
      as: 'json'
    }, requestInterceptor);

    proxy.intercept({
      phase: 'response',
      as: 'json'
    }, responseInterceptor);
  }

  proxy = hoxy.createServer({
    reverse: 'https://example.com/'
    // tls: {
      // key: fs.readFileSync('./my-server.key.pem'),
      // cert: fs.readFileSync('./my-server.crt.pem')
    // }
  }).listen(5000);

  attachInterceptors();

@greim
Copy link
Owner

greim commented Nov 4, 2015

Is it logging undefined?

@aemonge
Copy link
Author

aemonge commented Nov 4, 2015

  '1':
   Response {
     domain: null,
     _events: { log: [Function] },
     _eventsCount: 1,
     _maxListeners: undefined,
     _data: { statusCode: 200, headers: {}, slow: {} },
     phase: 'request' },
  '2':
   Cycle {
     domain: null,
     _events: { log: [Function] },
     _eventsCount: 1,
     _maxListeners: undefined,
     _proxy:
      Proxy {
        domain: null,
        _events: {},
        _eventsCount: 0,
        _maxListeners: undefined,
        _reverse: 'https://non-existing-example.com/',
        _tls: undefined,
        _intercepts: [Object],
        _server: [Object] },
     _request:
      Request {
        domain: null,
        _events: [Object],
        _eventsCount: 1,
        _maxListeners: undefined,
        _data: [Object],
        _populated: true,
        phase: 'request' },
     _response:
      Response {
        domain: null,
        _events: [Object],
        _eventsCount: 1,
        _maxListeners: undefined,
        _data: [Object],
        phase: 'request' },
     _phase: 'request' } }

@greim
Copy link
Owner

greim commented Nov 4, 2015

That looks incomplete. What does it log if you just do console.log(response.statusCode)?

@aemonge
Copy link
Author

aemonge commented Nov 4, 2015

Nothing is been logged. I've managed to resolve this issues by login in the 'response-sent' phase. Yeah, I've trim the request part of the argument cause I didn't tough it was usefull.

So if you intend to support the response.statusCode on response phase, then this issue isn't fixed, and I would gladdly provide you an example of it

But if you intend no to support it, and instead encorage user to use the response-sent phase, then you should make a note on documentation ;)

I would be more than happy to help you either ways, I think hoxy is amazing ;) !!! And you're very kind ^^

@greim
Copy link
Owner

greim commented Nov 5, 2015

But specifically, when you say nothing was logged, do you mean it logged undefined, or was the console.log() statement never reached, or something else?

@aemonge
Copy link
Author

aemonge commented Nov 5, 2015

console.log() never reached, as if the timeOut is way to big, or something like that

@greim
Copy link
Owner

greim commented Nov 6, 2015

The output pasted above looks like a fragment of arguments is being printed from console.log(arguments, response.statusCode). The status code should appear immediately after it. However it looks like you didn't paste the entire output, which is why I was asking.

@aemonge
Copy link
Author

aemonge commented Nov 6, 2015

So no logging the server's timeOut (waited my whole lunch, so about an hour or so )

This is my code

#!/usr/bin/env node
/*eslint no-unused-vars: 0*/
'use strict';

(function () {
  var hoxy = require('hoxy'), proxy;

  function responseSentInterceptor(request, response) {
    console.log('====================== RESPONSE SENT INTERCEPTOR');
    console.log(request, response);
  }

  function responseInterceptor(request, response) {
    console.log('====================== RESPONSE INTERCEPTOR');
    console.log(request, response);
  }

  function requestInterceptor(request, response) {
    console.log('======================= REQUEST INTERCEPTOR');
    console.log(request, response);
  }

  function attachInterceptors() {
    proxy.intercept({
      phase: 'request',
      as: 'json'
    }, requestInterceptor);

    proxy.intercept({
      phase: 'response',
      as: 'json'
    }, responseInterceptor);

    proxy.intercept({
      phase: 'response-sent'
    }, responseSentInterceptor);
  }

  proxy = hoxy.createServer({
    reverse: 'http://thisIsNot.a.real.server'
  }).listen(5000);

  attachInterceptors();
}());

Output

======================= REQUEST INTERCEPTOR
Request {
  domain: null,
  _events: { log: [Function] },
  _eventsCount: 1,
  _maxListeners: undefined,
  _data: 
   { slow: {},
     httpVersion: '1.1',
     headers: 
      { 'user-agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:42.0) Gecko/20100101 Firefox/42.0',
        accept: 'application/json, text/javascript',
        'accept-language': 'en-US,es;q=0.8,en;q=0.5,es-ES;q=0.3',
        'accept-encoding': 'gzip, deflate',
        dnt: '1',
        channel: '49',
        version: '2',
        'x-requested-with': 'XMLHttpRequest',
        'content-type': 'application/json; charset=UTF-8',
        referer: 'http://localhost:3000/',
        'content-length': '268',
        cookie: 'JSESSIONID=0000RWu-GDpXC4SsvFPvl5PFTkq:191dudcmv',
        connection: 'keep-alive',
        pragma: 'no-cache',
        'cache-control': 'no-cache',
        host: 'thisisnot.a.real.server' },
     protocol: 'http:',
     hostname: 'thisisnot.a.real.server',
     method: 'POST',
     url: '/auth/validate',
     source: 
      JsonReader {
        _readableState: [Object],
        readable: true,
        domain: null,
        _events: {},
        _eventsCount: 0,
        _maxListeners: undefined,
        _obj: [Object] } },
  _populated: true,
  phase: 'request' } Response {
  domain: null,
  _events: { log: [Function] },
  _eventsCount: 1,
  _maxListeners: undefined,
  _data: { statusCode: 200, headers: {}, slow: {} },
  phase: 'request' }

@aemonge
Copy link
Author

aemonge commented Nov 6, 2015

So I hope this clarify my issue =^.^=

And thanks again !! (:

@greim
Copy link
Owner

greim commented Nov 6, 2015

Can you add

proxy.log('error warn debug', process.stderr);
proxy.log('info', process.stdout);

and let me know if it logs any errors or anything?

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

No branches or pull requests

2 participants