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 package org.apache.hc.client5.http.async.methods;
29
30 import java.net.URI;
31 import java.util.Iterator;
32
33 import org.apache.hc.core5.http.ContentType;
34 import org.apache.hc.core5.http.Header;
35 import org.apache.hc.core5.http.HttpHost;
36 import org.apache.hc.core5.http.HttpRequest;
37 import org.apache.hc.core5.http.Method;
38 import org.apache.hc.core5.net.URIAuthority;
39 import org.apache.hc.core5.util.Args;
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 public final class SimpleHttpRequest extends ConfigurableHttpRequest {
56
57 private static final long serialVersionUID = 1L;
58 private SimpleBody body;
59
60
61
62
63 public static SimpleHttpRequest create(final String method, final String uri) {
64 return new SimpleHttpRequest(method, uri);
65 }
66
67
68
69
70 public static SimpleHttpRequest create(final String method, final URI uri) {
71 return new SimpleHttpRequest(method, uri);
72 }
73
74
75
76
77 public static SimpleHttpRequest create(final Method method, final URI uri) {
78 return new SimpleHttpRequest(method, uri);
79 }
80
81
82
83
84 public static SimpleHttpRequest create(final Method method, final HttpHost host, final String path) {
85 return new SimpleHttpRequest(method, host, path);
86 }
87
88
89
90
91 public static SimpleHttpRequest create(final String method, final String scheme, final URIAuthority authority, final String path) {
92 return new SimpleHttpRequest(method, scheme, authority, path);
93 }
94
95
96
97
98 @Deprecated
99 public static SimpleHttpRequest copy(final HttpRequest original) {
100 Args.notNull(original, "HTTP request");
101 final SimpleHttpRequest copy = new SimpleHttpRequest(original.getMethod(), original.getRequestUri());
102 copy.setVersion(original.getVersion());
103 for (final Iterator<Header> it = original.headerIterator(); it.hasNext(); ) {
104 copy.addHeader(it.next());
105 }
106 copy.setScheme(original.getScheme());
107 copy.setAuthority(original.getAuthority());
108 return copy;
109 }
110
111 public SimpleHttpRequest(final String method, final String path) {
112 super(method, path);
113 }
114
115 public SimpleHttpRequest(final String method, final HttpHost host, final String path) {
116 super(method, host, path);
117 }
118
119 public SimpleHttpRequest(final String method, final URI requestUri) {
120 super(method, requestUri);
121 }
122
123
124
125
126 public SimpleHttpRequest(final Method method, final URI requestUri) {
127 this(method.name(), requestUri);
128 }
129
130
131
132
133 public SimpleHttpRequest(final Method method, final HttpHost host, final String path) {
134 this(method.name(), host, path);
135 }
136
137
138
139
140 public SimpleHttpRequest(final String method, final String scheme, final URIAuthority authority, final String path) {
141 super(method, scheme, authority, path);
142 }
143
144 public void setBody(final SimpleBody body) {
145 this.body = body;
146 }
147
148 public void setBody(final byte[] bodyBytes, final ContentType contentType) {
149 this.body = SimpleBody.create(bodyBytes, contentType);
150 }
151
152 public void setBody(final String bodyText, final ContentType contentType) {
153 this.body = SimpleBody.create(bodyText, contentType);
154 }
155
156 public SimpleBody getBody() {
157 return body;
158 }
159
160 public ContentType getContentType() {
161 return body != null ? body.getContentType() : null;
162 }
163
164 public String getBodyText() {
165 return body != null ? body.getBodyText() : null;
166 }
167
168 public byte[] getBodyBytes() {
169 return body != null ? body.getBodyBytes() : null;
170 }
171
172 }
173