Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not add Http Header #714

Open
zll123dxd opened this issue Dec 8, 2022 · 2 comments
Open

Can not add Http Header #714

zll123dxd opened this issue Dec 8, 2022 · 2 comments

Comments

@zll123dxd
Copy link

I'm not sure if this project is still maintained, try asking.

I have configured a proxy with authentication in my android project.
There are two options to achieve

  1. extends SimpleMiddleware, and add Proxy-Authorization in the onRequest function.
  2. Call addHeader [Proxy-Authorization] in AsyncHttpRequest.
    Check the http message through tcpdump, it tries to connect to the target proxy, but it does not carry the [Proxy-Authorization] I added.

I don't know if I used it wrong, attach a piece of code:

    Headers header = new Headers();
    String baseAuth = Base64.encodeToString(("test:12345678").getBytes(), Base64.NO_WRAP);
    AsyncHttpRequest.setDefaultHeaders(header, Uri.parse(url));
    header.set("Proxy-Authorization", "Basic " + baseAuth);
    AsyncHttpGet request = new AsyncHttpGet(url);
    request.setHeader("Proxy-Authorization", "Basic " + baseAuth);
    view.setText(request.toString());
    mClient.executeString(request, mCallback);

If I configure this parameter in the okhttp framework, I can successfully connect. So I think there is nothing wrong with the parameters of the header.

I checked the code of the AsyncHttp framework, I think the default does not support Proxy-Auth, so I want to manually add the http header, but it is invalid, if anyone has a suitable solution, please help me.

@zll123dxd
Copy link
Author

http
I tried to do some debugging, the header is correctly saved in the request, but when it is actually sent, there is only the host field, is this a bug?

@zll123dxd
Copy link
Author

To add, I found this code to force the use of the Host field, and did not use other fields in the Request

AsyncSSLSocketMiddleware.java
...
String connect = String.format(Locale.ENGLISH, "CONNECT %s:%s HTTP/1.1\r\nHost: %s\r\n\r\n", uri.getHost(), port, uri.getHost());
data.request.logv("Proxying: " + connect);
Util.writeAll(socket, connect.getBytes(), new CompletedCallback() {
...

In other words, the header I added will be used after the proxy is forwarded, not when the proxy is connected. I think it does not support the proxy with authentication, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant