Issue and proposed fix. Non ascii characters in header causes a IllegalArgumentException
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- java
- Domain
- networking
Research direction
Start at the setHttpHeader entry point and the doRequestAsync path described in the issue, then reproduce the request with the Chinese carrier value. Compare header construction with the referenced Headers.Builder behavior and verify that the request completes without an IllegalArgumentException.
Written by the indexing model from the issue text.
Description
No pending exception expected: java.lang.IllegalArgumentException: Unexpected char
https://github.com/square/okhttp/issues/6347
https://github.com/square/okhttp/issues/4008
https://github.com/square/okhttp/issues/7275
https://github.com/square/okhttp/pull/4296
In the case of using setHttpHeader("carrier", ""中国电信"").
Note: 中国电信 is a Chinese telecommunications (cell phone provider carrier).
No pending exception expected: java.lang.IllegalArgumentException: Unexpected char 0x4e2d at 243 in User-Agent value
at void okhttp3.Headers$Companion.checkValue(java.lang.String, java.lang.String) (Headers.kt:450)
at void okhttp3.Headers$Companion.access$checkValue(okhttp3.Headers$Companion, java.lang.String, java.lang.String) (Headers.kt:362)
at okhttp3.Headers$Builder okhttp3.Headers$Builder.add(java.lang.String, java.lang.String) (Headers.kt:261)
at okhttp3.Request$Builder okhttp3.Request$Builder.addHeader(java.lang.String, java.lang.String) (Request.kt:210)
at <snipped>.setHttpHeader(java.lang.String, java.lang.String) (HttpClientRequest.java
The currently existing code snippet causes an issue.
public void setHttpHeader(String name, String value) {
this.requestBuilder = requestBuilder.addHeader(name, value);
}
I believe the possible fix is to add a
this.headersBuilder = new Headers.Builder();
and then switch setHttpHeader to
this.headersBuilder = headersBuilder.addUnsafeNonAscii(name, value);
Then in the doRequestAsync add this.requestBuilder.headers(this.headersBuilder.build()); before the OK_Client call
or to 'build and set' in every set. Just depends if you want to do a lot of duplicate work or not.
We are running a modified version of libhttpclient, so our fix is applied there. I'll see if/when I have time to PR this change into libHttpClient proper, but if not, above should help anyone who comes across similar issue.
- Dominant language
- C++
- Stars
- 295
- Forks
- 144
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 2
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/libHttpClient
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
microsoft/libHttpClient#964 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 65/100
microsoft/libHttpClient#958 ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
microsoft/libHttpClient#989 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
microsoft/libHttpClient#909 · 2 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
microsoft/libHttpClient#868 · 6 comments · 1 reaction ·
All issues in microsoft/libHttpClient
Similar issues
-
ai_reviewed
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
ydb-platform/ydb#53869 · 3 comments ·
-
bug cert blocker needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
project-chip/connectedhomeip#74373 ·
-
upstream update
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
conan-io/conan-center-index#31035 ·
-
Bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
documentation
Difficulty 1/5 Under an hour Newbie friendliness 85/100
vllm-project/vllm-ascend#17329 ·