Skip to content

Commit 435f2c3

Browse files
committed
remove Apache HTTP client and libs
1 parent 674c451 commit 435f2c3

File tree

5 files changed

+179
-8
lines changed

5 files changed

+179
-8
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ _Changes since 1.7.3_
2222
### Fixed
2323
- Crash when selecting the last tab of a HTTP request then switching to a gRPC or WS request
2424

25+
### Optimized
26+
- The app is minified. The app size is decreased by about 1/3.
27+
2528

2629
## [1.7.3] -- 2025-04-29
2730

build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ kotlin {
4242
implementation("org.jetbrains.kotlinx:kotlinx-serialization-cbor:1.6.0")
4343
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor:1.8.1")
4444

45-
implementation("io.github.sunny-chung:httpclient5:5.2.1-inspect-patch5")
45+
// implementation("io.github.sunny-chung:httpclient5:5.2.1-inspect-patch5")
46+
4647
// implementation("com.squareup.okhttp3:okhttp:4.11.0")
4748

4849
// implementation("io.github.sunny-chung:okhttp:4.11.0-patch-1")
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
/*
2+
* ====================================================================
3+
* Licensed to the Apache Software Foundation (ASF) under one
4+
* or more contributor license agreements. See the NOTICE file
5+
* distributed with this work for additional information
6+
* regarding copyright ownership. The ASF licenses this file
7+
* to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance
9+
* with 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,
14+
* software distributed under the License is distributed on an
15+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
* KIND, either express or implied. See the License for the
17+
* specific language governing permissions and limitations
18+
* under the License.
19+
* ====================================================================
20+
*
21+
* This software consists of voluntary contributions made by many
22+
* individuals on behalf of the Apache Software Foundation. For more
23+
* information on the Apache Software Foundation, please see
24+
* <http://www.apache.org/>.
25+
*
26+
*/
27+
package org.apache.hc.core5.http2;
28+
29+
import java.util.concurrent.ConcurrentHashMap;
30+
import java.util.concurrent.ConcurrentMap;
31+
32+
/**
33+
* Errors codes defined by HTTP/2 specification.
34+
*
35+
* @since 5.0
36+
*/
37+
public enum H2Error {
38+
39+
/**
40+
* Graceful shutdown
41+
* <p>
42+
* The associated condition is not as a result of an error.
43+
*/
44+
NO_ERROR (0x00),
45+
46+
/**
47+
* Protocol error detected
48+
* <p>
49+
* The endpoint detected an unspecific protocol error. This error is for use when a more
50+
* specific error code is not available
51+
*/
52+
PROTOCOL_ERROR (0x01),
53+
54+
/**
55+
* Implementation fault
56+
* <p>
57+
* The endpoint encountered an unexpected internal error.
58+
*/
59+
INTERNAL_ERROR (0x02),
60+
61+
/**
62+
* Flow control limits exceeded.
63+
* <p>
64+
* The endpoint detected that its peer violated the flow control protocol.
65+
*/
66+
FLOW_CONTROL_ERROR (0x03),
67+
68+
/**
69+
* Settings not acknowledged.
70+
* <p>
71+
* The endpoint sent a SETTINGS frame, but did not receive a response in a timely manner.
72+
*/
73+
SETTINGS_TIMEOUT (0x04),
74+
75+
/**
76+
* Frame received for closed stream.
77+
* <p>
78+
* The endpoint received a frame after a stream was half closed.
79+
*/
80+
STREAM_CLOSED (0x05),
81+
82+
/**
83+
* Frame size incorrect.
84+
* <p>
85+
* The endpoint received a frame with an invalid size.
86+
*/
87+
FRAME_SIZE_ERROR (0x06),
88+
89+
/**
90+
* Stream not processed
91+
* <p>
92+
* The endpoint refuses the stream prior to performing any application processing.
93+
*/
94+
REFUSED_STREAM (0x07),
95+
96+
/**
97+
* Stream canceled.
98+
* <p>
99+
* Used by the endpoint to indicate that the stream is no longer needed
100+
*/
101+
CANCEL (0x08),
102+
103+
/**
104+
* Compression state not updated.
105+
* <p>
106+
* The endpoint is unable to maintain the header compression context for the connection.
107+
*/
108+
COMPRESSION_ERROR (0x09),
109+
110+
/**
111+
* TCP connection error.
112+
* <p>
113+
* The connection established in response to a CONNECT request was reset or abnormally closed.
114+
*/
115+
CONNECT_ERROR (0x0a),
116+
117+
/**
118+
* Processing capacity exceeded.
119+
* <p>
120+
* The endpoint detected that its peer is exhibiting a behavior that might be generating
121+
* excessive load.
122+
*/
123+
ENHANCE_YOUR_CALM (0x0b),
124+
125+
/**
126+
* Negotiated TLS parameters not acceptable.
127+
* <p>
128+
* The underlying transport has properties that do not meet minimum security requirements.
129+
*/
130+
INADEQUATE_SECURITY (0x0c),
131+
132+
/**
133+
* Use HTTP/1.1 for the request.
134+
* <p>
135+
* The endpoint requires that HTTP/1.1 be used instead of HTTP/2.
136+
*/
137+
HTTP_1_1_REQUIRED (0x0d);
138+
139+
int code;
140+
141+
H2Error(final int code) {
142+
this.code = code;
143+
}
144+
145+
public int getCode() {
146+
return code;
147+
}
148+
149+
private static final ConcurrentMap<Integer, H2Error> MAP_BY_CODE;
150+
static {
151+
MAP_BY_CODE = new ConcurrentHashMap<>();
152+
for (final H2Error error: values()) {
153+
MAP_BY_CODE.putIfAbsent(error.code, error);
154+
}
155+
}
156+
157+
public static H2Error getByCode(final int code) {
158+
return MAP_BY_CODE.get(code);
159+
}
160+
161+
}

src/jvmMain/kotlin/com/sunnychung/application/multiplatform/hellohttp/extension/UserRequestConversionExtension.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ import graphql.language.OperationDefinition
3737
//import org.apache.hc.core5.http.nio.AsyncRequestProducer
3838
//import org.apache.hc.core5.http.nio.entity.AsyncEntityProducers
3939
//import org.apache.hc.core5.http.nio.support.AsyncRequestBuilder
40-
import org.apache.hc.core5.net.URIBuilder
40+
//import org.apache.hc.core5.net.URIBuilder
41+
import org.springframework.web.util.UriComponentsBuilder
4142
import java.io.ByteArrayOutputStream
4243
import java.io.File
44+
import java.net.URI
4345
import java.net.URLEncoder
4446
import java.nio.charset.StandardCharsets
4547
import java.util.Locale
@@ -147,16 +149,18 @@ fun UserRequestTemplate.toHttpRequest(
147149
body = body,
148150
)
149151
} else {
152+
val uri = URI(req.url)
150153
req.copy(
151154
extra = graphqlRequest,
152-
url = URIBuilder(req.url)
155+
url = UriComponentsBuilder.fromUri(uri)
153156
.run {
154-
setScheme(when (scheme) {
157+
scheme(when (uri.scheme) {
155158
"http", "ws" -> "ws"
156159
"https", "wss" -> "wss"
157160
else -> throw IllegalArgumentException("Unknown scheme")
158161
})
159162
}
163+
.encode()
160164
.build()
161165
.toString()
162166
)

src/jvmMain/kotlin/com/sunnychung/application/multiplatform/hellohttp/model/HttpRequest.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.sunnychung.application.multiplatform.hellohttp.model
22

3-
import org.apache.hc.core5.net.URIBuilder
3+
//import org.apache.hc.core5.net.URIBuilder
4+
import org.springframework.web.util.UriComponentsBuilder
45
import java.net.URI
56

67
class HttpRequest(
@@ -32,16 +33,17 @@ class HttpRequest(
3233
val queryParameters get() = initialQueryParameters + newQueryParameters
3334

3435
fun getResolvedUri(): URI {
35-
return URIBuilder(url.replace(" ", "+"))
36+
return UriComponentsBuilder.fromUriString(url.replace(" ", "+"))
3637
.run {
3738
var b = this
3839
queryParameters.forEach {
39-
b = b.addParameter(it.first, it.second)
40+
b = b.queryParam(it.first, it.second)
4041
}
4142
b
4243
}
44+
.encode()
4345
.build()
44-
.let { URI.create(it.toASCIIString()) }
46+
.let { URI.create(it.toString()) }
4547
}
4648

4749
fun addHeader(key: String, value: String) {

0 commit comments

Comments
 (0)