├── .github └── workflows │ ├── builds.yml │ ├── maven.yml │ └── release.yml ├── .gitignore ├── .mvn ├── jvm.config └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── CHANGES.md ├── LICENSE.txt ├── LICENSES └── LICENSE.zstd-jni.txt ├── README.md ├── client ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── asynchttpclient │ │ │ ├── AsyncCompletionHandler.java │ │ │ ├── AsyncCompletionHandlerBase.java │ │ │ ├── AsyncHandler.java │ │ │ ├── AsyncHttpClient.java │ │ │ ├── AsyncHttpClientConfig.java │ │ │ ├── AsyncHttpClientState.java │ │ │ ├── BoundRequestBuilder.java │ │ │ ├── ClientStats.java │ │ │ ├── DefaultAsyncHttpClient.java │ │ │ ├── DefaultAsyncHttpClientConfig.java │ │ │ ├── DefaultRequest.java │ │ │ ├── Dsl.java │ │ │ ├── HostStats.java │ │ │ ├── HttpResponseBodyPart.java │ │ │ ├── HttpResponseStatus.java │ │ │ ├── ListenableFuture.java │ │ │ ├── Param.java │ │ │ ├── Realm.java │ │ │ ├── Request.java │ │ │ ├── RequestBuilder.java │ │ │ ├── RequestBuilderBase.java │ │ │ ├── Response.java │ │ │ ├── SignatureCalculator.java │ │ │ ├── SslEngineFactory.java │ │ │ ├── channel │ │ │ ├── ChannelPool.java │ │ │ ├── ChannelPoolPartitioning.java │ │ │ ├── DefaultKeepAliveStrategy.java │ │ │ ├── KeepAliveStrategy.java │ │ │ └── NoopChannelPool.java │ │ │ ├── config │ │ │ ├── AsyncHttpClientConfigDefaults.java │ │ │ └── AsyncHttpClientConfigHelper.java │ │ │ ├── cookie │ │ │ ├── CookieEvictionTask.java │ │ │ ├── CookieStore.java │ │ │ └── ThreadSafeCookieStore.java │ │ │ ├── exception │ │ │ ├── ChannelClosedException.java │ │ │ ├── FilterException.java │ │ │ ├── PoolAlreadyClosedException.java │ │ │ ├── RemotelyClosedException.java │ │ │ ├── TooManyConnectionsException.java │ │ │ └── TooManyConnectionsPerHostException.java │ │ │ ├── filter │ │ │ ├── FilterContext.java │ │ │ ├── IOExceptionFilter.java │ │ │ ├── ReleasePermitOnComplete.java │ │ │ ├── RequestFilter.java │ │ │ ├── ResponseFilter.java │ │ │ └── ThrottleRequestFilter.java │ │ │ ├── handler │ │ │ ├── BodyDeferringAsyncHandler.java │ │ │ ├── MaxRedirectException.java │ │ │ ├── ProgressAsyncHandler.java │ │ │ ├── TransferCompletionHandler.java │ │ │ ├── TransferListener.java │ │ │ └── resumable │ │ │ │ ├── PropertiesBasedResumableProcessor.java │ │ │ │ ├── ResumableAsyncHandler.java │ │ │ │ ├── ResumableIOExceptionFilter.java │ │ │ │ ├── ResumableListener.java │ │ │ │ └── ResumableRandomAccessFileListener.java │ │ │ ├── netty │ │ │ ├── DiscardEvent.java │ │ │ ├── EagerResponseBodyPart.java │ │ │ ├── LazyResponseBodyPart.java │ │ │ ├── NettyResponse.java │ │ │ ├── NettyResponseFuture.java │ │ │ ├── NettyResponseStatus.java │ │ │ ├── OnLastHttpContentCallback.java │ │ │ ├── SimpleChannelFutureListener.java │ │ │ ├── SimpleFutureListener.java │ │ │ ├── channel │ │ │ │ ├── ChannelManager.java │ │ │ │ ├── ChannelState.java │ │ │ │ ├── Channels.java │ │ │ │ ├── CombinedConnectionSemaphore.java │ │ │ │ ├── ConnectionSemaphore.java │ │ │ │ ├── ConnectionSemaphoreFactory.java │ │ │ │ ├── DefaultChannelPool.java │ │ │ │ ├── DefaultConnectionSemaphoreFactory.java │ │ │ │ ├── EpollTransportFactory.java │ │ │ │ ├── InfiniteSemaphore.java │ │ │ │ ├── IoUringIncubatorTransportFactory.java │ │ │ │ ├── KQueueTransportFactory.java │ │ │ │ ├── MaxConnectionSemaphore.java │ │ │ │ ├── NettyChannelConnector.java │ │ │ │ ├── NettyConnectListener.java │ │ │ │ ├── NioTransportFactory.java │ │ │ │ ├── NoopConnectionSemaphore.java │ │ │ │ ├── PerHostConnectionSemaphore.java │ │ │ │ └── TransportFactory.java │ │ │ ├── future │ │ │ │ └── StackTraceInspector.java │ │ │ ├── handler │ │ │ │ ├── AsyncHttpClientHandler.java │ │ │ │ ├── HttpHandler.java │ │ │ │ ├── WebSocketHandler.java │ │ │ │ └── intercept │ │ │ │ │ ├── ConnectSuccessInterceptor.java │ │ │ │ │ ├── Continue100Interceptor.java │ │ │ │ │ ├── Interceptors.java │ │ │ │ │ ├── ProxyUnauthorized407Interceptor.java │ │ │ │ │ ├── Redirect30xInterceptor.java │ │ │ │ │ ├── ResponseFiltersInterceptor.java │ │ │ │ │ └── Unauthorized401Interceptor.java │ │ │ ├── request │ │ │ │ ├── NettyRequest.java │ │ │ │ ├── NettyRequestFactory.java │ │ │ │ ├── NettyRequestSender.java │ │ │ │ ├── WriteCompleteListener.java │ │ │ │ ├── WriteListener.java │ │ │ │ ├── WriteProgressListener.java │ │ │ │ └── body │ │ │ │ │ ├── BodyChunkedInput.java │ │ │ │ │ ├── BodyFileRegion.java │ │ │ │ │ ├── NettyBody.java │ │ │ │ │ ├── NettyBodyBody.java │ │ │ │ │ ├── NettyByteArrayBody.java │ │ │ │ │ ├── NettyByteBufBody.java │ │ │ │ │ ├── NettyByteBufferBody.java │ │ │ │ │ ├── NettyCompositeByteArrayBody.java │ │ │ │ │ ├── NettyDirectBody.java │ │ │ │ │ ├── NettyFileBody.java │ │ │ │ │ ├── NettyInputStreamBody.java │ │ │ │ │ └── NettyMultipartBody.java │ │ │ ├── ssl │ │ │ │ ├── DefaultSslEngineFactory.java │ │ │ │ ├── JsseSslEngineFactory.java │ │ │ │ └── SslEngineFactoryBase.java │ │ │ ├── timeout │ │ │ │ ├── ReadTimeoutTimerTask.java │ │ │ │ ├── RequestTimeoutTimerTask.java │ │ │ │ ├── TimeoutTimerTask.java │ │ │ │ └── TimeoutsHolder.java │ │ │ └── ws │ │ │ │ └── NettyWebSocket.java │ │ │ ├── ntlm │ │ │ ├── NtlmEngine.java │ │ │ └── NtlmEngineException.java │ │ │ ├── proxy │ │ │ ├── ProxyServer.java │ │ │ ├── ProxyServerSelector.java │ │ │ └── ProxyType.java │ │ │ ├── request │ │ │ └── body │ │ │ │ ├── Body.java │ │ │ │ ├── RandomAccessBody.java │ │ │ │ ├── generator │ │ │ │ ├── BodyChunk.java │ │ │ │ ├── BodyGenerator.java │ │ │ │ ├── BoundedQueueFeedableBodyGenerator.java │ │ │ │ ├── ByteArrayBodyGenerator.java │ │ │ │ ├── FeedListener.java │ │ │ │ ├── FeedableBodyGenerator.java │ │ │ │ ├── FileBodyGenerator.java │ │ │ │ ├── InputStreamBodyGenerator.java │ │ │ │ ├── PushBody.java │ │ │ │ ├── QueueBasedFeedableBodyGenerator.java │ │ │ │ └── UnboundedQueueFeedableBodyGenerator.java │ │ │ │ └── multipart │ │ │ │ ├── ByteArrayPart.java │ │ │ │ ├── FileLikePart.java │ │ │ │ ├── FilePart.java │ │ │ │ ├── InputStreamPart.java │ │ │ │ ├── MultipartBody.java │ │ │ │ ├── MultipartUtils.java │ │ │ │ ├── Part.java │ │ │ │ ├── PartBase.java │ │ │ │ ├── StringPart.java │ │ │ │ └── part │ │ │ │ ├── ByteArrayMultipartPart.java │ │ │ │ ├── FileLikeMultipartPart.java │ │ │ │ ├── FileMultipartPart.java │ │ │ │ ├── InputStreamMultipartPart.java │ │ │ │ ├── MessageEndMultipartPart.java │ │ │ │ ├── MultipartPart.java │ │ │ │ ├── MultipartState.java │ │ │ │ ├── PartVisitor.java │ │ │ │ └── StringMultipartPart.java │ │ │ ├── resolver │ │ │ └── RequestHostnameResolver.java │ │ │ ├── spnego │ │ │ ├── NamePasswordCallbackHandler.java │ │ │ ├── SpnegoEngine.java │ │ │ ├── SpnegoEngineException.java │ │ │ └── SpnegoTokenGenerator.java │ │ │ ├── uri │ │ │ ├── Uri.java │ │ │ └── UriParser.java │ │ │ ├── util │ │ │ ├── Assertions.java │ │ │ ├── AuthenticatorUtils.java │ │ │ ├── Counted.java │ │ │ ├── DateUtils.java │ │ │ ├── EnsuresNonNull.java │ │ │ ├── HttpConstants.java │ │ │ ├── HttpUtils.java │ │ │ ├── MessageDigestUtils.java │ │ │ ├── MiscUtils.java │ │ │ ├── ProxyUtils.java │ │ │ ├── StringBuilderPool.java │ │ │ ├── StringUtils.java │ │ │ ├── ThrowableUtil.java │ │ │ ├── UriEncoder.java │ │ │ └── Utf8UrlEncoder.java │ │ │ └── ws │ │ │ ├── WebSocket.java │ │ │ ├── WebSocketListener.java │ │ │ ├── WebSocketUpgradeHandler.java │ │ │ └── WebSocketUtils.java │ └── resources │ │ └── org │ │ └── asynchttpclient │ │ ├── config │ │ ├── ahc-default.properties │ │ └── ahc-version.properties │ │ └── request │ │ └── body │ │ └── multipart │ │ └── ahc-mime.types │ └── test │ ├── java │ └── org │ │ ├── apache │ │ └── commons │ │ │ └── fileupload2 │ │ │ ├── FileItem.java │ │ │ ├── FileItemFactory.java │ │ │ ├── FileItemHeaders.java │ │ │ ├── FileItemHeadersSupport.java │ │ │ ├── FileItemIterator.java │ │ │ ├── FileItemStream.java │ │ │ ├── FileUpload.java │ │ │ ├── FileUploadBase.java │ │ │ ├── FileUploadException.java │ │ │ ├── InvalidFileNameException.java │ │ │ ├── MultipartStream.java │ │ │ ├── ParameterParser.java │ │ │ ├── ProgressListener.java │ │ │ ├── RequestContext.java │ │ │ ├── UploadContext.java │ │ │ ├── disk │ │ │ ├── DiskFileItem.java │ │ │ ├── DiskFileItemFactory.java │ │ │ └── package-info.java │ │ │ ├── impl │ │ │ ├── FileItemIteratorImpl.java │ │ │ ├── FileItemStreamImpl.java │ │ │ └── package-info.java │ │ │ ├── jaksrvlt │ │ │ ├── JakSrvltFileCleaner.java │ │ │ ├── JakSrvltFileUpload.java │ │ │ ├── JakSrvltRequestContext.java │ │ │ └── package-info.java │ │ │ ├── package-info.java │ │ │ ├── portlet │ │ │ ├── PortletFileUpload.java │ │ │ ├── PortletRequestContext.java │ │ │ └── package-info.java │ │ │ ├── pub │ │ │ ├── FileSizeLimitExceededException.java │ │ │ ├── FileUploadIOException.java │ │ │ ├── IOFileUploadException.java │ │ │ ├── InvalidContentTypeException.java │ │ │ ├── SizeException.java │ │ │ ├── SizeLimitExceededException.java │ │ │ └── package-info.java │ │ │ ├── servlet │ │ │ ├── FileCleanerCleanup.java │ │ │ ├── ServletFileUpload.java │ │ │ ├── ServletRequestContext.java │ │ │ └── package-info.java │ │ │ └── util │ │ │ ├── Closeable.java │ │ │ ├── FileItemHeadersImpl.java │ │ │ ├── LimitedInputStream.java │ │ │ ├── Streams.java │ │ │ ├── mime │ │ │ ├── Base64Decoder.java │ │ │ ├── MimeUtility.java │ │ │ ├── ParseException.java │ │ │ ├── QuotedPrintableDecoder.java │ │ │ ├── RFC2231Utility.java │ │ │ └── package-info.java │ │ │ └── package-info.java │ │ └── asynchttpclient │ │ ├── AbstractBasicTest.java │ │ ├── AsyncHttpClientDefaultsTest.java │ │ ├── AsyncStreamHandlerTest.java │ │ ├── AsyncStreamLifecycleTest.java │ │ ├── AuthTimeoutTest.java │ │ ├── AutomaticDecompressionTest.java │ │ ├── BasicAuthTest.java │ │ ├── BasicHttpProxyToHttpTest.java │ │ ├── BasicHttpProxyToHttpsTest.java │ │ ├── BasicHttpTest.java │ │ ├── BasicHttpsTest.java │ │ ├── ByteBufferCapacityTest.java │ │ ├── ClientStatsTest.java │ │ ├── ComplexClientTest.java │ │ ├── CookieStoreTest.java │ │ ├── CustomRemoteAddressTest.java │ │ ├── DefaultAsyncHttpClientConfigTest.java │ │ ├── DefaultAsyncHttpClientTest.java │ │ ├── DigestAuthTest.java │ │ ├── EofTerminatedTest.java │ │ ├── ErrorResponseTest.java │ │ ├── Expect100ContinueTest.java │ │ ├── FollowingThreadTest.java │ │ ├── Head302Test.java │ │ ├── HttpToHttpsRedirectTest.java │ │ ├── IdleStateHandlerTest.java │ │ ├── ListenableFutureTest.java │ │ ├── MultipleHeaderTest.java │ │ ├── NoNullResponseTest.java │ │ ├── NonAsciiContentLengthTest.java │ │ ├── ParamEncodingTest.java │ │ ├── PerRequestRelative302Test.java │ │ ├── PerRequestTimeoutTest.java │ │ ├── PostRedirectGetTest.java │ │ ├── PostWithQueryStringTest.java │ │ ├── QueryParametersTest.java │ │ ├── RC1KTest.java │ │ ├── RealmTest.java │ │ ├── RedirectBodyTest.java │ │ ├── RedirectConnectionUsageTest.java │ │ ├── Relative302Test.java │ │ ├── RequestBuilderTest.java │ │ ├── RetryRequestTest.java │ │ ├── StripAuthorizationOnRedirectHttpTest.java │ │ ├── ThreadNameTest.java │ │ ├── channel │ │ ├── ConnectionPoolTest.java │ │ ├── MaxConnectionsInThreadsTest.java │ │ └── MaxTotalConnectionTest.java │ │ ├── filter │ │ └── FilterTest.java │ │ ├── handler │ │ ├── BodyDeferringAsyncHandlerTest.java │ │ └── resumable │ │ │ ├── MapResumableProcessor.java │ │ │ ├── PropertiesBasedResumableProcessorTest.java │ │ │ ├── ResumableAsyncHandlerTest.java │ │ │ └── ResumableRandomAccessFileListenerTest.java │ │ ├── netty │ │ ├── EventPipelineTest.java │ │ ├── NettyAsyncResponseTest.java │ │ ├── NettyConnectionResetByPeerTest.java │ │ ├── NettyRequestThrottleTimeoutTest.java │ │ ├── NettyResponseFutureTest.java │ │ ├── NettyTest.java │ │ ├── RetryNonBlockingIssueTest.java │ │ ├── TimeToLiveIssueTest.java │ │ └── channel │ │ │ ├── SemaphoreRunner.java │ │ │ └── SemaphoreTest.java │ │ ├── ntlm │ │ └── NtlmTest.java │ │ ├── proxy │ │ ├── CustomHeaderProxyTest.java │ │ ├── HttpsProxyTest.java │ │ ├── NTLMProxyTest.java │ │ └── ProxyTest.java │ │ ├── request │ │ └── body │ │ │ ├── BodyChunkTest.java │ │ │ ├── ChunkingTest.java │ │ │ ├── EmptyBodyTest.java │ │ │ ├── FilePartLargeFileTest.java │ │ │ ├── InputStreamPartLargeFileTest.java │ │ │ ├── InputStreamTest.java │ │ │ ├── PutByteBufTest.java │ │ │ ├── PutFileTest.java │ │ │ ├── TransferListenerTest.java │ │ │ ├── ZeroCopyFileTest.java │ │ │ ├── generator │ │ │ ├── ByteArrayBodyGeneratorTest.java │ │ │ └── FeedableBodyGeneratorTest.java │ │ │ └── multipart │ │ │ ├── MultipartBasicAuthTest.java │ │ │ ├── MultipartBodyTest.java │ │ │ ├── MultipartUploadTest.java │ │ │ └── part │ │ │ └── MultipartPartTest.java │ │ ├── spnego │ │ └── SpnegoEngineTest.java │ │ ├── test │ │ ├── EchoHandler.java │ │ ├── EventCollectingHandler.java │ │ ├── Slf4jJuliLog.java │ │ └── TestUtils.java │ │ ├── testserver │ │ ├── HttpServer.java │ │ ├── HttpTest.java │ │ └── SocksProxy.java │ │ ├── uri │ │ ├── UriParserTest.java │ │ └── UriTest.java │ │ ├── util │ │ ├── HttpUtilsTest.java │ │ └── Utf8UrlEncoderTest.java │ │ └── ws │ │ ├── AbstractBasicWebSocketTest.java │ │ ├── ByteMessageTest.java │ │ ├── CloseCodeReasonMessageTest.java │ │ ├── EchoWebSocket.java │ │ ├── ProxyTunnellingTest.java │ │ ├── RedirectTest.java │ │ ├── TextMessageTest.java │ │ └── WebSocketWriteFutureTest.java │ └── resources │ ├── 300k.png │ ├── META-INF │ └── services │ │ └── org.apache.juli.logging.Log │ ├── SimpleTextFile.txt │ ├── client.keystore │ ├── empty.txt │ ├── gzip.txt.gz │ ├── kerberos.jaas │ ├── logback-test.xml │ ├── realm.properties │ ├── ssltest-cacerts.jks │ ├── ssltest-keystore.jks │ ├── test_sample_message.eml │ ├── textfile.txt │ └── textfile2.txt ├── mvnw ├── mvnw.cmd └── pom.xml /.github/workflows/builds.yml: -------------------------------------------------------------------------------- 1 | name: Build Check 2 | 3 | on: 4 | schedule: 5 | - cron: '0 12 * * *' 6 | 7 | jobs: 8 | Verify: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v4 12 | - name: Grant Permission 13 | run: chmod +x ./mvnw 14 | - uses: actions/setup-java@v4 15 | with: 16 | distribution: 'corretto' 17 | java-version: '11' 18 | - name: Verify 19 | run: ./mvnw -B -ntp clean verify -DskipTests -Dgpg.skip=true 20 | 21 | RunOnLinux: 22 | runs-on: ubuntu-latest 23 | needs: Verify 24 | steps: 25 | - uses: actions/checkout@v4 26 | - name: Grant Permission 27 | run: chmod +x ./mvnw 28 | - uses: actions/setup-java@v4 29 | with: 30 | distribution: 'corretto' 31 | java-version: '11' 32 | - name: Run Tests 33 | run: ./mvnw -B -ntp test 34 | 35 | RunOnMacOs: 36 | runs-on: macos-latest 37 | needs: Verify 38 | steps: 39 | - uses: actions/checkout@v4 40 | - name: Grant Permission 41 | run: chmod +x ./mvnw 42 | - uses: actions/setup-java@v4 43 | with: 44 | distribution: 'corretto' 45 | java-version: '11' 46 | - name: Run Tests 47 | run: ./mvnw -B -ntp test 48 | 49 | RunOnWindows: 50 | runs-on: windows-latest 51 | needs: Verify 52 | steps: 53 | - uses: actions/checkout@v4 54 | - uses: actions/setup-java@v4 55 | with: 56 | distribution: 'corretto' 57 | java-version: '11' 58 | - name: Run Tests 59 | run: ./mvnw.cmd -B -ntp test 60 | -------------------------------------------------------------------------------- /.github/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | # This workflow is designed to build PRs for AHC. Note that it does not actually publish AHC, just builds and test it. 2 | # Docs: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven 3 | 4 | name: Build PR 5 | 6 | on: 7 | push: 8 | branches: 9 | - main 10 | pull_request: 11 | 12 | workflow_dispatch: 13 | inputs: 14 | name: 15 | description: 'Github Actions' 16 | required: true 17 | default: 'Github Actions' 18 | 19 | jobs: 20 | RunOnLinux: 21 | runs-on: ubuntu-latest 22 | steps: 23 | - uses: actions/checkout@v4 24 | - name: Grant Permission 25 | run: sudo chmod +x ./mvnw 26 | - uses: actions/setup-java@v4 27 | with: 28 | distribution: 'corretto' 29 | java-version: '11' 30 | - name: Run Tests 31 | run: ./mvnw -B -ntp clean test 32 | 33 | RunOnMacOs: 34 | runs-on: macos-latest 35 | steps: 36 | - uses: actions/checkout@v4 37 | - name: Grant Permission 38 | run: sudo chmod +x ./mvnw 39 | - uses: actions/setup-java@v4 40 | with: 41 | distribution: 'corretto' 42 | java-version: '11' 43 | - name: Run Tests 44 | run: ./mvnw -B -ntp clean test 45 | 46 | RunOnWindows: 47 | runs-on: windows-latest 48 | steps: 49 | - uses: actions/checkout@v4 50 | - uses: actions/setup-java@v4 51 | with: 52 | distribution: 'corretto' 53 | java-version: '11' 54 | - name: Run Tests 55 | run: ./mvnw.cmd -B -ntp clean test 56 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | workflow_dispatch: 5 | inputs: 6 | name: 7 | description: 'Github Actions - Release' 8 | required: true 9 | default: 'Github Actions - Release' 10 | 11 | jobs: 12 | 13 | Publish: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@v4 17 | 18 | - name: Grant Permission 19 | run: sudo chmod +x ./mvnw 20 | 21 | - uses: actions/setup-java@v4 22 | with: 23 | distribution: 'corretto' 24 | java-version: '11' 25 | 26 | - name: Remove old Maven Settings 27 | run: rm -f /home/runner/.m2/settings.xml 28 | 29 | - name: Maven Settings 30 | uses: s4u/maven-settings-action@v3.1.0 31 | with: 32 | servers: | 33 | [{ 34 | "id": "ossrh", 35 | "username": "${{ secrets.OSSRH_USERNAME }}", 36 | "password": "${{ secrets.OSSRH_PASSWORD }}" 37 | }] 38 | 39 | - name: Import GPG 40 | uses: crazy-max/ghaction-import-gpg@v6.3.0 41 | with: 42 | gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} 43 | passphrase: ${{ secrets.GPG_PASSPHRASE }} 44 | 45 | - name: Build 46 | run: mvn -ntp -B clean verify install -DskipTests 47 | 48 | - name: Publish to Maven Central 49 | env: 50 | GPG_KEY_NAME: ${{ secrets.GPG_KEY_NAME }} 51 | GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} 52 | run: mvn -ntp -B deploy -DskipTests -Dgpg.keyname=${GPG_KEY_NAME} -Dgpg.passphrase=${GPG_PASSPHRASE} 53 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *~ 3 | .*.swp 4 | .*.swo 5 | .loadpath 6 | .buildpath 7 | .classpath 8 | .project 9 | .settings 10 | .idea 11 | *.iml 12 | *.ipr 13 | *.iws 14 | nbproject 15 | .DS_Store 16 | target 17 | test-output 18 | MANIFEST.MF 19 | work 20 | atlassian-ide-plugin.xml 21 | /bom/.flattened-pom.xml 22 | -------------------------------------------------------------------------------- /.mvn/jvm.config: -------------------------------------------------------------------------------- 1 | --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED 2 | --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED 3 | --add-exports jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED 4 | --add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED 5 | --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED 6 | --add-exports jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED 7 | --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED 8 | --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED 9 | --add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED 10 | --add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED 11 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsyncHttpClient/async-http-client/eeec3349d367ee0409acc5a63cc8d25f568e5539/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip 18 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar 19 | -------------------------------------------------------------------------------- /CHANGES.md: -------------------------------------------------------------------------------- 1 | ## From 2.2 to 2.3 2 | 3 | * New `isFilterInsecureCipherSuites` config to disable unsecure and weak ciphers filtering performed internally in Netty. 4 | 5 | ## From 2.1 to 2.2 6 | 7 | * New [Typesafe config](https://github.com/lightbend/config) extra module 8 | * new `enableWebSocketCompression` config to enable per-message and per-frame WebSocket compression extension 9 | 10 | ## From 2.0 to 2.1 11 | 12 | * AHC 2.1 targets Netty 4.1. 13 | * `org.asynchttpclient.HttpResponseHeaders` was [dropped](https://github.com/AsyncHttpClient/async-http-client/commit/f4786f3ac7699f8f8664e7c7db0b7097585a0786) in favor 14 | of `io.netty.handler.codec.http.HttpHeaders`. 15 | * `org.asynchttpclient.cookie.Cookie` was [dropped](https://github.com/AsyncHttpClient/async-http-client/commit/a6d659ea0cc11fa5131304d8a04a7ba89c7a66af) in favor 16 | of `io.netty.handler.codec.http.cookie.Cookie` as AHC's cookie parsers were contributed to Netty. 17 | * AHC now has a RFC6265 `CookieStore` that is enabled by default. Implementation can be changed in `AsyncHttpClientConfig`. 18 | * `AsyncHttpClient` now exposes stats with `getClientStats`. 19 | * `AsyncHandlerExtensions` was [dropped](https://github.com/AsyncHttpClient/async-http-client/commit/1972c9b9984d6d9f9faca6edd4f2159013205aea) in favor of default methods 20 | in `AsyncHandler`. 21 | * `WebSocket` and `WebSocketListener` methods were renamed to mention frames 22 | * `AsyncHttpClientConfig` various changes: 23 | * new `getCookieStore` now lets you configure a CookieStore (enabled by default) 24 | * new `isAggregateWebSocketFrameFragments` now lets you disable WebSocket fragmented frames aggregation 25 | * new `isUseLaxCookieEncoder` lets you loosen cookie chars validation 26 | * `isAcceptAnyCertificate` was dropped, as it didn't do what its name stated 27 | * new `isUseInsecureTrustManager` lets you use a permissive TrustManager, that would typically let you accept self-signed certificates 28 | * new `isDisableHttpsEndpointIdentificationAlgorithm` disables setting `HTTPS` algorithm on the SSLEngines, typically disables SNI and HTTPS hostname verification 29 | * new `isAggregateWebSocketFrameFragments` lets you disable fragmented WebSocket frames aggregation 30 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014-2024 AsyncHttpClient Project. All rights reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /LICENSES/LICENSE.zstd-jni.txt: -------------------------------------------------------------------------------- 1 | Zstd-jni: JNI bindings to Zstd Library 2 | 3 | Copyright (c) 2015-present, Luben Karavelov/ All rights reserved. 4 | 5 | BSD License 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | 13 | * Redistributions in binary form must reproduce the above copyright notice, this 14 | list of conditions and the following disclaimer in the documentation and/or 15 | other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/AsyncCompletionHandlerBase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Ning, Inc. 3 | * 4 | * This program is licensed to you under the Apache License, version 2.0 5 | * (the "License"); you may not use this file except in compliance with the 6 | * License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | * 16 | */ 17 | package org.asynchttpclient; 18 | 19 | 20 | import org.jetbrains.annotations.Nullable; 21 | 22 | /** 23 | * Simple {@link AsyncHandler} of type {@link Response} 24 | */ 25 | public class AsyncCompletionHandlerBase extends AsyncCompletionHandler { 26 | 27 | @Override 28 | public @Nullable Response onCompleted(@Nullable Response response) throws Exception { 29 | return response; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/AsyncHttpClientState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient; 17 | 18 | import java.util.concurrent.atomic.AtomicBoolean; 19 | 20 | public class AsyncHttpClientState { 21 | 22 | private final AtomicBoolean closed; 23 | 24 | AsyncHttpClientState(AtomicBoolean closed) { 25 | this.closed = closed; 26 | } 27 | 28 | public boolean isClosed() { 29 | return closed.get(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/BoundRequestBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2024 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient; 17 | 18 | public class BoundRequestBuilder extends RequestBuilderBase { 19 | 20 | private final AsyncHttpClient client; 21 | 22 | public BoundRequestBuilder(AsyncHttpClient client, String method, boolean isDisableUrlEncoding, boolean validateHeaders) { 23 | super(method, isDisableUrlEncoding, validateHeaders); 24 | this.client = client; 25 | } 26 | 27 | public BoundRequestBuilder(AsyncHttpClient client, String method, boolean isDisableUrlEncoding) { 28 | super(method, isDisableUrlEncoding); 29 | this.client = client; 30 | } 31 | 32 | public BoundRequestBuilder(AsyncHttpClient client, Request prototype) { 33 | super(prototype); 34 | this.client = client; 35 | } 36 | 37 | public ListenableFuture execute(AsyncHandler handler) { 38 | return client.executeRequest(build(), handler); 39 | } 40 | 41 | public ListenableFuture execute() { 42 | return client.executeRequest(build(), new AsyncCompletionHandlerBase()); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/HttpResponseBodyPart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Ning, Inc. 3 | * 4 | * This program is licensed to you under the Apache License, version 2.0 5 | * (the "License"); you may not use this file except in compliance with the 6 | * License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package org.asynchttpclient; 17 | 18 | import io.netty.buffer.ByteBuf; 19 | 20 | import java.nio.ByteBuffer; 21 | 22 | /** 23 | * A callback class used when an HTTP response body is received. 24 | */ 25 | public abstract class HttpResponseBodyPart { 26 | 27 | private final boolean last; 28 | 29 | protected HttpResponseBodyPart(boolean last) { 30 | this.last = last; 31 | } 32 | 33 | /** 34 | * @return length of this part in bytes 35 | */ 36 | public abstract int length(); 37 | 38 | /** 39 | * @return the response body's part bytes received. 40 | */ 41 | public abstract byte[] getBodyPartBytes(); 42 | 43 | /** 44 | * @return a {@link ByteBuffer} that wraps the actual bytes read from the response's chunk. 45 | * The {@link ByteBuffer}'s capacity is equal to the number of bytes available. 46 | */ 47 | public abstract ByteBuffer getBodyByteBuffer(); 48 | 49 | /** 50 | * @return the {@link ByteBuf} of the bytes read from the response's chunk. 51 | * The {@link ByteBuf}'s capacity is equal to the number of bytes available. 52 | */ 53 | public abstract ByteBuf getBodyByteBuf(); 54 | 55 | /** 56 | * @return true if this is the last part. 57 | */ 58 | public boolean isLast() { 59 | return last; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/RequestBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Ning, Inc. 3 | * 4 | * This program is licensed to you under the Apache License, version 2.0 5 | * (the "License"); you may not use this file except in compliance with the 6 | * License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package org.asynchttpclient; 17 | 18 | import static org.asynchttpclient.util.HttpConstants.Methods.GET; 19 | 20 | /** 21 | * Builder for a {@link Request}. Warning: mutable and not thread-safe! Beware that it holds a reference to the Request instance it builds, so modifying the builder will modify the 22 | * request even after it has been built. 23 | */ 24 | public class RequestBuilder extends RequestBuilderBase { 25 | 26 | public RequestBuilder() { 27 | this(GET); 28 | } 29 | 30 | public RequestBuilder(String method) { 31 | this(method, false); 32 | } 33 | 34 | public RequestBuilder(String method, boolean disableUrlEncoding) { 35 | super(method, disableUrlEncoding); 36 | } 37 | 38 | public RequestBuilder(String method, boolean disableUrlEncoding, boolean validateHeaders) { 39 | super(method, disableUrlEncoding, validateHeaders); 40 | } 41 | 42 | RequestBuilder(Request prototype) { 43 | super(prototype); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/SignatureCalculator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Ning, Inc. 3 | * 4 | * This program is licensed to you under the Apache License, version 2.0 5 | * (the "License"); you may not use this file except in compliance with the 6 | * License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package org.asynchttpclient; 17 | 18 | 19 | /** 20 | * Interface that allows injecting signature calculator into 21 | * {@link RequestBuilder} so that signature calculation and inclusion can 22 | * be added as a pluggable component. 23 | * 24 | * @since 1.1 25 | */ 26 | @FunctionalInterface 27 | public interface SignatureCalculator { 28 | 29 | /** 30 | * Method called when {@link RequestBuilder#build} method is called. 31 | * Should first calculate signature information and then modify request 32 | * (using passed {@link RequestBuilder}) to add signature (usually as 33 | * an HTTP header). 34 | * 35 | * @param requestBuilder builder that can be used to modify request, usually 36 | * by adding header that includes calculated signature. Be sure NOT to 37 | * call {@link RequestBuilder#build} since this will cause infinite recursion 38 | * @param request Request that is being built; needed to access content to 39 | * be signed 40 | */ 41 | void calculateAndAddSignature(Request request, RequestBuilderBase requestBuilder); 42 | } 43 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/SslEngineFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2024 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient; 17 | 18 | import javax.net.ssl.SSLEngine; 19 | import javax.net.ssl.SSLException; 20 | 21 | @FunctionalInterface 22 | public interface SslEngineFactory { 23 | 24 | /** 25 | * Creates a new {@link SSLEngine}. 26 | * 27 | * @param config the client config 28 | * @param peerHost the peer hostname 29 | * @param peerPort the peer port 30 | * @return new engine 31 | */ 32 | SSLEngine newSslEngine(AsyncHttpClientConfig config, String peerHost, int peerPort); 33 | 34 | /** 35 | * Perform any necessary one-time configuration. This will be called just once before {@code newSslEngine} is called 36 | * for the first time. 37 | * 38 | * @param config the client config 39 | * @throws SSLException if initialization fails. If an exception is thrown, the instance will not be used as client 40 | * creation will fail. 41 | */ 42 | default void init(AsyncHttpClientConfig config) throws SSLException { 43 | // no op 44 | } 45 | 46 | /** 47 | * Perform any necessary cleanup. 48 | */ 49 | default void destroy() { 50 | // no op 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/channel/DefaultKeepAliveStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.channel; 17 | 18 | import io.netty.handler.codec.http.HttpRequest; 19 | import io.netty.handler.codec.http.HttpResponse; 20 | import io.netty.handler.codec.http.HttpUtil; 21 | import org.asynchttpclient.Request; 22 | 23 | import java.net.InetSocketAddress; 24 | 25 | import static io.netty.handler.codec.http.HttpHeaderValues.CLOSE; 26 | 27 | /** 28 | * Connection strategy implementing standard HTTP 1.0/1.1 behavior. 29 | */ 30 | public class DefaultKeepAliveStrategy implements KeepAliveStrategy { 31 | 32 | /** 33 | * Implemented in accordance with RFC 7230 section 6.1 ... 34 | */ 35 | @Override 36 | public boolean keepAlive(InetSocketAddress remoteAddress, Request ahcRequest, HttpRequest request, HttpResponse response) { 37 | return HttpUtil.isKeepAlive(response) && 38 | HttpUtil.isKeepAlive(request) && 39 | // support non-standard Proxy-Connection 40 | !response.headers().contains("Proxy-Connection", CLOSE, true); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/channel/KeepAliveStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2024 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.channel; 17 | 18 | import io.netty.handler.codec.http.HttpRequest; 19 | import io.netty.handler.codec.http.HttpResponse; 20 | import org.asynchttpclient.Request; 21 | 22 | import java.net.InetSocketAddress; 23 | 24 | @FunctionalInterface 25 | public interface KeepAliveStrategy { 26 | 27 | /** 28 | * Determines whether the connection should be kept alive after this HTTP message exchange. 29 | * 30 | * @param remoteAddress the remote InetSocketAddress associated with the request 31 | * @param ahcRequest the Request, as built by AHC 32 | * @param nettyRequest the HTTP request sent to Netty 33 | * @param nettyResponse the HTTP response received from Netty 34 | * @return true if the connection should be kept alive, false if it should be closed. 35 | */ 36 | boolean keepAlive(InetSocketAddress remoteAddress, Request ahcRequest, HttpRequest nettyRequest, HttpResponse nettyResponse); 37 | } 38 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/cookie/CookieEvictionTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.cookie; 17 | 18 | import io.netty.util.Timeout; 19 | import io.netty.util.TimerTask; 20 | import org.asynchttpclient.AsyncHttpClientConfig; 21 | 22 | import java.util.concurrent.TimeUnit; 23 | 24 | /** 25 | * Evicts expired cookies from the {@linkplain CookieStore} periodically. 26 | * The default delay is 30 seconds. You may override the default using 27 | * {@linkplain AsyncHttpClientConfig#expiredCookieEvictionDelay()}. 28 | */ 29 | public class CookieEvictionTask implements TimerTask { 30 | 31 | private final long evictDelayInMs; 32 | private final CookieStore cookieStore; 33 | 34 | public CookieEvictionTask(long evictDelayInMs, CookieStore cookieStore) { 35 | this.evictDelayInMs = evictDelayInMs; 36 | this.cookieStore = cookieStore; 37 | } 38 | 39 | @Override 40 | public void run(Timeout timeout) throws Exception { 41 | cookieStore.evictExpired(); 42 | timeout.timer().newTimeout(this, evictDelayInMs, TimeUnit.MILLISECONDS); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/exception/ChannelClosedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.exception; 17 | 18 | import java.io.IOException; 19 | 20 | import static org.asynchttpclient.util.ThrowableUtil.unknownStackTrace; 21 | 22 | /** 23 | * This exception is thrown when a channel is closed. 24 | */ 25 | public final class ChannelClosedException extends IOException { 26 | 27 | private static final long serialVersionUID = -2528693697240456658L; 28 | public static final ChannelClosedException INSTANCE = unknownStackTrace(new ChannelClosedException(), ChannelClosedException.class, "INSTANCE"); 29 | 30 | private ChannelClosedException() { 31 | super("Channel closed"); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/exception/FilterException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.exception; 17 | 18 | import org.asynchttpclient.AsyncHandler; 19 | import org.asynchttpclient.filter.RequestFilter; 20 | import org.asynchttpclient.filter.ResponseFilter; 21 | 22 | /** 23 | * An exception that can be thrown by an {@link AsyncHandler} to interrupt invocation of 24 | * the {@link RequestFilter} and {@link ResponseFilter}. It also interrupts the request and response processing. 25 | */ 26 | public class FilterException extends Exception { 27 | 28 | private static final long serialVersionUID = -3963344749394925069L; 29 | 30 | public FilterException(final String message) { 31 | super(message); 32 | } 33 | 34 | public FilterException(final String message, final Throwable cause) { 35 | super(message, cause); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/exception/PoolAlreadyClosedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.exception; 17 | 18 | import java.io.IOException; 19 | 20 | import static org.asynchttpclient.util.ThrowableUtil.unknownStackTrace; 21 | 22 | /** 23 | * This exception is thrown when a channel pool is already closed. 24 | */ 25 | public class PoolAlreadyClosedException extends IOException { 26 | 27 | private static final long serialVersionUID = -3883404852005245296L; 28 | public static final PoolAlreadyClosedException INSTANCE = unknownStackTrace(new PoolAlreadyClosedException(), PoolAlreadyClosedException.class, "INSTANCE"); 29 | 30 | private PoolAlreadyClosedException() { 31 | super("Pool is already closed"); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/exception/RemotelyClosedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.exception; 17 | 18 | import java.io.IOException; 19 | 20 | import static org.asynchttpclient.util.ThrowableUtil.unknownStackTrace; 21 | 22 | /** 23 | * This exception is thrown when a channel is closed by remote host. 24 | */ 25 | public final class RemotelyClosedException extends IOException { 26 | 27 | private static final long serialVersionUID = 5634105738124356785L; 28 | public static final RemotelyClosedException INSTANCE = unknownStackTrace(new RemotelyClosedException(), RemotelyClosedException.class, "INSTANCE"); 29 | 30 | private RemotelyClosedException() { 31 | super("Remotely closed"); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/exception/TooManyConnectionsException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.exception; 17 | 18 | import java.io.IOException; 19 | 20 | /** 21 | * This exception is thrown when too many connections are opened. 22 | */ 23 | public class TooManyConnectionsException extends IOException { 24 | private static final long serialVersionUID = 8645586459539317237L; 25 | 26 | public TooManyConnectionsException(int max) { 27 | super("Too many connections: " + max); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/exception/TooManyConnectionsPerHostException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.exception; 17 | 18 | import java.io.IOException; 19 | 20 | /** 21 | * This exception is thrown when too many connections are opened to a remote host. 22 | */ 23 | public class TooManyConnectionsPerHostException extends IOException { 24 | 25 | private static final long serialVersionUID = 5702859695179937503L; 26 | 27 | public TooManyConnectionsPerHostException(int max) { 28 | super("Too many connections: " + max); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/filter/IOExceptionFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012 Sonatype, Inc. 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 http://www.apache.org/licenses/LICENSE-2.0. 7 | * 8 | * Unless required by applicable law or agreed to in writing, 9 | * software distributed under the Apache License Version 2.0 is distributed on an 10 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. 12 | */ 13 | package org.asynchttpclient.filter; 14 | 15 | import org.asynchttpclient.AsyncHttpClient; 16 | import org.asynchttpclient.Request; 17 | import org.asynchttpclient.exception.FilterException; 18 | 19 | import java.io.IOException; 20 | 21 | /** 22 | * This filter is invoked when an {@link IOException} occurs during a http transaction. 23 | */ 24 | public interface IOExceptionFilter { 25 | 26 | /** 27 | * An {@link AsyncHttpClient} will invoke {@link IOExceptionFilter#filter} and will 28 | * use the returned {@link FilterContext} to replay the {@link Request} or abort the processing. 29 | * 30 | * @param ctx a {@link FilterContext} 31 | * @param the handler result type 32 | * @return {@link FilterContext}. The {@link FilterContext} instance may not the same as the original one. 33 | * @throws FilterException to interrupt the filter processing. 34 | */ 35 | FilterContext filter(FilterContext ctx) throws FilterException; 36 | } 37 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/filter/RequestFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012 Sonatype, Inc. 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 http://www.apache.org/licenses/LICENSE-2.0. 7 | * 8 | * Unless required by applicable law or agreed to in writing, 9 | * software distributed under the Apache License Version 2.0 is distributed on an 10 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. 12 | */ 13 | package org.asynchttpclient.filter; 14 | 15 | import org.asynchttpclient.AsyncHttpClient; 16 | import org.asynchttpclient.exception.FilterException; 17 | 18 | /** 19 | * A Filter interface that gets invoked before making an actual request. 20 | */ 21 | public interface RequestFilter { 22 | 23 | /** 24 | * An {@link AsyncHttpClient} will invoke {@link RequestFilter#filter} and will use the 25 | * returned {@link FilterContext#getRequest()} and {@link FilterContext#getAsyncHandler()} to continue the request 26 | * processing. 27 | * 28 | * @param ctx a {@link FilterContext} 29 | * @param the handler result type 30 | * @return {@link FilterContext}. The {@link FilterContext} instance may not the same as the original one. 31 | * @throws FilterException to interrupt the filter processing. 32 | */ 33 | FilterContext filter(FilterContext ctx) throws FilterException; 34 | } 35 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/filter/ResponseFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012 Sonatype, Inc. 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 http://www.apache.org/licenses/LICENSE-2.0. 7 | * 8 | * Unless required by applicable law or agreed to in writing, 9 | * software distributed under the Apache License Version 2.0 is distributed on an 10 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. 12 | */ 13 | package org.asynchttpclient.filter; 14 | 15 | import org.asynchttpclient.AsyncHttpClient; 16 | import org.asynchttpclient.exception.FilterException; 17 | 18 | /** 19 | * A Filter interface that gets invoked before making the processing of the response bytes. {@link ResponseFilter} are invoked 20 | * before the actual response's status code get processed. That means authorization, proxy authentication and redirects 21 | * processing hasn't occurred when {@link ResponseFilter} gets invoked. 22 | */ 23 | public interface ResponseFilter { 24 | 25 | /** 26 | * An {@link AsyncHttpClient} will invoke {@link ResponseFilter#filter} and will use the 27 | * returned {@link FilterContext#replayRequest()} and {@link FilterContext#getAsyncHandler()} to decide if the response 28 | * processing can continue. If {@link FilterContext#replayRequest()} return true, a new request will be made 29 | * using {@link FilterContext#getRequest()} and the current response processing will be ignored. 30 | * 31 | * @param ctx a {@link FilterContext} 32 | * @param the handler result type 33 | * @return {@link FilterContext}. The {@link FilterContext} instance may not the same as the original one. 34 | * @throws FilterException to interrupt the filter processing. 35 | */ 36 | FilterContext filter(FilterContext ctx) throws FilterException; 37 | } 38 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/handler/MaxRedirectException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2024 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.handler; 17 | 18 | import org.asynchttpclient.DefaultAsyncHttpClientConfig; 19 | 20 | /** 21 | * Thrown when the {@link DefaultAsyncHttpClientConfig#getMaxRedirects()} has been reached. 22 | */ 23 | public class MaxRedirectException extends Exception { 24 | private static final long serialVersionUID = 1L; 25 | 26 | public MaxRedirectException(String msg) { 27 | super(msg, null, true, false); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/handler/ProgressAsyncHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012 Sonatype, Inc. 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 http://www.apache.org/licenses/LICENSE-2.0. 7 | * 8 | * Unless required by applicable law or agreed to in writing, 9 | * software distributed under the Apache License Version 2.0 is distributed on an 10 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. 12 | */ 13 | package org.asynchttpclient.handler; 14 | 15 | import org.asynchttpclient.AsyncHandler; 16 | import org.asynchttpclient.Request; 17 | 18 | import java.io.File; 19 | import java.io.FileInputStream; 20 | 21 | /** 22 | * An extended {@link AsyncHandler} with two extra callback who get invoked during the content upload to a remote server. 23 | * This {@link AsyncHandler} must be used only with PUT and POST request. 24 | */ 25 | public interface ProgressAsyncHandler extends AsyncHandler { 26 | 27 | /** 28 | * Invoked when the content (a {@link File}, {@link String} or {@link FileInputStream}) has been fully 29 | * written on the I/O socket. 30 | * 31 | * @return a {@link AsyncHandler.State} telling to CONTINUE or ABORT the current processing. 32 | */ 33 | State onHeadersWritten(); 34 | 35 | /** 36 | * Invoked when the content (a {@link File}, {@link String} or {@link FileInputStream}) has been fully 37 | * written on the I/O socket. 38 | * 39 | * @return a {@link AsyncHandler.State} telling to CONTINUE or ABORT the current processing. 40 | */ 41 | State onContentWritten(); 42 | 43 | /** 44 | * Invoked when the I/O operation associated with the {@link Request} body wasn't fully written in a single I/O write 45 | * operation. This method is never invoked if the write operation complete in a sinfle I/O write. 46 | * 47 | * @param amount The amount of bytes to transfer. 48 | * @param current The amount of bytes transferred 49 | * @param total The total number of bytes transferred 50 | * @return a {@link AsyncHandler.State} telling to CONTINUE or ABORT the current processing. 51 | */ 52 | State onContentWriteProgress(long amount, long current, long total); 53 | } 54 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/handler/TransferListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012 Sonatype, Inc. 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 http://www.apache.org/licenses/LICENSE-2.0. 7 | * 8 | * Unless required by applicable law or agreed to in writing, 9 | * software distributed under the Apache License Version 2.0 is distributed on an 10 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. 12 | */ 13 | package org.asynchttpclient.handler; 14 | 15 | import io.netty.handler.codec.http.HttpHeaders; 16 | 17 | /** 18 | * A simple interface an application can implement in order to received byte transfer information. 19 | */ 20 | public interface TransferListener { 21 | 22 | /** 23 | * Invoked when the request bytes are starting to get send. 24 | * 25 | * @param headers the headers 26 | */ 27 | void onRequestHeadersSent(HttpHeaders headers); 28 | 29 | /** 30 | * Invoked when the response bytes are starting to get received. 31 | * 32 | * @param headers the headers 33 | */ 34 | void onResponseHeadersReceived(HttpHeaders headers); 35 | 36 | /** 37 | * Invoked every time response's chunk are received. 38 | * 39 | * @param bytes a {@link byte} array 40 | */ 41 | void onBytesReceived(byte[] bytes); 42 | 43 | /** 44 | * Invoked every time request's chunk are sent. 45 | * 46 | * @param amount The amount of bytes to transfer 47 | * @param current The amount of bytes transferred 48 | * @param total The total number of bytes transferred 49 | */ 50 | void onBytesSent(long amount, long current, long total); 51 | 52 | /** 53 | * Invoked when the response bytes are been fully received. 54 | */ 55 | void onRequestResponseCompleted(); 56 | 57 | /** 58 | * Invoked when there is an unexpected issue. 59 | * 60 | * @param t a {@link Throwable} 61 | */ 62 | void onThrowable(Throwable t); 63 | } 64 | 65 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/handler/resumable/ResumableIOExceptionFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012 Sonatype, Inc. 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 http://www.apache.org/licenses/LICENSE-2.0. 7 | * 8 | * Unless required by applicable law or agreed to in writing, 9 | * software distributed under the Apache License Version 2.0 is distributed on an 10 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. 12 | */ 13 | package org.asynchttpclient.handler.resumable; 14 | 15 | import org.asynchttpclient.Request; 16 | import org.asynchttpclient.filter.FilterContext; 17 | import org.asynchttpclient.filter.IOExceptionFilter; 18 | 19 | /** 20 | * Simple {@link IOExceptionFilter} that replay the current {@link Request} using a {@link ResumableAsyncHandler} 21 | */ 22 | public class ResumableIOExceptionFilter implements IOExceptionFilter { 23 | 24 | @Override 25 | public FilterContext filter(FilterContext ctx) { 26 | if (ctx.getIOException() != null && ctx.getAsyncHandler() instanceof ResumableAsyncHandler) { 27 | Request request = ((ResumableAsyncHandler) ctx.getAsyncHandler()).adjustRequestRange(ctx.getRequest()); 28 | return new FilterContext.FilterContextBuilder<>(ctx).request(request).replayRequest(true).build(); 29 | } 30 | return ctx; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/handler/resumable/ResumableListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012 Sonatype, Inc. 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 http://www.apache.org/licenses/LICENSE-2.0. 7 | * 8 | * Unless required by applicable law or agreed to in writing, 9 | * software distributed under the Apache License Version 2.0 is distributed on an 10 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. 12 | */ 13 | package org.asynchttpclient.handler.resumable; 14 | 15 | import java.io.IOException; 16 | import java.nio.ByteBuffer; 17 | 18 | /** 19 | * A listener class that can be used to digest the bytes from an {@link ResumableAsyncHandler} 20 | */ 21 | public interface ResumableListener { 22 | 23 | /** 24 | * Invoked when some bytes are available to digest. 25 | * 26 | * @param byteBuffer the current bytes 27 | * @throws IOException exception while writing the byteBuffer 28 | */ 29 | void onBytesReceived(ByteBuffer byteBuffer) throws IOException; 30 | 31 | /** 32 | * Invoked when all the bytes has been successfully transferred. 33 | */ 34 | void onAllBytesReceived(); 35 | 36 | /** 37 | * Return the length of previously downloaded bytes. 38 | * 39 | * @return the length of previously downloaded bytes 40 | */ 41 | long length(); 42 | } 43 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/netty/DiscardEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2024 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.netty; 17 | 18 | /** 19 | * Simple marker for stopping publishing bytes 20 | */ 21 | public enum DiscardEvent { 22 | DISCARD 23 | } 24 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/netty/EagerResponseBodyPart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2024 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.netty; 17 | 18 | import io.netty.buffer.ByteBuf; 19 | import io.netty.buffer.ByteBufUtil; 20 | import io.netty.buffer.Unpooled; 21 | import org.asynchttpclient.HttpResponseBodyPart; 22 | 23 | import java.nio.ByteBuffer; 24 | 25 | /** 26 | * A callback class used when an HTTP response body is received. 27 | * Bytes are eagerly fetched from the ByteBuf 28 | */ 29 | public class EagerResponseBodyPart extends HttpResponseBodyPart { 30 | 31 | private final byte[] bytes; 32 | 33 | public EagerResponseBodyPart(ByteBuf buf, boolean last) { 34 | super(last); 35 | bytes = ByteBufUtil.getBytes(buf); 36 | } 37 | 38 | /** 39 | * Return the response body's part bytes received. 40 | * 41 | * @return the response body's part bytes received. 42 | */ 43 | @Override 44 | public byte[] getBodyPartBytes() { 45 | return bytes; 46 | } 47 | 48 | @Override 49 | public int length() { 50 | return bytes.length; 51 | } 52 | 53 | @Override 54 | public ByteBuffer getBodyByteBuffer() { 55 | return ByteBuffer.wrap(bytes); 56 | } 57 | 58 | @Override 59 | public ByteBuf getBodyByteBuf() { 60 | return Unpooled.wrappedBuffer(bytes); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/netty/LazyResponseBodyPart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2024 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.netty; 17 | 18 | import io.netty.buffer.ByteBuf; 19 | import io.netty.buffer.ByteBufUtil; 20 | import org.asynchttpclient.HttpResponseBodyPart; 21 | 22 | import java.nio.ByteBuffer; 23 | 24 | /** 25 | * A callback class used when an HTTP response body is received. 26 | */ 27 | public class LazyResponseBodyPart extends HttpResponseBodyPart { 28 | 29 | private final ByteBuf buf; 30 | 31 | public LazyResponseBodyPart(ByteBuf buf, boolean last) { 32 | super(last); 33 | this.buf = buf; 34 | } 35 | 36 | @Override 37 | public ByteBuf getBodyByteBuf() { 38 | return buf; 39 | } 40 | 41 | @Override 42 | public int length() { 43 | return buf.readableBytes(); 44 | } 45 | 46 | /** 47 | * Return the response body's part bytes received. 48 | * 49 | * @return the response body's part bytes received. 50 | */ 51 | @Override 52 | public byte[] getBodyPartBytes() { 53 | return ByteBufUtil.getBytes(buf.duplicate()); 54 | } 55 | 56 | @Override 57 | public ByteBuffer getBodyByteBuffer() { 58 | return buf.nioBuffer(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/netty/OnLastHttpContentCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2024 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.netty; 17 | 18 | public abstract class OnLastHttpContentCallback { 19 | 20 | protected final NettyResponseFuture future; 21 | 22 | protected OnLastHttpContentCallback(NettyResponseFuture future) { 23 | this.future = future; 24 | } 25 | 26 | public abstract void call() throws Exception; 27 | 28 | public NettyResponseFuture future() { 29 | return future; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/netty/SimpleChannelFutureListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.netty; 17 | 18 | import io.netty.channel.Channel; 19 | import io.netty.channel.ChannelFuture; 20 | import io.netty.channel.ChannelFutureListener; 21 | 22 | public abstract class SimpleChannelFutureListener implements ChannelFutureListener { 23 | 24 | @Override 25 | public final void operationComplete(ChannelFuture future) { 26 | Channel channel = future.channel(); 27 | if (future.isSuccess()) { 28 | onSuccess(channel); 29 | } else { 30 | onFailure(channel, future.cause()); 31 | } 32 | } 33 | 34 | public abstract void onSuccess(Channel channel); 35 | 36 | public abstract void onFailure(Channel channel, Throwable cause); 37 | } 38 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/netty/SimpleFutureListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.netty; 17 | 18 | import io.netty.util.concurrent.Future; 19 | import io.netty.util.concurrent.FutureListener; 20 | 21 | public abstract class SimpleFutureListener implements FutureListener { 22 | 23 | @Override 24 | public final void operationComplete(Future future) throws Exception { 25 | if (future.isSuccess()) { 26 | onSuccess(future.getNow()); 27 | } else { 28 | onFailure(future.cause()); 29 | } 30 | } 31 | 32 | protected abstract void onSuccess(V value) throws Exception; 33 | 34 | protected abstract void onFailure(Throwable t) throws Exception; 35 | } 36 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/netty/channel/ChannelState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.netty.channel; 17 | 18 | public enum ChannelState { 19 | /** 20 | * The channel is new 21 | */ 22 | NEW, 23 | 24 | /** 25 | * The channel is open and pooled 26 | */ 27 | POOLED, 28 | 29 | /** 30 | * The channel is reconnected 31 | */ 32 | RECONNECTED, 33 | 34 | /** 35 | * The channel is closed 36 | */ 37 | CLOSED, 38 | } 39 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/netty/channel/ConnectionSemaphore.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.netty.channel; 17 | 18 | import java.io.IOException; 19 | 20 | /** 21 | * Connections limiter. 22 | */ 23 | public interface ConnectionSemaphore { 24 | 25 | void acquireChannelLock(Object partitionKey) throws IOException; 26 | 27 | void releaseChannelLock(Object partitionKey); 28 | } 29 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/netty/channel/ConnectionSemaphoreFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.netty.channel; 17 | 18 | import org.asynchttpclient.AsyncHttpClientConfig; 19 | 20 | @FunctionalInterface 21 | public interface ConnectionSemaphoreFactory { 22 | 23 | ConnectionSemaphore newConnectionSemaphore(AsyncHttpClientConfig config); 24 | } 25 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/netty/channel/DefaultConnectionSemaphoreFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.netty.channel; 17 | 18 | import org.asynchttpclient.AsyncHttpClientConfig; 19 | 20 | public class DefaultConnectionSemaphoreFactory implements ConnectionSemaphoreFactory { 21 | 22 | @Override 23 | public ConnectionSemaphore newConnectionSemaphore(AsyncHttpClientConfig config) { 24 | int acquireFreeChannelTimeout = Math.max(0, config.getAcquireFreeChannelTimeout()); 25 | int maxConnections = config.getMaxConnections(); 26 | int maxConnectionsPerHost = config.getMaxConnectionsPerHost(); 27 | 28 | if (maxConnections > 0 && maxConnectionsPerHost > 0) { 29 | return new CombinedConnectionSemaphore(maxConnections, maxConnectionsPerHost, acquireFreeChannelTimeout); 30 | } 31 | if (maxConnections > 0) { 32 | return new MaxConnectionSemaphore(maxConnections, acquireFreeChannelTimeout); 33 | } 34 | if (maxConnectionsPerHost > 0) { 35 | return new CombinedConnectionSemaphore(maxConnections, maxConnectionsPerHost, acquireFreeChannelTimeout); 36 | } 37 | 38 | return new NoopConnectionSemaphore(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/netty/channel/EpollTransportFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.netty.channel; 17 | 18 | import io.netty.channel.epoll.Epoll; 19 | import io.netty.channel.epoll.EpollEventLoopGroup; 20 | import io.netty.channel.epoll.EpollSocketChannel; 21 | 22 | import java.util.concurrent.ThreadFactory; 23 | 24 | class EpollTransportFactory implements TransportFactory { 25 | 26 | static boolean isAvailable() { 27 | try { 28 | Class.forName("io.netty.channel.epoll.Epoll"); 29 | } catch (ClassNotFoundException e) { 30 | return false; 31 | } 32 | return Epoll.isAvailable(); 33 | } 34 | 35 | @Override 36 | public EpollSocketChannel newChannel() { 37 | return new EpollSocketChannel(); 38 | } 39 | 40 | @Override 41 | public EpollEventLoopGroup newEventLoopGroup(int ioThreadsCount, ThreadFactory threadFactory) { 42 | return new EpollEventLoopGroup(ioThreadsCount, threadFactory); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/netty/channel/IoUringIncubatorTransportFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.netty.channel; 17 | 18 | import io.netty.incubator.channel.uring.IOUring; 19 | import io.netty.incubator.channel.uring.IOUringEventLoopGroup; 20 | import io.netty.incubator.channel.uring.IOUringSocketChannel; 21 | 22 | import java.util.concurrent.ThreadFactory; 23 | 24 | class IoUringIncubatorTransportFactory implements TransportFactory { 25 | 26 | static boolean isAvailable() { 27 | try { 28 | Class.forName("io.netty.incubator.channel.uring.IOUring"); 29 | } catch (ClassNotFoundException e) { 30 | return false; 31 | } 32 | return IOUring.isAvailable(); 33 | } 34 | 35 | @Override 36 | public IOUringSocketChannel newChannel() { 37 | return new IOUringSocketChannel(); 38 | } 39 | 40 | @Override 41 | public IOUringEventLoopGroup newEventLoopGroup(int ioThreadsCount, ThreadFactory threadFactory) { 42 | return new IOUringEventLoopGroup(ioThreadsCount, threadFactory); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/netty/channel/KQueueTransportFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.netty.channel; 17 | 18 | import io.netty.channel.kqueue.KQueue; 19 | import io.netty.channel.kqueue.KQueueEventLoopGroup; 20 | import io.netty.channel.kqueue.KQueueSocketChannel; 21 | 22 | import java.util.concurrent.ThreadFactory; 23 | 24 | class KQueueTransportFactory implements TransportFactory { 25 | 26 | static boolean isAvailable() { 27 | try { 28 | Class.forName("io.netty.channel.kqueue.KQueue"); 29 | } catch (ClassNotFoundException e) { 30 | return false; 31 | } 32 | return KQueue.isAvailable(); 33 | } 34 | 35 | @Override 36 | public KQueueSocketChannel newChannel() { 37 | return new KQueueSocketChannel(); 38 | } 39 | 40 | @Override 41 | public KQueueEventLoopGroup newEventLoopGroup(int ioThreadsCount, ThreadFactory threadFactory) { 42 | return new KQueueEventLoopGroup(ioThreadsCount, threadFactory); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/netty/channel/MaxConnectionSemaphore.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.netty.channel; 17 | 18 | import org.asynchttpclient.exception.TooManyConnectionsException; 19 | 20 | import java.io.IOException; 21 | import java.util.concurrent.Semaphore; 22 | import java.util.concurrent.TimeUnit; 23 | 24 | import static org.asynchttpclient.util.ThrowableUtil.unknownStackTrace; 25 | 26 | /** 27 | * Max connections limiter. 28 | * 29 | * @author Stepan Koltsov 30 | * @author Alex Maltinsky 31 | */ 32 | public class MaxConnectionSemaphore implements ConnectionSemaphore { 33 | 34 | protected final Semaphore freeChannels; 35 | protected final IOException tooManyConnections; 36 | protected final int acquireTimeout; 37 | 38 | MaxConnectionSemaphore(int maxConnections, int acquireTimeout) { 39 | tooManyConnections = unknownStackTrace(new TooManyConnectionsException(maxConnections), MaxConnectionSemaphore.class, "acquireChannelLock"); 40 | freeChannels = maxConnections > 0 ? new Semaphore(maxConnections) : InfiniteSemaphore.INSTANCE; 41 | this.acquireTimeout = Math.max(0, acquireTimeout); 42 | } 43 | 44 | @Override 45 | public void acquireChannelLock(Object partitionKey) throws IOException { 46 | try { 47 | if (!freeChannels.tryAcquire(acquireTimeout, TimeUnit.MILLISECONDS)) { 48 | throw tooManyConnections; 49 | } 50 | } catch (InterruptedException e) { 51 | throw new RuntimeException(e); 52 | } 53 | } 54 | 55 | @Override 56 | public void releaseChannelLock(Object partitionKey) { 57 | freeChannels.release(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/netty/channel/NioTransportFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.netty.channel; 17 | 18 | import io.netty.channel.nio.NioEventLoopGroup; 19 | import io.netty.channel.socket.nio.NioSocketChannel; 20 | 21 | import java.util.concurrent.ThreadFactory; 22 | 23 | enum NioTransportFactory implements TransportFactory { 24 | 25 | INSTANCE; 26 | 27 | @Override 28 | public NioSocketChannel newChannel() { 29 | return new NioSocketChannel(); 30 | } 31 | 32 | @Override 33 | public NioEventLoopGroup newEventLoopGroup(int ioThreadsCount, ThreadFactory threadFactory) { 34 | return new NioEventLoopGroup(ioThreadsCount, threadFactory); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/netty/channel/NoopConnectionSemaphore.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.netty.channel; 17 | 18 | import java.io.IOException; 19 | 20 | /** 21 | * No-op implementation of {@link ConnectionSemaphore}. 22 | */ 23 | public class NoopConnectionSemaphore implements ConnectionSemaphore { 24 | 25 | @Override 26 | public void acquireChannelLock(Object partitionKey) throws IOException { 27 | } 28 | 29 | @Override 30 | public void releaseChannelLock(Object partitionKey) { 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/netty/channel/TransportFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.netty.channel; 17 | 18 | import io.netty.channel.Channel; 19 | import io.netty.channel.ChannelFactory; 20 | import io.netty.channel.EventLoopGroup; 21 | 22 | import java.util.concurrent.ThreadFactory; 23 | 24 | public interface TransportFactory extends ChannelFactory { 25 | 26 | L newEventLoopGroup(int ioThreadsCount, ThreadFactory threadFactory); 27 | } 28 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/netty/handler/intercept/Continue100Interceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.netty.handler.intercept; 17 | 18 | import io.netty.channel.Channel; 19 | import org.asynchttpclient.netty.NettyResponseFuture; 20 | import org.asynchttpclient.netty.OnLastHttpContentCallback; 21 | import org.asynchttpclient.netty.channel.Channels; 22 | import org.asynchttpclient.netty.request.NettyRequestSender; 23 | 24 | class Continue100Interceptor { 25 | 26 | private final NettyRequestSender requestSender; 27 | 28 | Continue100Interceptor(NettyRequestSender requestSender) { 29 | this.requestSender = requestSender; 30 | } 31 | 32 | public boolean exitAfterHandling100(final Channel channel, final NettyResponseFuture future) { 33 | future.setHeadersAlreadyWrittenOnContinue(true); 34 | future.setDontWriteBodyBecauseExpectContinue(false); 35 | // directly send the body 36 | Channels.setAttribute(channel, new OnLastHttpContentCallback(future) { 37 | @Override 38 | public void call() { 39 | Channels.setAttribute(channel, future); 40 | requestSender.writeRequest(future, channel); 41 | } 42 | }); 43 | return true; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/netty/request/NettyRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2024 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.netty.request; 17 | 18 | import io.netty.handler.codec.http.HttpRequest; 19 | import org.asynchttpclient.netty.request.body.NettyBody; 20 | 21 | public final class NettyRequest { 22 | 23 | private final HttpRequest httpRequest; 24 | private final NettyBody body; 25 | 26 | NettyRequest(HttpRequest httpRequest, NettyBody body) { 27 | this.httpRequest = httpRequest; 28 | this.body = body; 29 | } 30 | 31 | public HttpRequest getHttpRequest() { 32 | return httpRequest; 33 | } 34 | 35 | public NettyBody getBody() { 36 | return body; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/netty/request/WriteCompleteListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.netty.request; 17 | 18 | import io.netty.channel.ChannelFuture; 19 | import io.netty.util.concurrent.GenericFutureListener; 20 | import org.asynchttpclient.netty.NettyResponseFuture; 21 | 22 | public class WriteCompleteListener extends WriteListener implements GenericFutureListener { 23 | 24 | WriteCompleteListener(NettyResponseFuture future) { 25 | super(future, true); 26 | } 27 | 28 | @Override 29 | public void operationComplete(ChannelFuture future) { 30 | operationComplete(future.channel(), future.cause()); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/netty/request/WriteProgressListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2024 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.netty.request; 17 | 18 | import io.netty.channel.ChannelProgressiveFuture; 19 | import io.netty.channel.ChannelProgressiveFutureListener; 20 | import org.asynchttpclient.netty.NettyResponseFuture; 21 | 22 | public class WriteProgressListener extends WriteListener implements ChannelProgressiveFutureListener { 23 | 24 | private final long expectedTotal; 25 | private long lastProgress; 26 | 27 | public WriteProgressListener(NettyResponseFuture future, boolean notifyHeaders, long expectedTotal) { 28 | super(future, notifyHeaders); 29 | this.expectedTotal = expectedTotal; 30 | } 31 | 32 | @Override 33 | public void operationComplete(ChannelProgressiveFuture cf) { 34 | operationComplete(cf.channel(), cf.cause()); 35 | } 36 | 37 | @Override 38 | public void operationProgressed(ChannelProgressiveFuture f, long progress, long total) { 39 | future.touch(); 40 | 41 | if (progressAsyncHandler != null && !notifyHeaders) { 42 | long lastLastProgress = lastProgress; 43 | lastProgress = progress; 44 | if (total < 0) { 45 | total = expectedTotal; 46 | } 47 | if (progress != lastLastProgress) { 48 | progressAsyncHandler.onContentWriteProgress(progress - lastLastProgress, progress, total); 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/netty/request/body/NettyBody.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2024 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.netty.request.body; 17 | 18 | import io.netty.channel.Channel; 19 | import org.asynchttpclient.netty.NettyResponseFuture; 20 | 21 | import java.io.IOException; 22 | 23 | public interface NettyBody { 24 | 25 | long getContentLength(); 26 | 27 | default CharSequence getContentTypeOverride() { 28 | return null; 29 | } 30 | 31 | void write(Channel channel, NettyResponseFuture future) throws IOException; 32 | } 33 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/netty/request/body/NettyByteArrayBody.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2024 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.netty.request.body; 17 | 18 | import io.netty.buffer.ByteBuf; 19 | import io.netty.buffer.Unpooled; 20 | 21 | public class NettyByteArrayBody extends NettyDirectBody { 22 | 23 | private final byte[] bytes; 24 | 25 | public NettyByteArrayBody(byte[] bytes) { 26 | this.bytes = bytes; 27 | } 28 | 29 | @Override 30 | public long getContentLength() { 31 | return bytes.length; 32 | } 33 | 34 | @Override 35 | public ByteBuf byteBuf() { 36 | return Unpooled.wrappedBuffer(bytes); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/netty/request/body/NettyByteBufBody.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.netty.request.body; 17 | 18 | import io.netty.buffer.ByteBuf; 19 | 20 | public class NettyByteBufBody extends NettyDirectBody { 21 | 22 | private final ByteBuf bb; 23 | private final CharSequence contentTypeOverride; 24 | private final long length; 25 | 26 | public NettyByteBufBody(ByteBuf bb) { 27 | this(bb, null); 28 | } 29 | 30 | public NettyByteBufBody(ByteBuf bb, CharSequence contentTypeOverride) { 31 | this.bb = bb; 32 | length = bb.readableBytes(); 33 | this.contentTypeOverride = contentTypeOverride; 34 | } 35 | 36 | @Override 37 | public long getContentLength() { 38 | return length; 39 | } 40 | 41 | @Override 42 | public CharSequence getContentTypeOverride() { 43 | return contentTypeOverride; 44 | } 45 | 46 | @Override 47 | public ByteBuf byteBuf() { 48 | return bb; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/netty/request/body/NettyByteBufferBody.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.netty.request.body; 17 | 18 | import io.netty.buffer.ByteBuf; 19 | import io.netty.buffer.Unpooled; 20 | 21 | import java.nio.ByteBuffer; 22 | 23 | public class NettyByteBufferBody extends NettyDirectBody { 24 | 25 | private final ByteBuffer bb; 26 | private final CharSequence contentTypeOverride; 27 | private final long length; 28 | 29 | public NettyByteBufferBody(ByteBuffer bb) { 30 | this(bb, null); 31 | } 32 | 33 | public NettyByteBufferBody(ByteBuffer bb, CharSequence contentTypeOverride) { 34 | this.bb = bb; 35 | length = bb.remaining(); 36 | bb.mark(); 37 | this.contentTypeOverride = contentTypeOverride; 38 | } 39 | 40 | @Override 41 | public long getContentLength() { 42 | return length; 43 | } 44 | 45 | @Override 46 | public CharSequence getContentTypeOverride() { 47 | return contentTypeOverride; 48 | } 49 | 50 | @Override 51 | public ByteBuf byteBuf() { 52 | // for retry 53 | bb.reset(); 54 | return Unpooled.wrappedBuffer(bb); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/netty/request/body/NettyCompositeByteArrayBody.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2024 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.netty.request.body; 17 | 18 | import io.netty.buffer.ByteBuf; 19 | import io.netty.buffer.Unpooled; 20 | 21 | import java.util.List; 22 | 23 | public class NettyCompositeByteArrayBody extends NettyDirectBody { 24 | 25 | private final byte[][] bytes; 26 | private final long contentLength; 27 | 28 | public NettyCompositeByteArrayBody(List bytes) { 29 | this.bytes = new byte[bytes.size()][]; 30 | bytes.toArray(this.bytes); 31 | long l = 0; 32 | for (byte[] b : bytes) { 33 | l += b.length; 34 | } 35 | contentLength = l; 36 | } 37 | 38 | @Override 39 | public long getContentLength() { 40 | return contentLength; 41 | } 42 | 43 | @Override 44 | public ByteBuf byteBuf() { 45 | return Unpooled.wrappedBuffer(bytes); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/netty/request/body/NettyDirectBody.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2024 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.netty.request.body; 17 | 18 | import io.netty.buffer.ByteBuf; 19 | import io.netty.channel.Channel; 20 | import org.asynchttpclient.netty.NettyResponseFuture; 21 | 22 | public abstract class NettyDirectBody implements NettyBody { 23 | 24 | public abstract ByteBuf byteBuf(); 25 | 26 | @Override 27 | public void write(Channel channel, NettyResponseFuture future) { 28 | throw new UnsupportedOperationException("This kind of body is supposed to be written directly"); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/netty/request/body/NettyMultipartBody.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2024 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.netty.request.body; 17 | 18 | import io.netty.handler.codec.http.HttpHeaders; 19 | import org.asynchttpclient.AsyncHttpClientConfig; 20 | import org.asynchttpclient.request.body.multipart.MultipartBody; 21 | import org.asynchttpclient.request.body.multipart.Part; 22 | 23 | import java.util.List; 24 | 25 | import static org.asynchttpclient.request.body.multipart.MultipartUtils.newMultipartBody; 26 | 27 | public class NettyMultipartBody extends NettyBodyBody { 28 | 29 | private final String contentTypeOverride; 30 | 31 | public NettyMultipartBody(List parts, HttpHeaders headers, AsyncHttpClientConfig config) { 32 | this(newMultipartBody(parts, headers), config); 33 | } 34 | 35 | private NettyMultipartBody(MultipartBody body, AsyncHttpClientConfig config) { 36 | super(body, config); 37 | contentTypeOverride = body.getContentType(); 38 | } 39 | 40 | @Override 41 | public String getContentTypeOverride() { 42 | return contentTypeOverride; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/netty/ssl/JsseSslEngineFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.netty.ssl; 17 | 18 | import org.asynchttpclient.AsyncHttpClientConfig; 19 | 20 | import javax.net.ssl.SSLContext; 21 | import javax.net.ssl.SSLEngine; 22 | 23 | public class JsseSslEngineFactory extends SslEngineFactoryBase { 24 | 25 | private final SSLContext sslContext; 26 | 27 | public JsseSslEngineFactory(SSLContext sslContext) { 28 | this.sslContext = sslContext; 29 | } 30 | 31 | @Override 32 | public SSLEngine newSslEngine(AsyncHttpClientConfig config, String peerHost, int peerPort) { 33 | SSLEngine sslEngine = sslContext.createSSLEngine(domain(peerHost), peerPort); 34 | configureSslEngine(sslEngine, config); 35 | return sslEngine; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/netty/ssl/SslEngineFactoryBase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.netty.ssl; 17 | 18 | import org.asynchttpclient.AsyncHttpClientConfig; 19 | import org.asynchttpclient.SslEngineFactory; 20 | 21 | import javax.net.ssl.SSLEngine; 22 | import javax.net.ssl.SSLParameters; 23 | 24 | public abstract class SslEngineFactoryBase implements SslEngineFactory { 25 | 26 | protected String domain(String hostname) { 27 | int fqdnLength = hostname.length() - 1; 28 | return hostname.charAt(fqdnLength) == '.' ? hostname.substring(0, fqdnLength) : hostname; 29 | } 30 | 31 | protected void configureSslEngine(SSLEngine sslEngine, AsyncHttpClientConfig config) { 32 | sslEngine.setUseClientMode(true); 33 | if (!config.isDisableHttpsEndpointIdentificationAlgorithm()) { 34 | SSLParameters params = sslEngine.getSSLParameters(); 35 | params.setEndpointIdentificationAlgorithm("HTTPS"); 36 | sslEngine.setSSLParameters(params); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/netty/timeout/RequestTimeoutTimerTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2024 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.netty.timeout; 17 | 18 | import io.netty.util.Timeout; 19 | import org.asynchttpclient.netty.NettyResponseFuture; 20 | import org.asynchttpclient.netty.request.NettyRequestSender; 21 | import org.asynchttpclient.util.StringBuilderPool; 22 | 23 | import static org.asynchttpclient.util.DateUtils.unpreciseMillisTime; 24 | 25 | public class RequestTimeoutTimerTask extends TimeoutTimerTask { 26 | 27 | private final long requestTimeout; 28 | 29 | RequestTimeoutTimerTask(NettyResponseFuture nettyResponseFuture, 30 | NettyRequestSender requestSender, 31 | TimeoutsHolder timeoutsHolder, 32 | long requestTimeout) { 33 | super(nettyResponseFuture, requestSender, timeoutsHolder); 34 | this.requestTimeout = requestTimeout; 35 | } 36 | 37 | @Override 38 | public void run(Timeout timeout) { 39 | if (done.getAndSet(true) || requestSender.isClosed()) { 40 | return; 41 | } 42 | 43 | // in any case, cancel possible readTimeout sibling 44 | timeoutsHolder.cancel(); 45 | 46 | if (nettyResponseFuture.isDone()) { 47 | return; 48 | } 49 | 50 | StringBuilder sb = StringBuilderPool.DEFAULT.stringBuilder().append("Request timeout to "); 51 | appendRemoteAddress(sb); 52 | String message = sb.append(" after ").append(requestTimeout).append(" ms").toString(); 53 | long age = unpreciseMillisTime() - nettyResponseFuture.getStart(); 54 | expire(message, age); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/ntlm/NtlmEngineException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ==================================================================== 19 | * 20 | * This software consists of voluntary contributions made by many 21 | * individuals on behalf of the Apache Software Foundation. For more 22 | * information on the Apache Software Foundation, please see 23 | * . 24 | * 25 | */ 26 | package org.asynchttpclient.ntlm; 27 | 28 | 29 | import org.jetbrains.annotations.Nullable; 30 | 31 | /** 32 | * Signals NTLM protocol failure. 33 | */ 34 | class NtlmEngineException extends RuntimeException { 35 | 36 | private static final long serialVersionUID = 6027981323731768824L; 37 | 38 | /** 39 | * Creates a new NTLMEngineException with the specified message. 40 | * 41 | * @param message the exception detail message 42 | */ 43 | NtlmEngineException(String message) { 44 | super(message); 45 | } 46 | 47 | /** 48 | * Creates a new NTLMEngineException with the specified detail message and cause. 49 | * 50 | * @param message the exception detail message 51 | * @param cause the Throwable that caused this exception, or null 52 | * if the cause is unavailable, unknown, or not a Throwable 53 | */ 54 | NtlmEngineException(@Nullable String message, Throwable cause) { 55 | super(message, cause); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/proxy/ProxyServerSelector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.proxy; 17 | 18 | import org.asynchttpclient.uri.Uri; 19 | import org.jetbrains.annotations.Nullable; 20 | 21 | /** 22 | * Selector for a proxy server 23 | */ 24 | @FunctionalInterface 25 | public interface ProxyServerSelector { 26 | 27 | /** 28 | * A selector that always selects no proxy. 29 | */ 30 | ProxyServerSelector NO_PROXY_SELECTOR = uri -> null; 31 | 32 | /** 33 | * Select a proxy server to use for the given URI. 34 | * 35 | * @param uri The URI to select a proxy server for. 36 | * @return The proxy server to use, if any. May return null. 37 | */ 38 | @Nullable 39 | ProxyServer select(Uri uri); 40 | } 41 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/proxy/ProxyType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.proxy; 17 | 18 | public enum ProxyType { 19 | HTTP(true), SOCKS_V4(false), SOCKS_V5(false); 20 | 21 | private final boolean http; 22 | 23 | ProxyType(boolean http) { 24 | this.http = http; 25 | } 26 | 27 | public boolean isHttp() { 28 | return http; 29 | } 30 | 31 | public boolean isSocks() { 32 | return !isHttp(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/request/body/Body.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012 Sonatype, Inc. 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 http://www.apache.org/licenses/LICENSE-2.0. 7 | * 8 | * Unless required by applicable law or agreed to in writing, 9 | * software distributed under the Apache License Version 2.0 is distributed on an 10 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. 12 | */ 13 | package org.asynchttpclient.request.body; 14 | 15 | import io.netty.buffer.ByteBuf; 16 | 17 | import java.io.Closeable; 18 | import java.io.IOException; 19 | 20 | /** 21 | * A request body. 22 | */ 23 | public interface Body extends Closeable { 24 | 25 | /** 26 | * Gets the length of the body. 27 | * 28 | * @return The length of the body in bytes, or negative if unknown. 29 | */ 30 | long getContentLength(); 31 | 32 | /** 33 | * Reads the next chunk of bytes from the body. 34 | * 35 | * @param target The buffer to store the chunk in, must not be {@code null}. 36 | * @return The state. 37 | * @throws IOException If the chunk could not be read. 38 | */ 39 | BodyState transferTo(ByteBuf target) throws IOException; 40 | 41 | enum BodyState { 42 | 43 | /** 44 | * There's something to read 45 | */ 46 | CONTINUE, 47 | 48 | /** 49 | * There's nothing to read and input has to suspend 50 | */ 51 | SUSPEND, 52 | 53 | /** 54 | * There's nothing to read and input has to stop 55 | */ 56 | STOP 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/request/body/RandomAccessBody.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012 Sonatype, Inc. 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 http://www.apache.org/licenses/LICENSE-2.0. 7 | * 8 | * Unless required by applicable law or agreed to in writing, 9 | * software distributed under the Apache License Version 2.0 is distributed on an 10 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. 12 | */ 13 | package org.asynchttpclient.request.body; 14 | 15 | import java.io.IOException; 16 | import java.nio.channels.WritableByteChannel; 17 | 18 | /** 19 | * A request body which supports random access to its contents. 20 | */ 21 | public interface RandomAccessBody extends Body { 22 | 23 | /** 24 | * Transfers the specified chunk of bytes from this body to the specified channel. 25 | * 26 | * @param target The destination channel to transfer the body chunk to, must not be {@code null}. 27 | * @return The non-negative number of bytes actually transferred. 28 | * @throws IOException If the body chunk could not be transferred. 29 | */ 30 | long transferTo(WritableByteChannel target) throws IOException; 31 | } 32 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/request/body/generator/BodyChunk.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.request.body.generator; 17 | 18 | import io.netty.buffer.ByteBuf; 19 | 20 | public final class BodyChunk { 21 | public final boolean last; 22 | public final ByteBuf buffer; 23 | 24 | BodyChunk(ByteBuf buffer, boolean last) { 25 | this.buffer = buffer; 26 | this.last = last; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/request/body/generator/BodyGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012 Sonatype, Inc. 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 http://www.apache.org/licenses/LICENSE-2.0. 7 | * 8 | * Unless required by applicable law or agreed to in writing, 9 | * software distributed under the Apache License Version 2.0 is distributed on an 10 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. 12 | */ 13 | package org.asynchttpclient.request.body.generator; 14 | 15 | import org.asynchttpclient.request.body.Body; 16 | 17 | /** 18 | * Creates a request body. 19 | */ 20 | @FunctionalInterface 21 | public interface BodyGenerator { 22 | 23 | /** 24 | * Creates a new instance of the request body to be read. While each invocation of this method is supposed to create 25 | * a fresh instance of the body, the actual contents of all these body instances is the same. For example, the body 26 | * needs to be resent after an authentication challenge of a redirect. 27 | * 28 | * @return The request body, never {@code null}. 29 | */ 30 | Body createBody(); 31 | } 32 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/request/body/generator/BoundedQueueFeedableBodyGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.request.body.generator; 17 | 18 | import java.util.concurrent.ArrayBlockingQueue; 19 | import java.util.concurrent.BlockingQueue; 20 | 21 | public final class BoundedQueueFeedableBodyGenerator extends QueueBasedFeedableBodyGenerator> { 22 | 23 | public BoundedQueueFeedableBodyGenerator(int capacity) { 24 | super(new ArrayBlockingQueue<>(capacity, true)); 25 | } 26 | 27 | @Override 28 | protected boolean offer(BodyChunk chunk) throws InterruptedException { 29 | return queue.offer(chunk); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/request/body/generator/ByteArrayBodyGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012 Sonatype, Inc. 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 http://www.apache.org/licenses/LICENSE-2.0. 7 | * 8 | * Unless required by applicable law or agreed to in writing, 9 | * software distributed under the Apache License Version 2.0 is distributed on an 10 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. 12 | */ 13 | package org.asynchttpclient.request.body.generator; 14 | 15 | import io.netty.buffer.ByteBuf; 16 | import org.asynchttpclient.request.body.Body; 17 | 18 | /** 19 | * A {@link BodyGenerator} backed by a byte array. 20 | */ 21 | public final class ByteArrayBodyGenerator implements BodyGenerator { 22 | 23 | private final byte[] bytes; 24 | 25 | public ByteArrayBodyGenerator(byte[] bytes) { 26 | this.bytes = bytes; 27 | } 28 | 29 | @Override 30 | public Body createBody() { 31 | return new ByteBody(); 32 | } 33 | 34 | protected final class ByteBody implements Body { 35 | private boolean eof; 36 | private int lastPosition; 37 | 38 | @Override 39 | public long getContentLength() { 40 | return bytes.length; 41 | } 42 | 43 | @Override 44 | public BodyState transferTo(ByteBuf target) { 45 | if (eof) { 46 | return BodyState.STOP; 47 | } 48 | 49 | final int remaining = bytes.length - lastPosition; 50 | final int initialTargetWritableBytes = target.writableBytes(); 51 | if (remaining <= initialTargetWritableBytes) { 52 | target.writeBytes(bytes, lastPosition, remaining); 53 | eof = true; 54 | } else { 55 | target.writeBytes(bytes, lastPosition, initialTargetWritableBytes); 56 | lastPosition += initialTargetWritableBytes; 57 | } 58 | return BodyState.CONTINUE; 59 | } 60 | 61 | @Override 62 | public void close() { 63 | lastPosition = 0; 64 | eof = false; 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/request/body/generator/FeedListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.request.body.generator; 17 | 18 | public interface FeedListener { 19 | void onContentAdded(); 20 | 21 | void onError(Throwable t); 22 | } 23 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/request/body/generator/FeedableBodyGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2024 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.request.body.generator; 17 | 18 | import io.netty.buffer.ByteBuf; 19 | 20 | /** 21 | * {@link BodyGenerator} which may return just part of the payload at the time handler is requesting it. 22 | * If it happens, client becomes responsible for providing the rest of the chunks. 23 | */ 24 | public interface FeedableBodyGenerator extends BodyGenerator { 25 | 26 | boolean feed(ByteBuf buffer, boolean isLast) throws Exception; 27 | 28 | void setListener(FeedListener listener); 29 | } 30 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/request/body/generator/FileBodyGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012 Sonatype, Inc. 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 http://www.apache.org/licenses/LICENSE-2.0. 7 | * 8 | * Unless required by applicable law or agreed to in writing, 9 | * software distributed under the Apache License Version 2.0 is distributed on an 10 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. 12 | */ 13 | package org.asynchttpclient.request.body.generator; 14 | 15 | import org.asynchttpclient.request.body.RandomAccessBody; 16 | 17 | import java.io.File; 18 | 19 | import static java.util.Objects.requireNonNull; 20 | 21 | /** 22 | * Creates a request body from the contents of a file. 23 | */ 24 | public final class FileBodyGenerator implements BodyGenerator { 25 | 26 | private final File file; 27 | private final long regionSeek; 28 | private final long regionLength; 29 | 30 | public FileBodyGenerator(File file) { 31 | this(file, 0L, file.length()); 32 | } 33 | 34 | public FileBodyGenerator(File file, long regionSeek, long regionLength) { 35 | this.file = requireNonNull(file, "file"); 36 | this.regionLength = regionLength; 37 | this.regionSeek = regionSeek; 38 | } 39 | 40 | public File getFile() { 41 | return file; 42 | } 43 | 44 | public long getRegionLength() { 45 | return regionLength; 46 | } 47 | 48 | public long getRegionSeek() { 49 | return regionSeek; 50 | } 51 | 52 | @Override 53 | public RandomAccessBody createBody() { 54 | throw new UnsupportedOperationException("FileBodyGenerator.createBody isn't used, Netty direclt sends the file"); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/request/body/generator/QueueBasedFeedableBodyGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.request.body.generator; 17 | 18 | import io.netty.buffer.ByteBuf; 19 | import org.asynchttpclient.request.body.Body; 20 | 21 | import java.util.Queue; 22 | 23 | public abstract class QueueBasedFeedableBodyGenerator> implements FeedableBodyGenerator { 24 | 25 | protected final T queue; 26 | private FeedListener listener; 27 | 28 | protected QueueBasedFeedableBodyGenerator(T queue) { 29 | this.queue = queue; 30 | } 31 | 32 | @Override 33 | public Body createBody() { 34 | return new PushBody(queue); 35 | } 36 | 37 | protected abstract boolean offer(BodyChunk chunk) throws Exception; 38 | 39 | @Override 40 | public boolean feed(final ByteBuf buffer, final boolean isLast) throws Exception { 41 | boolean offered = offer(new BodyChunk(buffer, isLast)); 42 | if (offered && listener != null) { 43 | listener.onContentAdded(); 44 | } 45 | return offered; 46 | } 47 | 48 | @Override 49 | public void setListener(FeedListener listener) { 50 | this.listener = listener; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/request/body/generator/UnboundedQueueFeedableBodyGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2024 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.request.body.generator; 17 | 18 | import java.util.concurrent.ConcurrentLinkedQueue; 19 | 20 | public final class UnboundedQueueFeedableBodyGenerator extends QueueBasedFeedableBodyGenerator> { 21 | 22 | public UnboundedQueueFeedableBodyGenerator() { 23 | super(new ConcurrentLinkedQueue<>()); 24 | } 25 | 26 | @Override 27 | protected boolean offer(BodyChunk chunk) { 28 | return queue.offer(chunk); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/request/body/multipart/ByteArrayPart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2024 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.request.body.multipart; 17 | 18 | import java.nio.charset.Charset; 19 | 20 | import static java.util.Objects.requireNonNull; 21 | 22 | public class ByteArrayPart extends FileLikePart { 23 | 24 | private final byte[] bytes; 25 | 26 | public ByteArrayPart(String name, byte[] bytes) { 27 | this(name, bytes, null); 28 | } 29 | 30 | public ByteArrayPart(String name, byte[] bytes, String contentType) { 31 | this(name, bytes, contentType, null); 32 | } 33 | 34 | public ByteArrayPart(String name, byte[] bytes, String contentType, Charset charset) { 35 | this(name, bytes, contentType, charset, null); 36 | } 37 | 38 | public ByteArrayPart(String name, byte[] bytes, String contentType, Charset charset, String fileName) { 39 | this(name, bytes, contentType, charset, fileName, null); 40 | } 41 | 42 | public ByteArrayPart(String name, byte[] bytes, String contentType, Charset charset, String fileName, String contentId) { 43 | this(name, bytes, contentType, charset, fileName, contentId, null); 44 | } 45 | 46 | public ByteArrayPart(String name, byte[] bytes, String contentType, Charset charset, String fileName, String contentId, String transferEncoding) { 47 | super(name, contentType, charset, fileName, contentId, transferEncoding); 48 | this.bytes = requireNonNull(bytes, "bytes"); 49 | } 50 | 51 | public byte[] getBytes() { 52 | return bytes; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/request/body/multipart/FilePart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2024 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.request.body.multipart; 17 | 18 | import java.io.File; 19 | import java.nio.charset.Charset; 20 | 21 | public class FilePart extends FileLikePart { 22 | 23 | private final File file; 24 | 25 | public FilePart(String name, File file) { 26 | this(name, file, null); 27 | } 28 | 29 | public FilePart(String name, File file, String contentType) { 30 | this(name, file, contentType, null); 31 | } 32 | 33 | public FilePart(String name, File file, String contentType, Charset charset) { 34 | this(name, file, contentType, charset, null); 35 | } 36 | 37 | public FilePart(String name, File file, String contentType, Charset charset, String fileName) { 38 | this(name, file, contentType, charset, fileName, null); 39 | } 40 | 41 | public FilePart(String name, File file, String contentType, Charset charset, String fileName, String contentId) { 42 | this(name, file, contentType, charset, fileName, contentId, null); 43 | } 44 | 45 | public FilePart(String name, File file, String contentType, Charset charset, String fileName, String contentId, String transferEncoding) { 46 | super(name, contentType, charset, fileName != null ? fileName : file.getName(), contentId, transferEncoding); 47 | if (!file.isFile()) { 48 | throw new IllegalArgumentException("File is not a normal file " + file.getAbsolutePath()); 49 | } 50 | if (!file.canRead()) { 51 | throw new IllegalArgumentException("File is not readable " + file.getAbsolutePath()); 52 | } 53 | this.file = file; 54 | } 55 | 56 | public File getFile() { 57 | return file; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/request/body/multipart/Part.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2024 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.request.body.multipart; 17 | 18 | import org.asynchttpclient.Param; 19 | 20 | import java.nio.charset.Charset; 21 | import java.util.List; 22 | 23 | public interface Part { 24 | 25 | /** 26 | * Return the name of this part. 27 | * 28 | * @return The name. 29 | */ 30 | String getName(); 31 | 32 | /** 33 | * Returns the content type of this part. 34 | * 35 | * @return the content type, or {@code null} to exclude the content 36 | * type header 37 | */ 38 | String getContentType(); 39 | 40 | /** 41 | * Return the character encoding of this part. 42 | * 43 | * @return the character encoding, or {@code null} to exclude the 44 | * character encoding header 45 | */ 46 | Charset getCharset(); 47 | 48 | /** 49 | * Return the transfer encoding of this part. 50 | * 51 | * @return the transfer encoding, or {@code null} to exclude the 52 | * transfer encoding header 53 | */ 54 | String getTransferEncoding(); 55 | 56 | /** 57 | * Return the content ID of this part. 58 | * 59 | * @return the content ID, or {@code null} to exclude the content ID 60 | * header 61 | */ 62 | String getContentId(); 63 | 64 | /** 65 | * Gets the disposition-type to be used in Content-Disposition header 66 | * 67 | * @return the disposition-type 68 | */ 69 | String getDispositionType(); 70 | 71 | List getCustomHeaders(); 72 | } 73 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/request/body/multipart/part/ByteArrayMultipartPart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.request.body.multipart.part; 17 | 18 | import io.netty.buffer.ByteBuf; 19 | import io.netty.buffer.Unpooled; 20 | import org.asynchttpclient.request.body.multipart.ByteArrayPart; 21 | 22 | import java.io.IOException; 23 | import java.nio.channels.WritableByteChannel; 24 | 25 | public class ByteArrayMultipartPart extends FileLikeMultipartPart { 26 | 27 | private final ByteBuf contentBuffer; 28 | 29 | public ByteArrayMultipartPart(ByteArrayPart part, byte[] boundary) { 30 | super(part, boundary); 31 | contentBuffer = Unpooled.wrappedBuffer(part.getBytes()); 32 | } 33 | 34 | @Override 35 | protected long getContentLength() { 36 | return part.getBytes().length; 37 | } 38 | 39 | @Override 40 | protected long transferContentTo(ByteBuf target) { 41 | return transfer(contentBuffer, target, MultipartState.POST_CONTENT); 42 | } 43 | 44 | @Override 45 | protected long transferContentTo(WritableByteChannel target) throws IOException { 46 | return transfer(contentBuffer, target, MultipartState.POST_CONTENT); 47 | } 48 | 49 | @Override 50 | public void close() { 51 | super.close(); 52 | contentBuffer.release(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/request/body/multipart/part/FileLikeMultipartPart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.request.body.multipart.part; 17 | 18 | import org.asynchttpclient.request.body.multipart.FileLikePart; 19 | 20 | import static java.nio.charset.StandardCharsets.US_ASCII; 21 | import static java.nio.charset.StandardCharsets.UTF_8; 22 | 23 | public abstract class FileLikeMultipartPart extends MultipartPart { 24 | 25 | /** 26 | * Attachment's file name as a byte array 27 | */ 28 | private static final byte[] FILE_NAME_BYTES = "; filename=".getBytes(US_ASCII); 29 | 30 | FileLikeMultipartPart(T part, byte[] boundary) { 31 | super(part, boundary); 32 | } 33 | 34 | @Override 35 | protected void visitDispositionHeader(PartVisitor visitor) { 36 | super.visitDispositionHeader(visitor); 37 | if (part.getFileName() != null) { 38 | visitor.withBytes(FILE_NAME_BYTES); 39 | visitor.withByte(QUOTE_BYTE); 40 | visitor.withBytes(part.getFileName().getBytes(part.getCharset() != null ? part.getCharset() : UTF_8)); 41 | visitor.withByte(QUOTE_BYTE); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/request/body/multipart/part/MultipartState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.request.body.multipart.part; 17 | 18 | public enum MultipartState { 19 | PRE_CONTENT, 20 | CONTENT, 21 | POST_CONTENT, 22 | DONE 23 | } 24 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/request/body/multipart/part/PartVisitor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2024 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.request.body.multipart.part; 17 | 18 | import io.netty.buffer.ByteBuf; 19 | 20 | public interface PartVisitor { 21 | 22 | void withBytes(byte[] bytes); 23 | 24 | void withByte(byte b); 25 | 26 | class CounterPartVisitor implements PartVisitor { 27 | 28 | private int count; 29 | 30 | @Override 31 | public void withBytes(byte[] bytes) { 32 | count += bytes.length; 33 | } 34 | 35 | @Override 36 | public void withByte(byte b) { 37 | count++; 38 | } 39 | 40 | public int getCount() { 41 | return count; 42 | } 43 | } 44 | 45 | class ByteBufVisitor implements PartVisitor { 46 | private final ByteBuf target; 47 | 48 | public ByteBufVisitor(ByteBuf target) { 49 | this.target = target; 50 | } 51 | 52 | @Override 53 | public void withBytes(byte[] bytes) { 54 | target.writeBytes(bytes); 55 | } 56 | 57 | @Override 58 | public void withByte(byte b) { 59 | target.writeByte(b); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/request/body/multipart/part/StringMultipartPart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.request.body.multipart.part; 17 | 18 | import io.netty.buffer.ByteBuf; 19 | import io.netty.buffer.Unpooled; 20 | import org.asynchttpclient.request.body.multipart.StringPart; 21 | 22 | import java.io.IOException; 23 | import java.nio.channels.WritableByteChannel; 24 | 25 | public class StringMultipartPart extends MultipartPart { 26 | 27 | private final ByteBuf contentBuffer; 28 | 29 | public StringMultipartPart(StringPart part, byte[] boundary) { 30 | super(part, boundary); 31 | contentBuffer = Unpooled.wrappedBuffer(part.getValue().getBytes(part.getCharset())); 32 | } 33 | 34 | @Override 35 | protected long getContentLength() { 36 | return contentBuffer.capacity(); 37 | } 38 | 39 | @Override 40 | protected long transferContentTo(ByteBuf target) { 41 | return transfer(contentBuffer, target, MultipartState.POST_CONTENT); 42 | } 43 | 44 | @Override 45 | protected long transferContentTo(WritableByteChannel target) throws IOException { 46 | return transfer(contentBuffer, target, MultipartState.POST_CONTENT); 47 | } 48 | 49 | @Override 50 | public void close() { 51 | super.close(); 52 | contentBuffer.release(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/spnego/SpnegoEngineException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.spnego; 17 | 18 | import org.jetbrains.annotations.Nullable; 19 | 20 | /** 21 | * Signals SPNEGO protocol failure. 22 | */ 23 | public class SpnegoEngineException extends Exception { 24 | 25 | private static final long serialVersionUID = -3123799505052881438L; 26 | 27 | public SpnegoEngineException(@Nullable String message) { 28 | super(message); 29 | } 30 | 31 | public SpnegoEngineException(@Nullable String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/util/Assertions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.util; 17 | 18 | import org.jetbrains.annotations.Contract; 19 | import org.jetbrains.annotations.Nullable; 20 | 21 | import static java.util.Objects.requireNonNull; 22 | 23 | public final class Assertions { 24 | 25 | private Assertions() { 26 | } 27 | 28 | @Contract(value = "null, _ -> fail", pure = true) 29 | public static String assertNotEmpty(@Nullable String value, String name) { 30 | requireNonNull(value, name); 31 | if (value.length() == 0) { 32 | throw new IllegalArgumentException("empty " + name); 33 | } 34 | return value; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/util/Counted.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.util; 17 | 18 | import org.asynchttpclient.AsyncHttpClient; 19 | 20 | /** 21 | * An interface that defines useful methods to check how many {@linkplain AsyncHttpClient} 22 | * instances this particular implementation is shared with. 23 | */ 24 | public interface Counted { 25 | 26 | /** 27 | * Increment counter and return the incremented value 28 | */ 29 | int incrementAndGet(); 30 | 31 | /** 32 | * Decrement counter and return the decremented value 33 | */ 34 | int decrementAndGet(); 35 | 36 | /** 37 | * Return the current counter 38 | */ 39 | int count(); 40 | } 41 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/util/DateUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.util; 17 | 18 | public final class DateUtils { 19 | 20 | private DateUtils() { 21 | // Prevent outside initialization 22 | } 23 | 24 | public static long unpreciseMillisTime() { 25 | return System.currentTimeMillis(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/util/EnsuresNonNull.java: -------------------------------------------------------------------------------- 1 | package org.asynchttpclient.util; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * NullAway supports @EnsuresNonNull(param) annotation, but org.jetbrains.annotations doesn't include this annotation. 10 | * The purpose of this annotation is to tell NullAway that if the annotated method succeeded without any exceptions, 11 | * all class's fields defined in "param" will be @NotNull. 12 | */ 13 | @Retention(RetentionPolicy.CLASS) 14 | @Target(ElementType.METHOD) 15 | public @interface EnsuresNonNull { 16 | String[] value(); 17 | } 18 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/util/MessageDigestUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.util; 17 | 18 | import java.security.MessageDigest; 19 | import java.security.NoSuchAlgorithmException; 20 | 21 | public final class MessageDigestUtils { 22 | 23 | private static final ThreadLocal MD5_MESSAGE_DIGESTS = ThreadLocal.withInitial(() -> { 24 | try { 25 | return MessageDigest.getInstance("MD5"); 26 | } catch (NoSuchAlgorithmException e) { 27 | throw new InternalError("MD5 not supported on this platform"); 28 | } 29 | }); 30 | 31 | private static final ThreadLocal SHA1_MESSAGE_DIGESTS = ThreadLocal.withInitial(() -> { 32 | try { 33 | return MessageDigest.getInstance("SHA1"); 34 | } catch (NoSuchAlgorithmException e) { 35 | throw new InternalError("SHA1 not supported on this platform"); 36 | } 37 | }); 38 | 39 | private MessageDigestUtils() { 40 | // Prevent outside initialization 41 | } 42 | 43 | public static MessageDigest pooledMd5MessageDigest() { 44 | MessageDigest md = MD5_MESSAGE_DIGESTS.get(); 45 | md.reset(); 46 | return md; 47 | } 48 | 49 | public static MessageDigest pooledSha1MessageDigest() { 50 | MessageDigest md = SHA1_MESSAGE_DIGESTS.get(); 51 | md.reset(); 52 | return md; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/util/StringBuilderPool.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.util; 17 | 18 | public class StringBuilderPool { 19 | 20 | public static final StringBuilderPool DEFAULT = new StringBuilderPool(); 21 | 22 | private final ThreadLocal pool = ThreadLocal.withInitial(() -> new StringBuilder(512)); 23 | 24 | /** 25 | * BEWARE: MUSTN'T APPEND TO ITSELF! 26 | * 27 | * @return a pooled StringBuilder 28 | */ 29 | public StringBuilder stringBuilder() { 30 | StringBuilder sb = pool.get(); 31 | sb.setLength(0); 32 | return sb; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/util/StringUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2024 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.util; 17 | 18 | import java.nio.ByteBuffer; 19 | import java.nio.CharBuffer; 20 | import java.nio.charset.Charset; 21 | 22 | public final class StringUtils { 23 | 24 | private StringUtils() { 25 | // Prevent outside initialization 26 | } 27 | 28 | public static ByteBuffer charSequence2ByteBuffer(CharSequence cs, Charset charset) { 29 | return charset.encode(CharBuffer.wrap(cs)); 30 | } 31 | 32 | public static byte[] byteBuffer2ByteArray(ByteBuffer bb) { 33 | byte[] rawBase = new byte[bb.remaining()]; 34 | bb.get(rawBase); 35 | return rawBase; 36 | } 37 | 38 | public static byte[] charSequence2Bytes(CharSequence sb, Charset charset) { 39 | ByteBuffer bb = charSequence2ByteBuffer(sb, charset); 40 | return byteBuffer2ByteArray(bb); 41 | } 42 | 43 | public static String toHexString(byte[] data) { 44 | StringBuilder buffer = StringBuilderPool.DEFAULT.stringBuilder(); 45 | for (byte aData : data) { 46 | buffer.append(Integer.toHexString((aData & 0xf0) >>> 4)); 47 | buffer.append(Integer.toHexString(aData & 0x0f)); 48 | } 49 | return buffer.toString(); 50 | } 51 | 52 | public static void appendBase16(StringBuilder buf, byte[] bytes) { 53 | int base = 16; 54 | for (byte b : bytes) { 55 | int bi = 0xff & b; 56 | int c = '0' + bi / base % base; 57 | if (c > '9') { 58 | c = 'a' + c - '0' - 10; 59 | } 60 | buf.append((char) c); 61 | c = '0' + bi % base; 62 | if (c > '9') { 63 | c = 'a' + c - '0' - 10; 64 | } 65 | buf.append((char) c); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/util/ThrowableUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.util; 17 | 18 | public final class ThrowableUtil { 19 | 20 | private ThrowableUtil() { 21 | // Prevent outside initialization 22 | } 23 | 24 | /** 25 | * @param the Throwable type 26 | * @param t the throwable whose stacktrace we want to remove 27 | * @param clazz the caller class 28 | * @param method the caller method 29 | * @return the input throwable with removed stacktrace 30 | */ 31 | public static T unknownStackTrace(T t, Class clazz, String method) { 32 | t.setStackTrace(new StackTraceElement[]{new StackTraceElement(clazz.getName(), method, null, -1)}); 33 | return t; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /client/src/main/java/org/asynchttpclient/ws/WebSocketUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2024 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.ws; 17 | 18 | import io.netty.util.internal.ThreadLocalRandom; 19 | 20 | import java.util.Base64; 21 | 22 | import static java.nio.charset.StandardCharsets.US_ASCII; 23 | import static org.asynchttpclient.util.MessageDigestUtils.pooledSha1MessageDigest; 24 | 25 | public final class WebSocketUtils { 26 | private static final String MAGIC_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; 27 | 28 | private WebSocketUtils() { 29 | // Prevent outside initialization 30 | } 31 | 32 | public static String getWebSocketKey() { 33 | byte[] nonce = new byte[16]; 34 | ThreadLocalRandom random = ThreadLocalRandom.current(); 35 | for (int i = 0; i < nonce.length; i++) { 36 | nonce[i] = (byte) random.nextInt(256); 37 | } 38 | return Base64.getEncoder().encodeToString(nonce); 39 | } 40 | 41 | public static String getAcceptKey(String key) { 42 | return Base64.getEncoder().encodeToString(pooledSha1MessageDigest().digest((key + MAGIC_GUID).getBytes(US_ASCII))); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /client/src/main/resources/org/asynchttpclient/config/ahc-version.properties: -------------------------------------------------------------------------------- 1 | ahc.version=${pom.version} -------------------------------------------------------------------------------- /client/src/test/java/org/apache/commons/fileupload2/FileItemFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.fileupload2; 18 | 19 | /** 20 | *

A factory interface for creating {@link FileItem} instances. Factories 21 | * can provide their own custom configuration, over and above that provided 22 | * by the default file upload implementation.

23 | */ 24 | public interface FileItemFactory { 25 | 26 | /** 27 | * Create a new {@link FileItem} instance from the supplied parameters and 28 | * any local factory configuration. 29 | * 30 | * @param fieldName The name of the form field. 31 | * @param contentType The content type of the form field. 32 | * @param isFormField {@code true} if this is a plain form field; 33 | * {@code false} otherwise. 34 | * @param fileName The name of the uploaded file, if any, as supplied 35 | * by the browser or other client. 36 | * @return The newly created file item. 37 | */ 38 | FileItem createItem( 39 | String fieldName, 40 | String contentType, 41 | boolean isFormField, 42 | String fileName 43 | ); 44 | 45 | } 46 | -------------------------------------------------------------------------------- /client/src/test/java/org/apache/commons/fileupload2/FileItemHeadersSupport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.fileupload2; 18 | 19 | /** 20 | * Interface that will indicate that {@link FileItem} or {@link FileItemStream} 21 | * implementations will accept the headers read for the item. 22 | * 23 | * @see FileItem 24 | * @see FileItemStream 25 | * @since 1.2.1 26 | */ 27 | public interface FileItemHeadersSupport { 28 | 29 | /** 30 | * Returns the collection of headers defined locally within this item. 31 | * 32 | * @return the {@link FileItemHeaders} present for this item. 33 | */ 34 | FileItemHeaders getHeaders(); 35 | 36 | /** 37 | * Sets the headers read from within an item. Implementations of 38 | * {@link FileItem} or {@link FileItemStream} should implement this 39 | * interface to be able to get the raw headers found within the item 40 | * header block. 41 | * 42 | * @param headers the instance that holds onto the headers 43 | * for this instance. 44 | */ 45 | void setHeaders(FileItemHeaders headers); 46 | 47 | } 48 | -------------------------------------------------------------------------------- /client/src/test/java/org/apache/commons/fileupload2/InvalidFileNameException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.fileupload2; 18 | 19 | /** 20 | * This exception is thrown in case of an invalid file name. 21 | * A file name is invalid, if it contains a NUL character. 22 | * Attackers might use this to circumvent security checks: 23 | * For example, a malicious user might upload a file with the name 24 | * "foo.exe\0.png". This file name might pass security checks (i.e. 25 | * checks for the extension ".png"), while, depending on the underlying 26 | * C library, it might create a file named "foo.exe", as the NUL 27 | * character is the string terminator in C. 28 | */ 29 | public class InvalidFileNameException extends RuntimeException { 30 | 31 | /** 32 | * Serial version UID, being used, if the exception 33 | * is serialized. 34 | */ 35 | private static final long serialVersionUID = 7922042602454350470L; 36 | 37 | /** 38 | * The file name causing the exception. 39 | */ 40 | private final String name; 41 | 42 | /** 43 | * Creates a new instance. 44 | * 45 | * @param pName The file name causing the exception. 46 | * @param pMessage A human readable error message. 47 | */ 48 | public InvalidFileNameException(final String pName, final String pMessage) { 49 | super(pMessage); 50 | name = pName; 51 | } 52 | 53 | /** 54 | * Returns the invalid file name. 55 | * 56 | * @return the invalid file name. 57 | */ 58 | public String getName() { 59 | return name; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /client/src/test/java/org/apache/commons/fileupload2/ProgressListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.fileupload2; 18 | 19 | /** 20 | * The {@link ProgressListener} may be used to display a progress bar 21 | * or do stuff like that. 22 | */ 23 | public interface ProgressListener { 24 | 25 | /** 26 | * Updates the listeners status information. 27 | * 28 | * @param pBytesRead The total number of bytes, which have been read 29 | * so far. 30 | * @param pContentLength The total number of bytes, which are being 31 | * read. May be -1, if this number is unknown. 32 | * @param pItems The number of the field, which is currently being 33 | * read. (0 = no item so far, 1 = first item is being read, ...) 34 | */ 35 | void update(long pBytesRead, long pContentLength, int pItems); 36 | 37 | } 38 | -------------------------------------------------------------------------------- /client/src/test/java/org/apache/commons/fileupload2/RequestContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.fileupload2; 18 | 19 | import java.io.IOException; 20 | import java.io.InputStream; 21 | 22 | /** 23 | *

Abstracts access to the request information needed for file uploads. This 24 | * interface should be implemented for each type of request that may be 25 | * handled by FileUpload, such as servlets and portlets.

26 | * 27 | * @since 1.1 28 | */ 29 | public interface RequestContext { 30 | 31 | /** 32 | * Retrieve the character encoding for the request. 33 | * 34 | * @return The character encoding for the request. 35 | */ 36 | String getCharacterEncoding(); 37 | 38 | /** 39 | * Retrieve the content type of the request. 40 | * 41 | * @return The content type of the request. 42 | */ 43 | String getContentType(); 44 | 45 | /** 46 | * Retrieve the content length of the request. 47 | * 48 | * @return The content length of the request. 49 | * @deprecated 1.3 Use {@link UploadContext#contentLength()} instead 50 | */ 51 | @Deprecated 52 | int getContentLength(); 53 | 54 | /** 55 | * Retrieve the input stream for the request. 56 | * 57 | * @return The input stream for the request. 58 | * @throws IOException if a problem occurs. 59 | */ 60 | InputStream getInputStream() throws IOException; 61 | 62 | } 63 | -------------------------------------------------------------------------------- /client/src/test/java/org/apache/commons/fileupload2/UploadContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.fileupload2; 18 | 19 | /** 20 | * Enhanced access to the request information needed for file uploads, 21 | * which fixes the Content Length data access in {@link RequestContext}. 22 | *

23 | * The reason of introducing this new interface is just for backward compatibility 24 | * and it might vanish for a refactored 2.x version moving the new method into 25 | * RequestContext again. 26 | * 27 | * @since 1.3 28 | */ 29 | public interface UploadContext extends RequestContext { 30 | 31 | /** 32 | * Retrieve the content length of the request. 33 | * 34 | * @return The content length of the request. 35 | * @since 1.3 36 | */ 37 | long contentLength(); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /client/src/test/java/org/apache/commons/fileupload2/disk/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | *

20 | * A disk-based implementation of the 21 | * {@link org.apache.commons.fileupload2.FileItem FileItem} 22 | * interface. This implementation retains smaller items in memory, while 23 | * writing larger ones to disk. The threshold between these two is 24 | * configurable, as is the location of files that are written to disk. 25 | *

26 | *

27 | * In typical usage, an instance of 28 | * {@link org.apache.commons.fileupload2.disk.DiskFileItemFactory DiskFileItemFactory} 29 | * would be created, configured, and then passed to a 30 | * {@link org.apache.commons.fileupload2.FileUpload FileUpload} 31 | * implementation such as 32 | * {@link org.apache.commons.fileupload2.servlet.ServletFileUpload ServletFileUpload} 33 | * or 34 | * {@link org.apache.commons.fileupload2.portlet.PortletFileUpload PortletFileUpload}. 35 | *

36 | *

37 | * The following code fragment demonstrates this usage. 38 | *

39 | *
40 |  *        DiskFileItemFactory factory = new DiskFileItemFactory();
41 |  *        // maximum size that will be stored in memory
42 |  *        factory.setSizeThreshold(4096);
43 |  *        // the location for saving data that is larger than getSizeThreshold()
44 |  *        factory.setRepository(new File("/tmp"));
45 |  *
46 |  *        ServletFileUpload upload = new ServletFileUpload(factory);
47 |  * 
48 | *

49 | * Please see the FileUpload 50 | * User Guide 51 | * for further details and examples of how to use this package. 52 | *

53 | */ 54 | package org.apache.commons.fileupload2.disk; 55 | -------------------------------------------------------------------------------- /client/src/test/java/org/apache/commons/fileupload2/impl/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Implementations and exceptions utils. 20 | */ 21 | package org.apache.commons.fileupload2.impl; 22 | -------------------------------------------------------------------------------- /client/src/test/java/org/apache/commons/fileupload2/jaksrvlt/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | *

20 | * An implementation of 21 | * {@link org.apache.commons.fileupload2.FileUpload FileUpload} 22 | * for use in servlets conforming to the namespace {@code jakarta.servlet}. 23 | * 24 | *

25 | *

26 | * The following code fragment demonstrates typical usage. 27 | *

28 | *
29 |  *        DiskFileItemFactory factory = new DiskFileItemFactory();
30 |  *        // Configure the factory here, if desired.
31 |  *        JakSrvltFileUpload upload = new JakSrvltFileUpload(factory);
32 |  *        // Configure the uploader here, if desired.
33 |  *        List fileItems = upload.parseRequest(request);
34 |  * 
35 | *

36 | * Please see the FileUpload 37 | * User Guide 38 | * for further details and examples of how to use this package. 39 | *

40 | */ 41 | package org.apache.commons.fileupload2.jaksrvlt; 42 | -------------------------------------------------------------------------------- /client/src/test/java/org/apache/commons/fileupload2/portlet/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | *

20 | * An implementation of 21 | * {@link org.apache.commons.fileupload2.FileUpload FileUpload} 22 | * for use in portlets conforming to JSR 168. This implementation requires 23 | * only access to the portlet's current {@code ActionRequest} instance, 24 | * and a suitable 25 | * {@link org.apache.commons.fileupload2.FileItemFactory FileItemFactory} 26 | * implementation, such as 27 | * {@link org.apache.commons.fileupload2.disk.DiskFileItemFactory DiskFileItemFactory}. 28 | *

29 | *

30 | * The following code fragment demonstrates typical usage. 31 | *

32 | *
33 |  *        DiskFileItemFactory factory = new DiskFileItemFactory();
34 |  *        // Configure the factory here, if desired.
35 |  *        PortletFileUpload upload = new PortletFileUpload(factory);
36 |  *        // Configure the uploader here, if desired.
37 |  *        List fileItems = upload.parseRequest(request);
38 |  * 
39 | *

40 | * Please see the FileUpload 41 | * User Guide 42 | * for further details and examples of how to use this package. 43 | *

44 | */ 45 | package org.apache.commons.fileupload2.portlet; 46 | -------------------------------------------------------------------------------- /client/src/test/java/org/apache/commons/fileupload2/pub/FileUploadIOException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.fileupload2.pub; 18 | 19 | import org.apache.commons.fileupload2.FileUploadException; 20 | 21 | import java.io.IOException; 22 | 23 | /** 24 | * This exception is thrown for hiding an inner 25 | * {@link FileUploadException} in an {@link IOException}. 26 | */ 27 | public class FileUploadIOException extends IOException { 28 | 29 | /** 30 | * The exceptions UID, for serializing an instance. 31 | */ 32 | private static final long serialVersionUID = -7047616958165584154L; 33 | 34 | /** 35 | * The exceptions cause; we overwrite the parent 36 | * classes field, which is available since Java 37 | * 1.4 only. 38 | */ 39 | private final FileUploadException cause; 40 | 41 | /** 42 | * Creates a {@code FileUploadIOException} with the 43 | * given cause. 44 | * 45 | * @param pCause The exceptions cause, if any, or null. 46 | */ 47 | public FileUploadIOException(final FileUploadException pCause) { 48 | // We're not doing super(pCause) cause of 1.3 compatibility. 49 | cause = pCause; 50 | } 51 | 52 | /** 53 | * Returns the exceptions cause. 54 | * 55 | * @return The exceptions cause, if any, or null. 56 | */ 57 | @Override 58 | public Throwable getCause() { 59 | return cause; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /client/src/test/java/org/apache/commons/fileupload2/pub/IOFileUploadException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.fileupload2.pub; 18 | 19 | import org.apache.commons.fileupload2.FileUploadException; 20 | 21 | import java.io.IOException; 22 | 23 | /** 24 | * Thrown to indicate an IOException. 25 | */ 26 | public class IOFileUploadException extends FileUploadException { 27 | 28 | /** 29 | * The exceptions UID, for serializing an instance. 30 | */ 31 | private static final long serialVersionUID = 1749796615868477269L; 32 | 33 | /** 34 | * The exceptions cause; we overwrite the parent 35 | * classes field, which is available since Java 36 | * 1.4 only. 37 | */ 38 | private final IOException cause; 39 | 40 | /** 41 | * Creates a new instance with the given cause. 42 | * 43 | * @param pMsg The detail message. 44 | * @param pException The exceptions cause. 45 | */ 46 | public IOFileUploadException(final String pMsg, final IOException pException) { 47 | super(pMsg); 48 | cause = pException; 49 | } 50 | 51 | /** 52 | * Returns the exceptions cause. 53 | * 54 | * @return The exceptions cause, if any, or null. 55 | */ 56 | @Override 57 | public Throwable getCause() { 58 | return cause; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /client/src/test/java/org/apache/commons/fileupload2/pub/InvalidContentTypeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.fileupload2.pub; 18 | 19 | import org.apache.commons.fileupload2.FileUploadException; 20 | 21 | /** 22 | * Thrown to indicate that the request is not a multipart request. 23 | */ 24 | public class InvalidContentTypeException 25 | extends FileUploadException { 26 | 27 | /** 28 | * The exceptions UID, for serializing an instance. 29 | */ 30 | private static final long serialVersionUID = -9073026332015646668L; 31 | 32 | /** 33 | * Constructs a {@code InvalidContentTypeException} with no 34 | * detail message. 35 | */ 36 | public InvalidContentTypeException() { 37 | } 38 | 39 | /** 40 | * Constructs an {@code InvalidContentTypeException} with 41 | * the specified detail message. 42 | * 43 | * @param message The detail message. 44 | */ 45 | public InvalidContentTypeException(final String message) { 46 | super(message); 47 | } 48 | 49 | /** 50 | * Constructs an {@code InvalidContentTypeException} with 51 | * the specified detail message and cause. 52 | * 53 | * @param msg The detail message. 54 | * @param cause the original cause 55 | * @since 1.3.1 56 | */ 57 | public InvalidContentTypeException(final String msg, final Throwable cause) { 58 | super(msg, cause); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /client/src/test/java/org/apache/commons/fileupload2/pub/SizeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.fileupload2.pub; 18 | 19 | import org.apache.commons.fileupload2.FileUploadException; 20 | 21 | /** 22 | * This exception is thrown, if a requests permitted size 23 | * is exceeded. 24 | */ 25 | abstract class SizeException extends FileUploadException { 26 | 27 | /** 28 | * Serial version UID, being used, if serialized. 29 | */ 30 | private static final long serialVersionUID = -8776225574705254126L; 31 | 32 | /** 33 | * The actual size of the request. 34 | */ 35 | private final long actual; 36 | 37 | /** 38 | * The maximum permitted size of the request. 39 | */ 40 | private final long permitted; 41 | 42 | /** 43 | * Creates a new instance. 44 | * 45 | * @param message The detail message. 46 | * @param actual The actual number of bytes in the request. 47 | * @param permitted The requests size limit, in bytes. 48 | */ 49 | protected SizeException(final String message, final long actual, final long permitted) { 50 | super(message); 51 | this.actual = actual; 52 | this.permitted = permitted; 53 | } 54 | 55 | /** 56 | * Retrieves the actual size of the request. 57 | * 58 | * @return The actual size of the request. 59 | * @since 1.3 60 | */ 61 | public long getActualSize() { 62 | return actual; 63 | } 64 | 65 | /** 66 | * Retrieves the permitted size of the request. 67 | * 68 | * @return The permitted size of the request. 69 | * @since 1.3 70 | */ 71 | public long getPermittedSize() { 72 | return permitted; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /client/src/test/java/org/apache/commons/fileupload2/pub/SizeLimitExceededException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.fileupload2.pub; 18 | 19 | /** 20 | * Thrown to indicate that the request size exceeds the configured maximum. 21 | */ 22 | public class SizeLimitExceededException 23 | extends SizeException { 24 | 25 | /** 26 | * The exceptions UID, for serializing an instance. 27 | */ 28 | private static final long serialVersionUID = -2474893167098052828L; 29 | 30 | /** 31 | * Constructs a {@code SizeExceededException} with 32 | * the specified detail message, and actual and permitted sizes. 33 | * 34 | * @param message The detail message. 35 | * @param actual The actual request size. 36 | * @param permitted The maximum permitted request size. 37 | */ 38 | public SizeLimitExceededException(final String message, final long actual, 39 | final long permitted) { 40 | super(message, actual, permitted); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /client/src/test/java/org/apache/commons/fileupload2/pub/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Exceptions, and other classes, that are known to be used outside 20 | * of FileUpload. 21 | */ 22 | package org.apache.commons.fileupload2.pub; 23 | -------------------------------------------------------------------------------- /client/src/test/java/org/apache/commons/fileupload2/servlet/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | *

20 | * An implementation of 21 | * {@link org.apache.commons.fileupload2.FileUpload FileUpload} 22 | * for use in servlets conforming to JSR 53. This implementation requires 23 | * only access to the servlet's current {@code HttpServletRequest} 24 | * instance, and a suitable 25 | * {@link org.apache.commons.fileupload2.FileItemFactory FileItemFactory} 26 | * implementation, such as 27 | * {@link org.apache.commons.fileupload2.disk.DiskFileItemFactory DiskFileItemFactory}. 28 | *

29 | *

30 | * The following code fragment demonstrates typical usage. 31 | *

32 | *
33 |  *        DiskFileItemFactory factory = new DiskFileItemFactory();
34 |  *        // Configure the factory here, if desired.
35 |  *        ServletFileUpload upload = new ServletFileUpload(factory);
36 |  *        // Configure the uploader here, if desired.
37 |  *        List fileItems = upload.parseRequest(request);
38 |  * 
39 | *

40 | * Please see the FileUpload 41 | * User Guide 42 | * for further details and examples of how to use this package. 43 | *

44 | */ 45 | package org.apache.commons.fileupload2.servlet; 46 | -------------------------------------------------------------------------------- /client/src/test/java/org/apache/commons/fileupload2/util/Closeable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.fileupload2.util; 18 | 19 | import java.io.IOException; 20 | 21 | /** 22 | * Interface of an object, which may be closed. 23 | */ 24 | public interface Closeable { 25 | 26 | /** 27 | * Closes the object. 28 | * 29 | * @throws IOException An I/O error occurred. 30 | */ 31 | void close() throws IOException; 32 | 33 | /** 34 | * Returns, whether the object is already closed. 35 | * 36 | * @return True, if the object is closed, otherwise false. 37 | * @throws IOException An I/O error occurred. 38 | */ 39 | boolean isClosed() throws IOException; 40 | 41 | } 42 | -------------------------------------------------------------------------------- /client/src/test/java/org/apache/commons/fileupload2/util/mime/ParseException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.fileupload2.util.mime; 18 | 19 | /** 20 | * @since 1.3 21 | */ 22 | final class ParseException extends Exception { 23 | 24 | /** 25 | * The UID to use when serializing this instance. 26 | */ 27 | private static final long serialVersionUID = 5355281266579392077L; 28 | 29 | /** 30 | * Constructs a new exception with the specified detail message. 31 | * 32 | * @param message the detail message. 33 | */ 34 | ParseException(final String message) { 35 | super(message); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /client/src/test/java/org/apache/commons/fileupload2/util/mime/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * MIME decoder implementation, imported and retailed from 20 | * Apache Geronimo. 21 | */ 22 | package org.apache.commons.fileupload2.util.mime; 23 | -------------------------------------------------------------------------------- /client/src/test/java/org/apache/commons/fileupload2/util/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * This package contains various IO related utility classes 20 | * or methods, which are basically reusable and not necessarily 21 | * restricted to the scope of a file upload. 22 | */ 23 | package org.apache.commons.fileupload2.util; 24 | -------------------------------------------------------------------------------- /client/src/test/java/org/asynchttpclient/CustomRemoteAddressTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient; 17 | 18 | import io.github.artsok.RepeatedIfExceptionsTest; 19 | import io.netty.util.internal.SocketUtils; 20 | import org.asynchttpclient.test.TestUtils.AsyncCompletionHandlerAdapter; 21 | import org.asynchttpclient.testserver.HttpServer; 22 | import org.asynchttpclient.testserver.HttpTest; 23 | import org.junit.jupiter.api.AfterEach; 24 | import org.junit.jupiter.api.BeforeEach; 25 | 26 | import static java.util.concurrent.TimeUnit.SECONDS; 27 | import static org.asynchttpclient.Dsl.get; 28 | import static org.asynchttpclient.test.TestUtils.TIMEOUT; 29 | import static org.junit.jupiter.api.Assertions.assertEquals; 30 | 31 | public class CustomRemoteAddressTest extends HttpTest { 32 | 33 | private HttpServer server; 34 | 35 | @BeforeEach 36 | public void start() throws Throwable { 37 | server = new HttpServer(); 38 | server.start(); 39 | } 40 | 41 | @AfterEach 42 | public void stop() throws Throwable { 43 | server.close(); 44 | } 45 | 46 | @RepeatedIfExceptionsTest(repeats = 5) 47 | public void getRootUrlWithCustomRemoteAddress() throws Throwable { 48 | withClient().run(client -> 49 | withServer(server).run(server -> { 50 | String url = server.getHttpUrl(); 51 | server.enqueueOk(); 52 | RequestBuilder request = get(url).setAddress(SocketUtils.addressByName("localhost")); 53 | Response response = client.executeRequest(request, new AsyncCompletionHandlerAdapter()).get(TIMEOUT, SECONDS); 54 | assertEquals(response.getStatusCode(), 200); 55 | })); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /client/src/test/java/org/asynchttpclient/DefaultAsyncHttpClientConfigTest.java: -------------------------------------------------------------------------------- 1 | package org.asynchttpclient; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertFalse; 6 | import static org.junit.jupiter.api.Assertions.assertTrue; 7 | 8 | class DefaultAsyncHttpClientConfigTest { 9 | @Test 10 | void testStripAuthorizationOnRedirect_DefaultIsFalse() { 11 | DefaultAsyncHttpClientConfig config = new DefaultAsyncHttpClientConfig.Builder().build(); 12 | assertFalse(config.isStripAuthorizationOnRedirect(), "Default should be false"); 13 | } 14 | 15 | @Test 16 | void testStripAuthorizationOnRedirect_SetTrue() { 17 | DefaultAsyncHttpClientConfig config = new DefaultAsyncHttpClientConfig.Builder() 18 | .setStripAuthorizationOnRedirect(true) 19 | .build(); 20 | assertTrue(config.isStripAuthorizationOnRedirect(), "Should be true when set"); 21 | } 22 | 23 | @Test 24 | void testStripAuthorizationOnRedirect_SetFalse() { 25 | DefaultAsyncHttpClientConfig config = new DefaultAsyncHttpClientConfig.Builder() 26 | .setStripAuthorizationOnRedirect(false) 27 | .build(); 28 | assertFalse(config.isStripAuthorizationOnRedirect(), "Should be false when set to false"); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /client/src/test/java/org/asynchttpclient/NoNullResponseTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2013 Ning, Inc. 3 | * 4 | * This program is licensed to you under the Apache License, version 2.0 5 | * (the "License"); you may not use this file except in compliance with the 6 | * License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | * 16 | */ 17 | package org.asynchttpclient; 18 | 19 | import org.junit.jupiter.api.RepeatedTest; 20 | 21 | import java.time.Duration; 22 | 23 | import static org.asynchttpclient.Dsl.asyncHttpClient; 24 | import static org.asynchttpclient.Dsl.config; 25 | import static org.junit.jupiter.api.Assertions.assertNotNull; 26 | 27 | public class NoNullResponseTest extends AbstractBasicTest { 28 | private static final String GOOGLE_HTTPS_URL = "https://www.google.com"; 29 | 30 | @RepeatedTest(4) 31 | public void multipleSslRequestsWithDelayAndKeepAlive() throws Exception { 32 | AsyncHttpClientConfig config = config() 33 | .setFollowRedirect(true) 34 | .setKeepAlive(true) 35 | .setConnectTimeout(Duration.ofSeconds(10)) 36 | .setPooledConnectionIdleTimeout(Duration.ofMinutes(1)) 37 | .setRequestTimeout(Duration.ofSeconds(10)) 38 | .setMaxConnectionsPerHost(-1) 39 | .setMaxConnections(-1) 40 | .build(); 41 | 42 | try (AsyncHttpClient client = asyncHttpClient(config)) { 43 | final BoundRequestBuilder builder = client.prepareGet(GOOGLE_HTTPS_URL); 44 | final Response response1 = builder.execute().get(); 45 | Thread.sleep(4000); 46 | final Response response2 = builder.execute().get(); 47 | assertNotNull(response1); 48 | assertNotNull(response2); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /client/src/test/java/org/asynchttpclient/handler/resumable/MapResumableProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.handler.resumable; 17 | 18 | import org.asynchttpclient.handler.resumable.ResumableAsyncHandler.ResumableProcessor; 19 | 20 | import java.util.Collections; 21 | import java.util.HashMap; 22 | import java.util.Map; 23 | 24 | /** 25 | * @author Benjamin Hanzelmann 26 | */ 27 | public class MapResumableProcessor implements ResumableProcessor { 28 | 29 | private final Map map = new HashMap<>(); 30 | 31 | @Override 32 | public void put(String key, long transferredBytes) { 33 | map.put(key, transferredBytes); 34 | } 35 | 36 | @Override 37 | public void remove(String key) { 38 | map.remove(key); 39 | } 40 | 41 | /** 42 | * NOOP 43 | */ 44 | @Override 45 | public void save(Map map) { 46 | 47 | } 48 | 49 | /** 50 | * NOOP 51 | */ 52 | @Override 53 | public Map load() { 54 | return Collections.unmodifiableMap(map); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /client/src/test/java/org/asynchttpclient/handler/resumable/PropertiesBasedResumableProcessorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Sonatype, Inc. 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 http://www.apache.org/licenses/LICENSE-2.0. 7 | * 8 | * Unless required by applicable law or agreed to in writing, 9 | * software distributed under the Apache License Version 2.0 is distributed on an 10 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. 12 | */ 13 | package org.asynchttpclient.handler.resumable; 14 | 15 | import io.github.artsok.RepeatedIfExceptionsTest; 16 | 17 | import java.util.Map; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertEquals; 20 | 21 | /** 22 | * @author Benjamin Hanzelmann 23 | */ 24 | public class PropertiesBasedResumableProcessorTest { 25 | 26 | @RepeatedIfExceptionsTest(repeats = 5) 27 | public void testSaveLoad() { 28 | PropertiesBasedResumableProcessor processor = new PropertiesBasedResumableProcessor(); 29 | processor.put("http://localhost/test.url", 15L); 30 | processor.put("http://localhost/test2.url", 50L); 31 | processor.save(null); 32 | processor = new PropertiesBasedResumableProcessor(); 33 | 34 | Map map = processor.load(); 35 | assertEquals(2, map.size()); 36 | assertEquals(Long.valueOf(15L), map.get("http://localhost/test.url")); 37 | assertEquals(Long.valueOf(50L), map.get("http://localhost/test2.url")); 38 | } 39 | 40 | @RepeatedIfExceptionsTest(repeats = 5) 41 | public void testRemove() { 42 | PropertiesBasedResumableProcessor processor = new PropertiesBasedResumableProcessor(); 43 | processor.put("http://localhost/test.url", 15L); 44 | processor.put("http://localhost/test2.url", 50L); 45 | processor.remove("http://localhost/test.url"); 46 | processor.save(null); 47 | processor = new PropertiesBasedResumableProcessor(); 48 | 49 | Map propertiesMap = processor.load(); 50 | assertEquals(1, propertiesMap.size()); 51 | assertEquals(Long.valueOf(50L), propertiesMap.get("http://localhost/test2.url")); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /client/src/test/java/org/asynchttpclient/handler/resumable/ResumableRandomAccessFileListenerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.handler.resumable; 17 | 18 | import io.github.artsok.RepeatedIfExceptionsTest; 19 | 20 | import java.io.IOException; 21 | import java.io.RandomAccessFile; 22 | import java.nio.ByteBuffer; 23 | 24 | import static org.mockito.Mockito.mock; 25 | import static org.mockito.Mockito.verify; 26 | 27 | public class ResumableRandomAccessFileListenerTest { 28 | 29 | @RepeatedIfExceptionsTest(repeats = 5) 30 | public void testOnBytesReceivedBufferHasArray() throws IOException { 31 | RandomAccessFile file = mock(RandomAccessFile.class); 32 | ResumableRandomAccessFileListener listener = new ResumableRandomAccessFileListener(file); 33 | byte[] array = {1, 2, 23, 33}; 34 | ByteBuffer buf = ByteBuffer.wrap(array); 35 | listener.onBytesReceived(buf); 36 | verify(file).write(array, 0, 4); 37 | } 38 | 39 | @RepeatedIfExceptionsTest(repeats = 5) 40 | public void testOnBytesReceivedBufferHasNoArray() throws IOException { 41 | RandomAccessFile file = mock(RandomAccessFile.class); 42 | ResumableRandomAccessFileListener listener = new ResumableRandomAccessFileListener(file); 43 | 44 | byte[] byteArray = {1, 2, 23, 33}; 45 | ByteBuffer buf = ByteBuffer.allocateDirect(4); 46 | buf.put(byteArray); 47 | buf.flip(); 48 | listener.onBytesReceived(buf); 49 | verify(file).write(byteArray); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /client/src/test/java/org/asynchttpclient/netty/NettyTest.java: -------------------------------------------------------------------------------- 1 | package org.asynchttpclient.netty; 2 | 3 | import io.netty.channel.epoll.Epoll; 4 | import io.netty.channel.kqueue.KQueue; 5 | import io.netty.handler.codec.compression.Brotli; 6 | import io.netty.handler.codec.compression.Zstd; 7 | import io.netty.incubator.channel.uring.IOUring; 8 | import org.junit.jupiter.api.Test; 9 | import org.junit.jupiter.api.condition.EnabledOnOs; 10 | import org.junit.jupiter.api.condition.OS; 11 | 12 | import static org.junit.jupiter.api.Assertions.assertTrue; 13 | 14 | public class NettyTest { 15 | @Test 16 | @EnabledOnOs(OS.LINUX) 17 | public void epollIsAvailableOnLinux() { 18 | assertTrue(Epoll.isAvailable()); 19 | } 20 | 21 | @Test 22 | @EnabledOnOs(OS.LINUX) 23 | public void ioUringIsAvailableOnLinux() { 24 | assertTrue(IOUring.isAvailable()); 25 | } 26 | 27 | @Test 28 | @EnabledOnOs(OS.MAC) 29 | public void kqueueIsAvailableOnMac() { 30 | assertTrue(KQueue.isAvailable()); 31 | } 32 | 33 | @Test 34 | @EnabledOnOs(OS.LINUX) 35 | public void brotliIsAvailableOnLinux() { 36 | assertTrue(Brotli.isAvailable()); 37 | } 38 | 39 | @Test 40 | @EnabledOnOs(OS.MAC) 41 | public void brotliIsAvailableOnMac() { 42 | assertTrue(Brotli.isAvailable()); 43 | } 44 | 45 | @Test 46 | @EnabledOnOs(OS.LINUX) 47 | public void zstdIsAvailableOnLinux() { 48 | assertTrue(Zstd.isAvailable()); 49 | } 50 | 51 | @Test 52 | @EnabledOnOs(OS.MAC) 53 | public void zstdIsAvailableOnMac() { 54 | assertTrue(Zstd.isAvailable()); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /client/src/test/java/org/asynchttpclient/netty/channel/SemaphoreRunner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.netty.channel; 17 | 18 | class SemaphoreRunner { 19 | 20 | final ConnectionSemaphore semaphore; 21 | final Thread acquireThread; 22 | 23 | volatile long acquireTime; 24 | volatile Exception acquireException; 25 | 26 | SemaphoreRunner(ConnectionSemaphore semaphore, Object partitionKey) { 27 | this.semaphore = semaphore; 28 | acquireThread = new Thread(() -> { 29 | long beforeAcquire = System.currentTimeMillis(); 30 | try { 31 | semaphore.acquireChannelLock(partitionKey); 32 | } catch (Exception e) { 33 | acquireException = e; 34 | } finally { 35 | acquireTime = System.currentTimeMillis() - beforeAcquire; 36 | } 37 | }); 38 | } 39 | 40 | public void acquire() { 41 | acquireThread.start(); 42 | } 43 | 44 | public void interrupt() { 45 | acquireThread.interrupt(); 46 | } 47 | 48 | public void await() { 49 | try { 50 | acquireThread.join(); 51 | } catch (InterruptedException e) { 52 | throw new RuntimeException(e); 53 | } 54 | } 55 | 56 | public boolean finished() { 57 | return !acquireThread.isAlive(); 58 | } 59 | 60 | public long getAcquireTime() { 61 | return acquireTime; 62 | } 63 | 64 | public Exception getAcquireException() { 65 | return acquireException; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /client/src/test/java/org/asynchttpclient/util/Utf8UrlEncoderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2023 AsyncHttpClient Project. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.asynchttpclient.util; 17 | 18 | import io.github.artsok.RepeatedIfExceptionsTest; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertEquals; 21 | 22 | public class Utf8UrlEncoderTest { 23 | 24 | @RepeatedIfExceptionsTest(repeats = 5) 25 | public void testBasics() { 26 | assertEquals("foobar", Utf8UrlEncoder.encodeQueryElement("foobar")); 27 | assertEquals("a%26b", Utf8UrlEncoder.encodeQueryElement("a&b")); 28 | assertEquals("a%2Bb", Utf8UrlEncoder.encodeQueryElement("a+b")); 29 | } 30 | 31 | @RepeatedIfExceptionsTest(repeats = 5) 32 | public void testPercentageEncoding() { 33 | assertEquals("foobar", Utf8UrlEncoder.percentEncodeQueryElement("foobar")); 34 | assertEquals("foo%2Abar", Utf8UrlEncoder.percentEncodeQueryElement("foo*bar")); 35 | assertEquals("foo~b_ar", Utf8UrlEncoder.percentEncodeQueryElement("foo~b_ar")); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /client/src/test/resources/300k.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsyncHttpClient/async-http-client/eeec3349d367ee0409acc5a63cc8d25f568e5539/client/src/test/resources/300k.png -------------------------------------------------------------------------------- /client/src/test/resources/META-INF/services/org.apache.juli.logging.Log: -------------------------------------------------------------------------------- 1 | org.asynchttpclient.test.Slf4jJuliLog -------------------------------------------------------------------------------- /client/src/test/resources/SimpleTextFile.txt: -------------------------------------------------------------------------------- 1 | This is a simple test file -------------------------------------------------------------------------------- /client/src/test/resources/client.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsyncHttpClient/async-http-client/eeec3349d367ee0409acc5a63cc8d25f568e5539/client/src/test/resources/client.keystore -------------------------------------------------------------------------------- /client/src/test/resources/empty.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsyncHttpClient/async-http-client/eeec3349d367ee0409acc5a63cc8d25f568e5539/client/src/test/resources/empty.txt -------------------------------------------------------------------------------- /client/src/test/resources/gzip.txt.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsyncHttpClient/async-http-client/eeec3349d367ee0409acc5a63cc8d25f568e5539/client/src/test/resources/gzip.txt.gz -------------------------------------------------------------------------------- /client/src/test/resources/kerberos.jaas: -------------------------------------------------------------------------------- 1 | 2 | alice { 3 | com.sun.security.auth.module.Krb5LoginModule required refreshKrb5Config=true useKeyTab=false principal="alice"; 4 | }; 5 | 6 | bob { 7 | com.sun.security.auth.module.Krb5LoginModule required refreshKrb5Config=true useKeyTab=false storeKey=true principal="bob/service.ws.apache.org"; 8 | }; 9 | -------------------------------------------------------------------------------- /client/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %d [%thread] %level %logger - %m%n 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /client/src/test/resources/realm.properties: -------------------------------------------------------------------------------- 1 | user=admin, admin -------------------------------------------------------------------------------- /client/src/test/resources/ssltest-cacerts.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsyncHttpClient/async-http-client/eeec3349d367ee0409acc5a63cc8d25f568e5539/client/src/test/resources/ssltest-cacerts.jks -------------------------------------------------------------------------------- /client/src/test/resources/ssltest-keystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsyncHttpClient/async-http-client/eeec3349d367ee0409acc5a63cc8d25f568e5539/client/src/test/resources/ssltest-keystore.jks -------------------------------------------------------------------------------- /client/src/test/resources/textfile.txt: -------------------------------------------------------------------------------- 1 | filecontent: hello -------------------------------------------------------------------------------- /client/src/test/resources/textfile2.txt: -------------------------------------------------------------------------------- 1 | filecontent: hello2 --------------------------------------------------------------------------------