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

Windows proxies/certificates using WinHTTP #97

Open
WebFreak001 opened this issue Mar 28, 2019 · 14 comments
Open

Windows proxies/certificates using WinHTTP #97

WebFreak001 opened this issue Mar 28, 2019 · 14 comments

Comments

@WebFreak001
Copy link
Contributor

Maybe dlang-requests should additionally wrap WinHTTP on Windows for not needing any dependencies like SSL.

It can take the system proxy (if http_proxy is not set) and has a lot of additional internal capabilities like kerberos authentication which I think would be pretty cool to have. Also it's recognized for example by anti-virus tools and other utilities to have all HTTP requests tracked using a central API. I think there could be a good wrapper around it in the library.

It would be cool if it would be compatible with vibe.d tasks using the async methods which integrate in the rest of Win32 events.

https://docs.microsoft.com/en-us/windows/desktop/WinHttp/about-winhttp

@WebFreak001 WebFreak001 changed the title Windows proxies/certificates Windows proxies/certificates using WinHTTP Mar 28, 2019
@TransientResponse
Copy link

I've not been able to get the OpenSSL stuff working with this library, so I'm going to fork it and give a WinHTTP wrapper a shot. Shouldn't be too hard (famous last words).

@WebFreak001
Copy link
Contributor Author

I wrote some WinHTTP code to download a file if you want to look at it for reference: (though there might be better ways, it's a way that worked and is stitched together from the examples and documentation) https://github.com/Pure-D/serve-d/blob/master/http/source/served/http.d#L38

@TransientResponse
Copy link

I've already got working code using WinHTTP in D by copy-pasting MS example code, D-ifying it, and then lots of trial and error :).

Your example looks like Wininet though. Well, wininet will let me handle FTP as well. I'll stick to WinHTTP for the HTTP side as I've already figured out how to do headers and such on that.

@ikod
Copy link
Owner

ikod commented Jul 26, 2019

Hello,
Is is possible to adapt windows ssl library (SecureChannel?) to solve this problem? It would be nice to add this functionality. I'm very weak with windows programming, so I afraid to start this job.

@TransientResponse
Copy link

TransientResponse commented Jul 27, 2019

So for WinHTTP SSL is handled very easily. The function WinHttpOpenRequest is called with an SSL flag, like so: WinHttpOpenRequest(hConnect, "METHOD"w.toUTF16z, "/route"w.toUTF16z, null, WINHTTP_NO_REFERER, WINHTTP_DEFAULT_ACCEPT_TYPES, WINHTTP_FLAG_SECURE);

That WINHTTP_FLAG_SECURE is literally it, assuming you gave the correct port in the earlier call to WinHttpConnect. Windows does the whole SSL connection thing itself. Totally transparent from the point of view of the API. For non-HTTPS calls, passing a flag value of 0 works.

@ikod
Copy link
Owner

ikod commented Jul 27, 2019

So for WinHTTP SSL is handled very easily. The function WinHttpOpenRequest is called with an SSL flag, like so: WinHttpOpenRequest(hConnect, "METHOD"w.toUTF16z, "/route"w.toUTF16z, null, WINHTTP_NO_REFERER, WINHTTP_DEFAULT_ACCEPT_TYPES, WINHTTP_FLAG_SECURE);

That WINHTTP_FLAG_SECURE is literally it, assuming you gave the correct port in the earlier call to WinHttpConnect. Windows does the whole SSL connection thing itself. Totally transparent from the point of view of the API. For non-HTTPS calls, passing a flag value of 0 works.

But with WinHTTP we will lose some dlang-requests functionality like receiveAsRange or not? If not - I'm ok with WinHTTP for windows builds.

@TransientResponse
Copy link

TransientResponse commented Jul 27, 2019 via email

@ikod
Copy link
Owner

ikod commented Jul 27, 2019

Thanks @TransientResponse !

Then I think it is worth to try. Did you forked this repo in order to implement this feature?

@TransientResponse
Copy link

TransientResponse commented Jul 27, 2019 via email

@TransientResponse
Copy link

Well, my first implementation works and 11/12 unittests pass (unless dub is tricking me). The test that's failing is package.d:80:__unittest_L29_C9 Check handling incomplete status line, and the reason seems to be that a GET to /incomplete on httpbin.org (local or remote) is returning 404 and not 600 or 502 as the assert wants. Not sure why this is.

@ikod
Copy link
Owner

ikod commented Aug 6, 2019

Well, my first implementation works and 11/12 unittests pass (unless dub is tricking me). The test that's failing is package.d:80:__unittest_L29_C9 Check handling incomplete status line, and the reason seems to be that a GET to /incomplete on httpbin.org (local or remote) is returning 404 and not 600 or 502 as the assert wants. Not sure why this is.

Very good!

You can enable full debug on particularly this test with globalLogLevel = LogLevel.trace and Request.verbosity = 2 or 3; You can place debug output here, I'll check

@ikod
Copy link
Owner

ikod commented Nov 12, 2021

hello @TransientResponse

any news on this?

@TransientResponse
Copy link

TransientResponse commented Nov 12, 2021 via email

@TransientResponse
Copy link

I set loglevel to trace and verbosity on the failing request to 2, and I only get a little more info:

2021-11-13T08:57:35.574 [info] source\requests\package.d:82:__unittest_L29_C9 Check handling incomplete status line
2021-11-13T08:57:35.575 [trace] source\requests\http.d:2616:execute serving Request(GET, http://127.0.0.1:8081/incomplete)
Doing connection to 127.0.0.1 with scheme http
Doing GET for /incomplete
2021-11-13T08:57:35.580 [trace] source\requests\streams.d:1000:connect Create connection to 127.0.0.1:8081
2021-11-13T08:57:35.580 [trace] source\requests\streams.d:1009:connect Trying 127.0.0.1:8081
2021-11-13T08:57:35.581 [trace] source\requests\streams.d:1019:connect Connected to 127.0.0.1:8081
2021-11-13T08:57:35.581 [trace] source\requests\streams.d:981:close Close socket

core.exception.AssertError@source\requests\package.d(86): unittest failure

The trace lines from streams.d look as though it's not calling the WinHttp API at all in that test, but I know it is compiling and testing. I can get errors out of WinAPI if I don't have an httpbin server running locally (like in docker). Unless the unittest build overrides version(Windows) checks?

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

3 participants