1
- /*
2
- * Copyright (c) 2011-2019 Contributors to the Eclipse Foundation
3
- *
4
- * This program and the accompanying materials are made available under the
5
- * terms of the Eclipse Public License 2.0 which is available at
6
- * http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7
- * which is available at https://www.apache.org/licenses/LICENSE-2.0.
8
- *
9
- * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
10
- */
11
- package top .meethigher .proxy .tcp ;
1
+ package top .meethigher .proxy ;
12
2
13
3
import io .vertx .core .*;
4
+ import io .vertx .core .http .HttpClientResponse ;
5
+ import io .vertx .core .http .HttpServerRequest ;
14
6
import io .vertx .core .net .NetSocket ;
15
7
import io .vertx .core .streams .ReadStream ;
16
8
import io .vertx .core .streams .WriteStream ;
17
9
import org .slf4j .Logger ;
18
10
import org .slf4j .LoggerFactory ;
19
11
12
+ /**
13
+ * 在io.vertx.core.streams.impl.PipeImpl
14
+ */
20
15
public class Pipe <T > implements io .vertx .core .streams .Pipe <T > {
21
16
22
17
private static final Logger log = LoggerFactory .getLogger (Pipe .class );
@@ -29,11 +24,18 @@ public class Pipe<T> implements io.vertx.core.streams.Pipe<T> {
29
24
public Pipe (ReadStream <T > src ) {
30
25
this .src = src ;
31
26
this .result = Promise .promise ();
32
-
33
27
if (src instanceof NetSocket ) {
34
28
NetSocket tsrc = (NetSocket ) src ;
35
29
tsrc .remoteAddress ();
36
30
tsrc .localAddress ();
31
+ } else if (src instanceof HttpServerRequest ) {
32
+ HttpServerRequest req = (HttpServerRequest ) src ;
33
+ req .connection ().remoteAddress ();
34
+ req .connection ().localAddress ();
35
+ } else if (src instanceof HttpClientResponse ) {
36
+ HttpClientResponse resp = (HttpClientResponse ) src ;
37
+ resp .request ().connection ().remoteAddress ();
38
+ resp .request ().connection ().localAddress ();
37
39
}
38
40
39
41
// Set handlers now
@@ -85,7 +87,19 @@ public void to(WriteStream<T> ws, Handler<AsyncResult<Void>> completionHandler)
85
87
src .handler (item -> {
86
88
if (src instanceof NetSocket ) {
87
89
NetSocket tsrc = (NetSocket ) src ;
88
- log .info ("{} -- {} received:\n {}" , tsrc .remoteAddress (), tsrc .localAddress (),
90
+ log .trace ("{} -- {} received:\n {}" , tsrc .remoteAddress (), tsrc .localAddress (),
91
+ item .toString ());
92
+ } else if (src instanceof HttpServerRequest ) {
93
+ HttpServerRequest req = (HttpServerRequest ) src ;
94
+ log .trace ("{} -- {} received:\n {}" ,
95
+ req .connection ().remoteAddress (),
96
+ req .connection ().localAddress (),
97
+ item .toString ());
98
+ } else if (src instanceof HttpClientResponse ) {
99
+ HttpClientResponse resp = (HttpClientResponse ) src ;
100
+ log .trace ("{} -- {} received:\n {}" ,
101
+ resp .request ().connection ().remoteAddress (),
102
+ resp .request ().connection ().localAddress (),
89
103
item .toString ());
90
104
}
91
105
ws .write (item , this ::handleWriteResult );
0 commit comments