Skip to content

Commit 4d7c315

Browse files
Fix: HttpServletHandler: Request.create() caused build failure (#2604)
* Undo Request.create() removal: Method was used by HttpServletHandler and caused build failure * Refactor `Request.create()` usage: Move method logic into `HttpServletHandler` to improve clarity and retain functionality. * Refactor `Request.Builder`: Add `uri` and `version` methods, update `HttpServletHandler.createRequest()` to use Builder for improved readability and maintainability.
1 parent bcaccce commit 4d7c315

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

core/src/main/java/com/predic8/membrane/core/http/Request.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,16 @@ public Builder url(URIFactory uriFactory, String url) throws URISyntaxException
249249
return this;
250250
}
251251

252+
public Builder uri(String uri) {
253+
req.setUri(uri);
254+
return this;
255+
}
256+
257+
public Builder version(String version) {
258+
req.setVersion(version);
259+
return this;
260+
}
261+
252262
public Builder authorization(String username, String password) {
253263
req.getHeader().setAuthorization(username,password);
254264
return this;

war/src/main/java/com/predic8/membrane/servlet/embedded/HttpServletHandler.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.slf4j.LoggerFactory;
3030

3131
import java.io.IOException;
32+
import java.io.InputStream;
3233
import java.net.InetAddress;
3334
import java.util.Enumeration;
3435

@@ -111,7 +112,6 @@ protected void writeResponse(Response res) throws Exception {
111112
}
112113

113114
private Request createRequest() throws IOException {
114-
Request srcReq = new Request();
115115

116116
String pathQuery = request.getRequestURI();
117117
if (request.getQueryString() != null)
@@ -123,13 +123,25 @@ private Request createRequest() throws IOException {
123123
pathQuery = pathQuery.substring(contextPath.length());
124124
}
125125

126-
srcReq.create(
126+
return createRequest(
127127
request.getMethod(),
128128
pathQuery,
129129
request.getProtocol(),
130130
createHeader(),
131131
request.getInputStream());
132-
return srcReq;
132+
}
133+
134+
public Request createRequest(String method, String uri, String protocol, Header header, InputStream in) {
135+
if (!protocol.startsWith("HTTP/"))
136+
throw new RuntimeException("Unknown protocol '" + protocol + "'");
137+
138+
return new Request.Builder()
139+
.method(method)
140+
.uri(uri)
141+
.header(header)
142+
.body(in)
143+
.version(protocol.substring(5))
144+
.build();
133145
}
134146

135147
private Header createHeader() {

0 commit comments

Comments
 (0)