forked from akka/akka-http
/
HttpRequest.java
115 lines (96 loc) · 3 KB
/
HttpRequest.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
package akka.http.javadsl.model;
import akka.Done;
import akka.http.impl.util.JavaAccessors;
import akka.stream.Materializer;
import akka.stream.javadsl.Sink;
import java.util.concurrent.CompletionStage;
/**
* Represents an Http request.
*/
public abstract class HttpRequest implements HttpMessage, HttpMessage.MessageTransformations<HttpRequest> {
/**
* Returns the Http method of this request.
*/
public abstract HttpMethod method();
/**
* Returns the Uri of this request.
*/
public abstract Uri getUri();
/**
* Returns the entity of this request.
*/
public abstract RequestEntity entity();
/**
* Returns a copy of this instance with a new method.
*/
public abstract HttpRequest withMethod(HttpMethod method);
/**
* Returns a copy of this instance with a new Uri.
*/
public abstract HttpRequest withUri(Uri relativeUri);
/**
* Returns a copy of this instance with a new Uri.
*/
public abstract HttpRequest withUri(String path);
/**
* Returns a copy of this instance with a new entity.
*/
public abstract HttpRequest withEntity(RequestEntity entity);
/**
* Returns a default request to be modified using the `withX` methods.
*/
public static HttpRequest create() {
return JavaAccessors.HttpRequest();
}
/**
* Returns a default request to the specified URI to be modified using the `withX` methods.
*/
public static HttpRequest create(String uri) {
return JavaAccessors.HttpRequest(uri);
}
/**
* A default GET request to be modified using the `withX` methods.
*/
public static HttpRequest GET(String uri) {
return create(uri);
}
/**
* A default POST request to be modified using the `withX` methods.
*/
public static HttpRequest POST(String uri) {
return create(uri).withMethod(HttpMethods.POST);
}
/**
* A default PUT request to be modified using the `withX` methods.
*/
public static HttpRequest PUT(String uri) {
return create(uri).withMethod(HttpMethods.PUT);
}
/**
* A default DELETE request to be modified using the `withX` methods.
*/
public static HttpRequest DELETE(String uri) {
return create(uri).withMethod(HttpMethods.DELETE);
}
/**
* A default HEAD request to be modified using the `withX` methods.
*/
public static HttpRequest HEAD(String uri) {
return create(uri).withMethod(HttpMethods.HEAD);
}
/**
* A default PATCH request to be modified using the `withX` methods.
*/
public static HttpRequest PATCH(String uri) {
return create(uri).withMethod(HttpMethods.PATCH);
}
/**
* A default OPTIONS request to be modified using the `withX` methods.
*/
public static HttpRequest OPTIONS(String uri) {
return create(uri).withMethod(HttpMethods.OPTIONS);
}
}