-
Notifications
You must be signed in to change notification settings - Fork 63
/
httpp.java
97 lines (73 loc) · 2.24 KB
/
httpp.java
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
package com.iwebpp.node.http;
import com.iwebpp.SimpleDebug;
import com.iwebpp.node.NodeContext;
import com.iwebpp.node.Url;
import com.iwebpp.node.Url.UrlObj;
public final class httpp extends SimpleDebug {
private static final String TAG = "httpp";
// httpp.createServer([requestListener])
public static HttppServer createServer(
NodeContext ctx,
HttpServer.requestListener onreq) throws Exception {
return new HttppServer(ctx, onreq);
}
public static HttppServer listen(
NodeContext ctx,
int port,
String host,
HttpServer.requestListener onreq) throws Exception {
HttppServer srv = createServer(ctx, onreq);
srv.listen(port, host);
return srv;
}
// httpp.request(options, [callback])
public static ClientRequest request(
NodeContext ctx,
ReqOptions options,
ClientRequest.responseListener onres) throws Exception {
debug(TAG, "httpp request");
options.httpp = true;
return new ClientRequest(ctx, options, onres);
}
// TBD... parser ReqOptions from URL
public static ClientRequest request(
NodeContext ctx,
String url,
ClientRequest.responseListener onres) throws Exception {
UrlObj obj = Url.parse(url);
ReqOptions options = new ReqOptions();
options.protocol = obj.protocol;
options.auth = obj.auth;
options.hostname = obj.hostname;
options.port = obj.port;
options.host = obj.host;
options.path = obj.path;
return request(ctx, options, onres);
}
// httpp.get(options, [callback])
public static ClientRequest get(
NodeContext ctx,
ReqOptions options,
ClientRequest.responseListener onres) throws Exception {
// GET method
options.method = "GET";
options.httpp = true;
ClientRequest req = request(ctx, options, onres);
req.end(null, null, null);
return req;
}
public static ClientRequest get(
NodeContext ctx,
String url,
ClientRequest.responseListener onres) throws Exception {
UrlObj obj = Url.parse(url);
ReqOptions options = new ReqOptions();
options.protocol = obj.protocol;
options.auth = obj.auth;
options.hostname = obj.hostname;
options.port = obj.port;
options.host = obj.host;
options.path = obj.path;
return get(ctx, options, onres);
}
}