This repository was archived by the owner on Mar 3, 2026. It is now read-only.
forked from jooby-project/jooby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContext.java
More file actions
135 lines (95 loc) · 3.52 KB
/
Context.java
File metadata and controls
135 lines (95 loc) · 3.52 KB
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
package io.jooby;
import org.jooby.funzy.Throwing;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.Executor;
public interface Context {
class Dispatched extends RuntimeException {
public final Executor executor;
public Dispatched(@Nullable Executor executor) {
this.executor = executor;
}
}
/**
* **********************************************************************************************
* **** Request methods *************************************************************************
* **********************************************************************************************
*/
@Nonnull QueryString query();
@Nonnull Value query(String name);
@Nonnull String method();
@Nonnull String path();
@Nonnull Route route();
@Nonnull Context route(@Nonnull Route route);
boolean isInIoThread();
default @Nonnull Context dispatch() {
return dispatch(null);
}
@Nonnull Context dispatch(@Nullable Executor executor);
@Nonnull Context detach();
/**
* **********************************************************************************************
* **** Response methods *************************************************************************
* **********************************************************************************************
*/
@Nonnull Context reset();
@Nonnull OutputStream outputStream();
default @Nonnull Context outputStream(@Nonnull Throwing.Consumer<OutputStream> callback) {
try (OutputStream w = outputStream()) {
callback.accept(w);
} catch (Throwable x) {
throw Throwing.sneakyThrow(x);
} finally {
end();
}
return this;
}
default @Nonnull Writer writer() {
return writer(StandardCharsets.UTF_8);
}
default @Nonnull Context writer(@Nonnull Throwing.Consumer<Writer> writer) {
return writer(StandardCharsets.UTF_8, writer);
}
default @Nonnull Context writer(@Nonnull Charset charset, @Nonnull Throwing.Consumer<Writer> writer) {
try (Writer w = writer(charset)) {
writer.accept(w);
} catch (Throwable x) {
throw Throwing.sneakyThrow(x);
} finally {
end();
}
return this;
}
default @Nonnull Writer writer(@Nonnull Charset charset) {
return new OutputStreamWriter(outputStream(), charset);
}
@Nonnull Context after(@Nonnull Route.After after);
default @Nonnull Context header(@Nonnull String name, int value) {
return header(name, Integer.toString(value));
}
@Nonnull Context header(@Nonnull String name, @Nonnull String value);
int status();
@Nonnull Context status(int status);
@Nonnull Context length(long length);
@Nonnull Context type(@Nonnull String contentType);
default @Nonnull Context write(@Nonnull String chunk) {
return write(chunk, StandardCharsets.UTF_8);
}
@Nonnull Context write(@Nonnull String chunk, @Nonnull Charset charset);
@Nonnull Context write(byte[] chunk);
@Nonnull Context write(@Nonnull ByteBuffer chunk);
default @Nonnull Context send(@Nonnull String response) {
return send(response, StandardCharsets.UTF_8);
}
@Nonnull Context send(@Nonnull String response, @Nonnull Charset charset);
@Nonnull Context send(@Nonnull byte[] chunk);
@Nonnull Context send(@Nonnull ByteBuffer chunk);
@Nonnull Context end();
boolean committed();
}