On Fri, 2021-02-26 at 14:52 +0100, Oleg Kalnichevski wrote: > On Fri, 2021-02-26 at 13:53 +0100, Jochen Wiedmann wrote: > > Hi, I am using the HttpServer class from httpcore5-5.0.3 to > > implement > > a simple HTTP server. I am registering a HttpRequestHandler as > > follows: > > > > ServerBootstrap.bootstrap(). > > ... > > .register("*", myHttpRequestHandler); > > > > I am not invoking > > > > .setLocalAddress(hostName) > > > > on the ServerBootstrap, in the hope, that this will bind to > > 0.0.0.0, > > as it should. > > > > Now, if I am sending a request to http://localhost:8080/uri, > > everything's fine. However, with http://127.0.0.1:8080/uri, I get > > the > > error > > > > "Not authoritative" > > > > Is it possible? (And how?) to fix that? > > > > Thanks, > > > > Jochen > > > > >
Jochen I tweaked RequestHandlerRegistry to resolve 127.0.0.1 as a primary host. Please re-test with the latest snapshot https://github.com/apache/httpcomponents-core/commit/9aac3cb591373ff12f6a2424ac45dbc6cfe19772 Oleg > This sample app works for me. > > ``` > HttpServer server = ServerBootstrap.bootstrap() > .setListenerPort(8080) > .register("*", (request, response, context) -> { > response.setCode(200); > response.setEntity(new StringEntity("blah")); > }) > .create(); > server.start(); > CloseableHttpClient httpClient = HttpClientBuilder.create() > .build(); > try (CloseableHttpResponse response = httpClient.execute(new > HttpGet("http://localhost:8080/"))) { > System.out.println(response.getCode()); > } > httpClient.close(); > server.close(); > ``` > > ``` > 2021-02-26 14:50:54,488 DEBUG > [main][org.apache.hc.client5.http.impl.classic.InternalHttpClient] > ex-00000001: preparing request execution > 2021-02-26 14:50:54,496 DEBUG > [main][org.apache.hc.client5.http.protocol.RequestAddCookies] Cookie > spec selected: strict > 2021-02-26 14:50:54,501 DEBUG > [main][org.apache.hc.client5.http.protocol.RequestAuthCache] Auth > cache not set in the context > 2021-02-26 14:50:54,502 DEBUG > [main][org.apache.hc.client5.http.impl.classic.ProtocolExec] ex- > 00000001: target auth state: UNCHALLENGED > 2021-02-26 14:50:54,502 DEBUG > [main][org.apache.hc.client5.http.impl.classic.ProtocolExec] ex- > 00000001: proxy auth state: UNCHALLENGED > 2021-02-26 14:50:54,503 DEBUG > [main][org.apache.hc.client5.http.impl.classic.ConnectExec] ex- > 00000001: acquiring connection with route {}->http://localhost:8080 > 2021-02-26 14:50:54,503 DEBUG > [main][org.apache.hc.client5.http.impl.classic.InternalHttpClient] > ex-00000001: acquiring endpoint (3 MINUTES) > 2021-02-26 14:50:54,504 DEBUG > [main][org.apache.hc.client5.http.impl.io.PoolingHttpClientConnection > Manager] ex-00000001: endpoint lease request (3 MINUTES) [route: {}-> > http://localhost:8080][total available: 0; route allocated: 0 of 5; > total allocated: 0 of 25] > 2021-02-26 14:50:54,510 DEBUG > [main][org.apache.hc.client5.http.impl.io.PoolingHttpClientConnection > Manager] ex-00000001: endpoint leased [route: {}-> > http://localhost:8080][total available: 0; route allocated: 1 of 5; > total allocated: 1 of 25] > 2021-02-26 14:50:54,520 DEBUG > [main][org.apache.hc.client5.http.impl.io.PoolingHttpClientConnection > Manager] ex-00000001: acquired ep-00000000 > 2021-02-26 14:50:54,521 DEBUG > [main][org.apache.hc.client5.http.impl.classic.InternalHttpClient] > ex-00000001: acquired endpoint ep-00000000 > 2021-02-26 14:50:54,521 DEBUG > [main][org.apache.hc.client5.http.impl.classic.ConnectExec] ex- > 00000001: opening connection {}->http://localhost:8080 > 2021-02-26 14:50:54,522 DEBUG > [main][org.apache.hc.client5.http.impl.classic.InternalHttpClient] > ep-00000000: connecting endpoint (3 MINUTES) > 2021-02-26 14:50:54,522 DEBUG > [main][org.apache.hc.client5.http.impl.io.PoolingHttpClientConnection > Manager] ep-00000000: connecting endpoint to http://localhost:8080 (3 > MINUTES) > 2021-02-26 14:50:54,523 DEBUG > [main][org.apache.hc.client5.http.impl.io.DefaultHttpClientConnection > Operator] http-outgoing-0: connecting to localhost/127.0.0.1:8080 > 2021-02-26 14:50:54,524 DEBUG > [main][org.apache.hc.client5.http.impl.io.DefaultHttpClientConnection > Operator] http-outgoing-0: connection established 127.0.0.1:44124<- > >127.0.0.1:8080 > 2021-02-26 14:50:54,524 DEBUG > [main][org.apache.hc.client5.http.impl.io.PoolingHttpClientConnection > Manager] ep-00000000: connected http-outgoing-0 > 2021-02-26 14:50:54,524 DEBUG > [main][org.apache.hc.client5.http.impl.classic.InternalHttpClient] > ep-00000000: endpoint connected > 2021-02-26 14:50:54,525 DEBUG > [main][org.apache.hc.client5.http.impl.classic.MainClientExec] ex- > 00000001: executing GET / HTTP/1.1 > 2021-02-26 14:50:54,525 DEBUG > [main][org.apache.hc.client5.http.impl.classic.InternalHttpClient] > ep-00000000: start execution ex-00000001 > 2021-02-26 14:50:54,526 DEBUG > [main][org.apache.hc.client5.http.impl.io.PoolingHttpClientConnection > Manager] ep-00000000: executing exchange ex-00000001 over http- > outgoing-0 > 2021-02-26 14:50:54,527 DEBUG > [main][org.apache.hc.client5.http.headers] http-outgoing-0 >> GET / > HTTP/1.1 > 2021-02-26 14:50:54,527 DEBUG > [main][org.apache.hc.client5.http.headers] http-outgoing-0 >> Accept- > Encoding: gzip, x-gzip, deflate > 2021-02-26 14:50:54,527 DEBUG > [main][org.apache.hc.client5.http.headers] http-outgoing-0 >> Host: > localhost:8080 > 2021-02-26 14:50:54,527 DEBUG > [main][org.apache.hc.client5.http.headers] http-outgoing-0 >> > Connection: keep-alive > 2021-02-26 14:50:54,527 DEBUG > [main][org.apache.hc.client5.http.headers] http-outgoing-0 >> User- > Agent: Apache-HttpClient/5.0.3 (Java/1.8.0_251) > 2021-02-26 14:50:54,546 DEBUG > [main][org.apache.hc.client5.http.headers] http-outgoing-0 << > HTTP/1.1 200 OK > 2021-02-26 14:50:54,546 DEBUG > [main][org.apache.hc.client5.http.headers] http-outgoing-0 << Date: > Fri, 26 Feb 2021 13:50:54 GMT > 2021-02-26 14:50:54,546 DEBUG > [main][org.apache.hc.client5.http.headers] http-outgoing-0 << Server: > Apache-HttpCore/5.0.3 (Java/1.8.0_251) > 2021-02-26 14:50:54,546 DEBUG > [main][org.apache.hc.client5.http.headers] http-outgoing-0 << > Content-Length: 4 > 2021-02-26 14:50:54,546 DEBUG > [main][org.apache.hc.client5.http.headers] http-outgoing-0 << > Content-Type: text/plain; charset=ISO-8859-1 > 2021-02-26 14:50:54,546 DEBUG > [main][org.apache.hc.client5.http.headers] http-outgoing-0 << > Connection: keep-alive > 2021-02-26 14:50:54,547 DEBUG > [main][org.apache.hc.client5.http.impl.classic.MainClientExec] ex- > 00000001: connection can be kept alive for 3 MINUTES > 2021-02-26 14:50:54,550 DEBUG > [main][org.apache.hc.client5.http.impl.io.DefaultManagedHttpClientCon > nection] http-outgoing-0: close connection GRACEFUL > 2021-02-26 14:50:54,550 DEBUG > [main][org.apache.hc.client5.http.impl.classic.InternalHttpClient] > ep-00000000: endpoint closed > 2021-02-26 14:50:54,550 DEBUG > [main][org.apache.hc.client5.http.impl.classic.InternalHttpClient] > ep-00000000: endpoint closed > 2021-02-26 14:50:54,550 DEBUG > [main][org.apache.hc.client5.http.impl.classic.InternalHttpClient] > ep-00000000: discarding endpoint > 2021-02-26 14:50:54,550 DEBUG > [main][org.apache.hc.client5.http.impl.io.PoolingHttpClientConnection > Manager] ep-00000000: releasing endpoint > 2021-02-26 14:50:54,550 DEBUG > [main][org.apache.hc.client5.http.impl.io.PoolingHttpClientConnection > Manager] ep-00000000: connection is not kept alive > 2021-02-26 14:50:54,550 DEBUG > [main][org.apache.hc.client5.http.impl.io.PoolingHttpClientConnection > Manager] ep-00000000: connection released [route: {}-> > http://localhost:8080][total available: 0; route allocated: 0 of 5; > total allocated: 0 of 25] > 2021-02-26 14:50:54,551 DEBUG > [main][org.apache.hc.client5.http.impl.io.PoolingHttpClientConnection > Manager] Shutdown connection pool GRACEFUL > 2021-02-26 14:50:54,551 DEBUG > [main][org.apache.hc.client5.http.impl.io.PoolingHttpClientConnection > Manager] Connection pool shut down > ``` > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org > For additional commands, e-mail: httpclient-users-h...@hc.apache.org > --------------------------------------------------------------------- To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org For additional commands, e-mail: httpclient-users-h...@hc.apache.org