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.util.Args;
39
40
41
42
43
44
45
46
47 public final class SimpleHttpRequest extends ConfigurableHttpRequest {
48
49 private static final long serialVersionUID = 1L;
50 private SimpleBody body;
51
52 public static SimpleHttpRequest copy(final HttpRequest original) {
53 Args.notNull(original, "HTTP request");
54 final SimpleHttpRequestsync/methods/SimpleHttpRequest.html#SimpleHttpRequest">SimpleHttpRequest copy = new SimpleHttpRequest(original.getMethod(), original.getRequestUri());
55 copy.setVersion(original.getVersion());
56 for (final Iterator<Header> it = original.headerIterator(); it.hasNext(); ) {
57 copy.addHeader(it.next());
58 }
59 copy.setScheme(original.getScheme());
60 copy.setAuthority(original.getAuthority());
61 return copy;
62 }
63
64 public SimpleHttpRequest(final String method, final String path) {
65 super(method, path);
66 }
67
68 public SimpleHttpRequest(final String method, final HttpHost host, final String path) {
69 super(method, host, path);
70 }
71
72 public SimpleHttpRequest(final String method, final URI requestUri) {
73 super(method, requestUri);
74 }
75
76 SimpleHttpRequest(final Method method, final URI requestUri) {
77 this(method.name(), requestUri);
78 }
79
80 SimpleHttpRequest(final Method method, final HttpHost host, final String path) {
81 this(method.name(), host, path);
82 }
83
84 public void setBody(final SimpleBody body) {
85 this.body = body;
86 }
87
88 public void setBody(final byte[] bodyBytes, final ContentType contentType) {
89 this.body = SimpleBody.create(bodyBytes, contentType);
90 }
91
92 public void setBody(final String bodyText, final ContentType contentType) {
93 this.body = SimpleBody.create(bodyText, contentType);
94 }
95
96 public SimpleBody getBody() {
97 return body;
98 }
99
100 public ContentType getContentType() {
101 return body != null ? body.getContentType() : null;
102 }
103
104 public String getBodyText() {
105 return body != null ? body.getBodyText() : null;
106 }
107
108 public byte[] getBodyBytes() {
109 return body != null ? body.getBodyBytes() : null;
110 }
111
112 }
113