forked from kriskowal/q-io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
http-apps.js
152 lines (136 loc) · 5.88 KB
/
http-apps.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/**
* Provides tools for making, routing, adapting, and decorating
* Q-JSGI web applications.
*
* Duck Types
* ----------
*
* A Q-JSGI _app_ is a function that accepts a request and returns a
* response. The response may be promised.
*
* A Q-JSGI _request_ is an object or a promise for an object that has
* the following properties:
*
* * `method` is the HTTP request method as a string.
* * `path` is a string, guaranteed to start with `"/"`.
* * `headers` is an object mapping lower-case HTTP headers to
* their corresponding values as strings.
* * `body` is a Q-JSGI content body.
*
* A Q-JSGI _response_ is an object or a promise for an object that
* has the following properties:
*
* * `status` is the HTTP response status code as a number.
* * `headers` is an object mapping lower-case HTTP headers to their
* corresponding values as strings.
* * `body` is a Q-JSGI content body.
*
* A Q-JSGI response and request content _body_ can be as simple as an
* array of strings. It can be a promise. In general, it must be an
* object that has a `forEach` method. The `forEach` method accepts a
* `write` function. It goes without saying that `forEach` returns
* `undefined`, but it can return a promise for `undefined` that will
* resolve when it has made all of its `write` calls and the request
* or response can be closed, re-used, or kept alive.. The `forEach`
* function may call `write` with a `String` any number of times. The
* `String` may be promised.
*
* @module
*/
require("collections/shim");
var Q = require("q");
var HTTP = require("./http");
var FS = require("./fs");
var URL = require("url2");
var inspect = require("util").inspect;
exports.Chain = require("./http-apps/chain");
var RouteApps = require("./http-apps/route");
exports.Cap = RouteApps.Cap;
exports.Tap = RouteApps.Tap;
exports.Trap = RouteApps.Trap;
exports.Branch = RouteApps.Branch;
var ContentApps = require("./http-apps/content");
exports.Content = ContentApps.Content;
exports.content = ContentApps.content;
exports.ok = ContentApps.ok;
exports.ContentRequest = ContentApps.ContentRequest;
exports.Inspect = ContentApps.Inspect;
exports.ParseQuery = ContentApps.ParseQuery;
var FsApps = require("./http-apps/fs");
exports.File = FsApps.File;
exports.FileTree = FsApps.FileTree;
exports.file = FsApps.file;
exports.directory = FsApps.directory;
exports.etag = FsApps.etag;
exports.ListDirectories = FsApps.ListDirectories;
exports.listDirectory = FsApps.listDirectory;
exports.listDirectoryHtmlFragment = FsApps.listDirectoryHtmlFragment;
exports.listDirectoryText = FsApps.listDirectoryText;
exports.listDirectoryMarkdown = FsApps.listDirectoryMarkdown;
exports.listDirectoryJson = FsApps.listDirectoryJson;
exports.listDirectoryData = FsApps.listDirectoryData;
exports.DirectoryIndex = FsApps.DirectoryIndex;
var HtmlApps = require("./http-apps/html");
exports.HandleHtmlFragmentResponses = HtmlApps.HandleHtmlFragmentResponses;
exports.handleHtmlFragmentResponse = HtmlApps.handleHtmlFragmentResponse;
exports.escapeHtml = HtmlApps.escapeHtml;
var JsonApps = require("./http-apps/json");
exports.HandleJsonResponses = JsonApps.HandleJsonResponses;
exports.handleJsonResponse = JsonApps.handleJsonResponse;
exports.Json = JsonApps.Json;
exports.json = JsonApps.json;
exports.JsonRequest = JsonApps.JsonRequest;
var RedirectApps = require("./http-apps/redirect");
exports.PermanentRedirect = RedirectApps.PermanentRedirect;
exports.PermanentRedirectTree = RedirectApps.PermanentRedirectTree;
exports.TemporaryRedirect = RedirectApps.TemporaryRedirect;
exports.TemporaryRedirectTree = RedirectApps.TemporaryRedirectTree;
exports.Redirect = RedirectApps.Redirect;
exports.RedirectTree = RedirectApps.RedirectTree;
exports.permanentRedirect = RedirectApps.permanentRedirect;
exports.permanentRedirectTree = RedirectApps.permanentRedirectTree;
exports.temporaryRedirect = RedirectApps.temporaryRedirect;
exports.temporaryRedirectTree = RedirectApps.temporaryRedirectTree;
exports.redirectTree = RedirectApps.redirectTree;
exports.redirect = RedirectApps.redirect;
exports.redirectText = RedirectApps.redirectText;
exports.redirectHtml = RedirectApps.redirectHtml;
exports.RedirectTrap = RedirectApps.RedirectTrap;
exports.isRedirect = RedirectApps.isRedirect;
var ProxyApps = require("./http-apps/proxy");
exports.Proxy = ProxyApps.Proxy;
exports.ProxyTree = ProxyApps.ProxyTree;
var NegotiationApps = require("./http-apps/negotiate");
exports.negotiate = NegotiationApps.negotiate;
exports.Method = NegotiationApps.Method;
exports.ContentType = NegotiationApps.ContentType;
exports.Language = NegotiationApps.Language;
exports.Charset = NegotiationApps.Charset;
exports.Encoding = NegotiationApps.Encoding;
exports.Host = NegotiationApps.Host;
exports.Select = NegotiationApps.Select;
var StatusApps = require("./http-apps/status");
exports.statusCodes = StatusApps.statusCodes;
exports.statusMessages = StatusApps.statusMessages;
exports.statusWithNoEntityBody = StatusApps.statusWithNoEntityBody;
exports.appForStatus = StatusApps.appForStatus;
exports.responseForStatus = StatusApps.responseForStatus;
exports.textResponseForStatus = StatusApps.textResponseForStatus;
exports.htmlResponseForStatus = StatusApps.htmlResponseForStatus;
exports.badRequest = StatusApps.badRequest;
exports.notFound = StatusApps.notFound;
exports.methodNotAllowed = StatusApps.methodNotAllowed;
exports.noLanguage = StatusApps.noLanguage;
exports.notAcceptable = StatusApps.notAcceptable;
var DecoratorApps = require("./http-apps/decorators");
exports.Normalize = DecoratorApps.Normalize;
exports.Date = DecoratorApps.Date;
exports.Error = DecoratorApps.Error;
exports.Debug = DecoratorApps.Debug;
exports.Log = DecoratorApps.Log;
exports.Time = DecoratorApps.Time;
exports.Headers = DecoratorApps.Headers;
exports.Permanent = DecoratorApps.Permanent;
exports.Decorators = DecoratorApps.Decorators;
var CookieApps = require("./http-apps/cookie");
exports.CookieJar = CookieApps.CookieJar;