Git Product home page Git Product logo

eight-track's People

Contributors

raynos avatar swbiggart avatar twolfson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

eight-track's Issues

Follows redirects when it shouldn't

Upon revisiting #17, I realized that we are allowing request to follow redirects. A quick regression test in 1f042c4 proved that my fears were true. Please add a followRedirect: false to all requests (the client requesting to our server will follow the 302's anyway).

Allow for modifying response content

Currently, it is difficult modify response content from eight-track. I attempted to write up way to perform it via piping the response but even that does not write original data to disk making it useless (it only reads from disk).

https://gist.github.com/twolfson/9753482

The ideal API would be request-like that emits data events or calls back with the body/buffer.

// Inside of a fixed-server
response: function (req, res, next) {
  // Forward the original request
  eightTrack.forwardRequest(req, function (err, externalRes, externalBody) {
    // If there was an error, callback with it
    if (err) {
      return next(err);
    }

    // Send back twice the amount of items
    var items = JSON.parse(externalBody);
    res.send(items.concat(items));
  });
}

This is a hybrid between mocking and realistic data which is more realistic than only mocks.

/cc @zheller

Build CLI library

During development, it is useful to have eight-track functionality to avoid abusing external services. We should consider creating eight-track-cli which would create an http server using eight-track.

I would prefer this be an external repo since it could get more complex as time goes on (e.g. support config files) and I would like to isolate said complexity.

eight-track --port 9001 --url "http://localhost:1337/" --fixture-dir "recordings"
eight-track --config ./eighttrackrc

/cc @zheller

OPTIONS encoding issue

Hey, trying to use this with some CORS requests and getting this error in Chrome when running through the middle ware:

I noticed that the body response for OPTIONS looks weird:

  "response": {
    "httpVersion": "1.1",
    "headers": {
      "content-type": "application/json; charset=utf-8",
      "strict-transport-security": "max-age=10886400",
      "timestamp": "1397159432",
      "access-control-allow-origin": "*",
      "access-control-max-age": "86400",
      "access-control-allow-methods": "GET, HEAD, POST, PUT, DELETE, OPTIONS",
      "access-control-allow-headers": "Authorization, Content-Type, If-None-Match",
      "access-control-expose-headers": "WWW-Authenticate, Server-Authorization, Timestamp, Accept-Language",
      "cache-control": "no-cache",
      "content-encoding": "gzip",
      "vary": "accept-encoding",
      "date": "Thu, 10 Apr 2014 19:50:32 GMT",
      "connection": "keep-alive",
      "transfer-encoding": "chunked"
    },
    "trailers": {},
    "statusCode": 200,
    "body": "\u001f�\b\u0000\u0000\u0000\u0000\u0000\u0000\u0003��\u0005\u0000C���\u0002\u0000\u0000\u0000"
  }
}

Find performance bottlenecks

While #14 is a step in the right direction, the benchmark of 800ms for 100 repeated requests leaves me wanting more. We should add some timing logs to each function run in the test suite.

Off the top of my head, some more possible gains might be:

Cannot cache `gzip` content

While attempting to install eight-track to twolfson/icomoon-phantomjs, I encountered an issue with us forwarding a request for gzipped content tthat was stringifying binary data in the response. When moving off of toString() for outgoingBuff, this fixed it nicely.

My suggestion is to:

  • Store buffer data in external file (e.g. .raw, .buff, or .in/.out for incoming/outgoing buffers respectively)
  • Possibly store truncated stringified version in JSON for faster viewing/debugging. Definitely add a reference to relative file path of .in/.out so we can extend on this as an indirect reference (instead of having weird brittle .ext replacement logic)

This might be a good opportunity to patch #1.

Cannot save very long request

When we make a very long request, we save a correspondingly long filename. Unfortunately, sometimes it is too long to save to disk (e.g. ENAMETOOLONG).

Add performance benchmarks

Recently, we added some large data sets in a private repository. We are seeing up to 200ms load time for both disk load and JSON.parse. We should consider caching disk loads and JSON.parse results (with deepClone's to prevent original data mutation).

Allow passing of pre-buffered body

Sometimes during testing, we want to assert we are passing specific data since achieving reproducable state can be difficult. We should make it easy for people to set a pre-buffered body that we can forward requests against.

Cannot repeat multipart/form-data requests

During the transition of twolfson/css-validator from nock to eight-track, I ran into a snag. The W3C's CSS validtion service uses multipart/form-data to accept POST data. An example request looks like:

    "headers": {
      "content-type": "multipart/form-data; boundary=--------------------------254222337025012242873031"
    },
    "method": "POST",
    "url": "/css-validator/validator",
    "body": "----------------------------254222337025012242873031\r\nContent-Disposition: form-data; name=\"output\"\r\n\r\nsoap12\r\n----------------------------254222337025012242873031\r\nContent-Disposition: form-data; name=\"w3cUrl\"\r\n\r\nhttp://localhost:1337/css-validator/validator\r\n----------------------------254222337025012242873031\r\nContent-Disposition: form-data; name=\"highWaterMark\"\r\n\r\n1024000\r\n----------------------------254222337025012242873031\r\nContent-Disposition: form-data; name=\"text\"\r\n\r\nbody {\n  background: url(abcd);\n}\n\r\n----------------------------254222337025012242873031--"

Part of the specification for multipart/form-data is to use a boundary to delimit different chunks of data. This delimiter must not be contained in the original data.

http://tools.ietf.org/html/rfc2388#section-4.1

To solve this problem, some libraries (e.g. felixge/node-form-data) generate a random number as their boundary (as seen in the example above).

https://github.com/felixge/node-form-data/blob/0.1.2/lib/form_data.js#L193-L202

To combat this, we some options include:

  • Introduce a normalize parameter which is a function that adjusts the data we serialize against to generate a key
  • Add built-in normalizing logic for multipart form (or at least an option for it)

I would lean towards the normalize function as it covers cases that we have not yet encountered. Additionally, maybe we can add a class-level function which is already set up to normalize multipart form boundaries.

Use buffer clones over concatenated buffer

To be as accurate as possible, we should consider moving to buffer clones that will each be written via their own unique data events.

Currently, we are concatenating them all and pushing them via one major data event.

Can I somehow disable remote requests?

I want to create fixtures on my local machine, and do not create them on CI server (use saved fixtures from repo). So, basically I want to disable recording during CI run. Is it possible now?

Explore proxying to subpaths

Currently, you can only proxy to a hostname + port. In theory, you should be able to proxy to a subpath

eightTrack({
  url: 'http://localhost:1337/abc'
}).listen(1338);

request('http://localhost:1338/def'); // proxies to 'http://localhost:1337/abc/def')

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.