Skip to content
This repository
Browse code

added notes about preemptive plugin responses

  • Loading branch information...
commit 58147e7bce8248ac6d34d7fe0f317be07757acd2 1 parent 7daa28e
Greg Reimer authored

Showing 1 changed file with 26 additions and 3 deletions. Show diff stats Hide diff stats

  1. +26 3 readme.markdown
29 readme.markdown
Source Rendered
@@ -19,7 +19,7 @@ If it doesn't already exist, upon startup hoxy will create a file in the `rules`
19 19 How to Use Hoxy
20 20 ---------------
21 21
22   -If you have a good grasp of HTTP basics, hoxy itself isn't wildly complicated, and reading the architectural overview below should give you a basic idea of how it works. From there, the readme file in the `rules` dir should give you enough info to get on your way for writing rules.
  22 +If you have a good grasp of HTTP basics, hoxy itself isn't wildly complicated, and reading the architectural overview below should give you a basic idea of how it works. From there, the readme file in the `rules` dir should give you enough info to get on your way writing rules.
23 23
24 24 If you're comfortable writing JavaScript for node.js, you can also write plugins for hoxy. See the readme file in the `plugins` dir for more info.
25 25
@@ -89,6 +89,29 @@ Request-phase rules (2) and response-phase rules (4) are written by you, and can
89 89
90 90 Furthermore, a rule will fire only when certain conditions are met. For example, *if* the url ends with ".min.js", *then* run js-beautify against the content of the response body. Or, *if* the hostname equals "www.example.com", *then* change it to "www-stage.example.com". Just as any aspect of a request or response can be altered, any aspect of a request or response can be used in a conditional.
91 91
92   -Finally, while hoxy has a broad set of out-of-the-box capabilities, it also has a plugin API allowing developers to extend it in arbitrary ways. Plugins are written in JavaScript and invoked using the same conditional logic described above.
  92 +Finally, while hoxy has a broad set of out-of-the-box capabilities, its plugin API allows developers to extend it in arbitrary ways. Plugins are written in JavaScript and invoked using the same conditional logic described above.
93 93
94   -This opens the door for all kinds of testing, debugging and prototyping (and maybe some mischief) that might not otherwise be possible. Please use hoxy responsibly.
  94 +A Twist in the Plot
  95 +-------------------
  96 +
  97 +Plugins running in the request phase have the option to write the response themselves, which effectively preempts the hit to the server. In such cases, hoxy's behavior would look like this:
  98 +
  99 + ------------------------------
  100 + server: *blissful ignorance*
  101 + ------------------------------
  102 + hoxy: 2———3
  103 + --------------/-----\---------
  104 + client: 1 4
  105 + ------------------------------
  106 +
  107 +* Phase 1: Client prepares to make request.
  108 +* Hop: Client transmits to hoxy.
  109 +* Phase 2: Hoxy executes request-phase rules, triggering a plugin that populates the response.
  110 +* Phase 3: Hoxy notices that a response has already been written, skips the server hit and executes response-phase rules.
  111 +* Hop: Hoxy transmits to client.
  112 +* Phase 4: Client processes response.
  113 +
  114 +Fin
  115 +---
  116 +
  117 +Hoxy opens the door for all kinds of testing, debugging and prototyping (and maybe some mischief) that might not otherwise be possible. Please use hoxy responsibly.

0 comments on commit 58147e7

Please sign in to comment.
Something went wrong with that request. Please try again.