Skip to content

Commit a84ab6c

Browse files
committed
removed un wanted comments
1 parent 2217238 commit a84ab6c

File tree

1 file changed

+18
-78
lines changed

1 file changed

+18
-78
lines changed

src/main/java/io/vertx/httpproxy/impl/ProxiedRequest.java

Lines changed: 18 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -232,140 +232,80 @@ public Future<ProxyResponse> send(HttpClientRequest request) {
232232
return promise.future();
233233
}
234234

235-
236-
/**
237-
* Transforms the request path by adding a prefix.
238-
*
239-
* @param prefix The prefix to add to the request path
240-
* @return This ProxiedRequest instance for method chaining
241-
*/
242-
public io.vertx.httpproxy.impl.ProxiedRequest addPathPrefix(String prefix) {
235+
public ProxiedRequest addPathPrefix(String prefix) {
243236
this.uri = prefix + this.uri;
244237
return this;
245238
}
246239

247-
/**
248-
* Transforms the request path by removing a prefix.
249-
*
250-
* @param prefix The prefix to remove from the request path
251-
* @return This ProxiedRequest instance for method chaining
252-
*/
253-
public io.vertx.httpproxy.impl.ProxiedRequest removePathPrefix(String prefix) {
240+
public ProxiedRequest removePathPrefix(String prefix) {
254241
if (this.uri.startsWith(prefix)) {
255242
this.uri = this.uri.substring(prefix.length());
256243
}
257244
return this;
258245
}
259246

260-
/**
261-
* Transforms query parameters into path parameters.
262-
*
263-
* @return This ProxiedRequest instance for method chaining
264-
*/
265-
public io.vertx.httpproxy.impl.ProxiedRequest transformQueryToPathParams() {
266-
// Parse the original URI to extract query parameters
247+
public ProxiedRequest transformQueryToPathParams() {
267248
URI originalUri = URI.create(this.uri);
268249
String originalPath = originalUri.getPath();
269250
String query = originalUri.getQuery();
270-
271-
// If there are query parameters, construct a new URI with them moved to the path
272251
if (query != null && !query.isEmpty()) {
273252
Map<String, String> queryParams = new HashMap<>();
274253
for (String param : query.split("&")) {
275254
String[] pair = param.split("=");
276255
queryParams.put(pair[0], pair[1]);
277256
}
278-
279-
// Reconstruct the path with query parameters replaced by path parameters
280257
StringBuilder newPath = new StringBuilder(originalPath);
281258
for (Map.Entry<String, String> entry : queryParams.entrySet()) {
282259
newPath.append("/").append(entry.getValue());
283260
}
284-
285-
// Update the uri field with the new path
286261
this.uri = newPath.toString();
287262
}
288-
289263
return this;
290264
}
291265

292-
293-
/**
294-
* Adds a header to the request.
295-
*
296-
* @param name The name of the header
297-
* @param value The value of the header
298-
* @return This ProxiedRequest instance for method chaining
299-
*/
300-
public io.vertx.httpproxy.impl.ProxiedRequest addHeader(String name, String value) {
266+
public ProxiedRequest addHeader(String name, String value) {
301267
this.headers.add(name, value);
302268
return this;
303269
}
304270

305-
/**
306-
* Removes a header from the request.
307-
*
308-
* @param name The name of the header to remove
309-
* @return This ProxiedRequest instance for method chaining
310-
*/
311-
public io.vertx.httpproxy.impl.ProxiedRequest removeHeader(String name) {
271+
public ProxiedRequest removeHeader(String name) {
312272
this.headers.remove(name);
313273
return this;
314274
}
315275

316-
/**
317-
* Modifies the value of a header.
318-
*
319-
* @param name The name of the header to modify
320-
* @param newVal The new value of the header
321-
* @return This ProxiedRequest instance for method chaining
322-
*/
323276
public ProxiedRequest modifyHeader(String name, String newVal) {
324277
this.headers.set(name, newVal);
325278
return this;
326279
}
327280

328-
/**
329-
* Modifies the request body by reading JSON fully and modifying specified fields.
330-
*
331-
* @param jsonObject A JsonObject containing fields to update and their new values
332-
* @return This ProxiedRequest instance for method chaining
333-
*/
334281
public ProxiedRequest setBody(JsonObject jsonObject) {
335-
// Buffer newBody = Buffer.buffer(jsonObject.encode());
336-
// ModifiedHttpServerRequest mr = new ModifiedHttpServerRequest(proxiedRequest, newBody);
337-
// body = Body.body(mr, newBody.length()+body.length());
338-
// Buffer modifiedBuffer = Buffer.buffer(jsonObject.encode());
339-
// this.body = Body.body(new BufferingReadStream(body.stream(), modifiedBuffer), body.length()+modifiedBuffer.length());
340282
body = Body.body(jsonObject.toBuffer());
341283
return this;
342284
}
343285

344-
/**
345-
* Retrieves the body content as a JSON object.
346-
*
347-
* @param resultHandler The handler to be called when the operation completes
348-
*/
349286
public void getBodyAsJson(Handler<JsonObject> resultHandler) {
350-
if (body != null) {
351-
BufferingWriteStream ws = new BufferingWriteStream();
352-
body.stream().pipeTo(ws, h->{
353-
if(h.succeeded()){
354-
resultHandler.handle(ws.content().toJsonObject());
287+
long len = body.length();
288+
if (body != null && len >=0) {
289+
BufferingWriteStream buffer = new BufferingWriteStream();
290+
body.stream().pipeTo(buffer).onComplete( ar->{
291+
if(ar.succeeded()){
292+
resultHandler.handle(buffer.content().toJsonObject());
293+
} else {
294+
System.out.println("not implemented");
355295
}
356296
});
357297
}
358298
}
359299

360300
public Future<JsonObject> getBodyAsJson() {
361301
Promise<JsonObject> promise = Promise.promise();
302+
long len = body.length();
303+
if (body != null && len >= 0) {
304+
BufferingWriteStream buffer = new BufferingWriteStream();
362305

363-
if (body != null && body.length()>0) {
364-
BufferingWriteStream ws = new BufferingWriteStream();
365-
366-
body.stream().pipeTo(ws, ar -> {
306+
body.stream().pipeTo(buffer).onComplete( ar -> {
367307
if (ar.succeeded()) {
368-
JsonObject jsonObject = ws.content().toJsonObject();
308+
JsonObject jsonObject = buffer.content().toJsonObject();
369309
promise.complete(jsonObject);
370310
} else {
371311
promise.fail(ar.cause());

0 commit comments

Comments
 (0)