|
| 1 | +/* |
| 2 | + * Copyright (c) 2016 AsyncHttpClient Project. All rights reserved. |
| 3 | + * |
| 4 | + * This program is licensed to you under the Apache License Version 2.0, |
| 5 | + * and you may not use this file except in compliance with the Apache License Version 2.0. |
| 6 | + * You may obtain a copy of the Apache License Version 2.0 at |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0. |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, |
| 10 | + * software distributed under the Apache License Version 2.0 is distributed on an |
| 11 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | + * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. |
| 13 | + */ |
| 14 | +package org.asynchttpclient; |
| 15 | + |
| 16 | +import io.netty.util.internal.SocketUtils; |
| 17 | +import org.asynchttpclient.test.TestUtils.AsyncCompletionHandlerAdapter; |
| 18 | +import org.asynchttpclient.testserver.HttpServer; |
| 19 | +import org.asynchttpclient.testserver.HttpTest; |
| 20 | +import org.testng.annotations.AfterClass; |
| 21 | +import org.testng.annotations.BeforeClass; |
| 22 | +import org.testng.annotations.Test; |
| 23 | + |
| 24 | +import static java.util.concurrent.TimeUnit.SECONDS; |
| 25 | +import static org.asynchttpclient.Dsl.get; |
| 26 | +import static org.asynchttpclient.test.TestUtils.TIMEOUT; |
| 27 | +import static org.testng.Assert.assertEquals; |
| 28 | + |
| 29 | +public class CustomRemoteAddressTest extends HttpTest { |
| 30 | + |
| 31 | + private static HttpServer server; |
| 32 | + |
| 33 | + @BeforeClass |
| 34 | + public static void start() throws Throwable { |
| 35 | + server = new HttpServer(); |
| 36 | + server.start(); |
| 37 | + } |
| 38 | + |
| 39 | + @AfterClass |
| 40 | + public static void stop() throws Throwable { |
| 41 | + server.close(); |
| 42 | + } |
| 43 | + |
| 44 | + @Test |
| 45 | + public void getRootUrlWithCustomRemoteAddress() throws Throwable { |
| 46 | + withClient().run(client -> |
| 47 | + withServer(server).run(server -> { |
| 48 | + String url = server.getHttpUrl(); |
| 49 | + server.enqueueOk(); |
| 50 | + RequestBuilder request = get(url).setAddress(SocketUtils.addressByName("localhost")); |
| 51 | + Response response = client.executeRequest(request, new AsyncCompletionHandlerAdapter()).get(TIMEOUT, SECONDS); |
| 52 | + assertEquals(response.getStatusCode(), 200); |
| 53 | + })); |
| 54 | + } |
| 55 | +} |
0 commit comments