Question

I'm going nuts, I have a very simple WEBrickProxy (WEBrick 1.3.1, with Ruby 1.9.3), and I want to try it out with curl. Here is the proxy:

require 'webrick'
require 'webrick/httpproxy'

server = WEBrick::HTTPProxyServer.new(:BindAddress => "localhost", :Port => 8888)
trap('INT') { server.shutdown }
server.start

And here is the cURL command

curl --proxy localhost:8888 http://www.google.de -v

But the curl command always returns a bad request:

* About to connect() to proxy localhost port 8888 (#0)
*   Trying ::1...
* connected
* Connected to localhost (::1) port 8888 (#0)
> GET http://www.google.de HTTP/1.1
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5
> Host: www.google.de
> Accept: */*
> Proxy-Connection: Keep-Alive
> 
< HTTP/1.1 400 Bad Request 
< Content-Type: text/html; charset=ISO-8859-1
< Server: WEBrick/1.3.1 (Ruby/1.9.3/2012-10-12)
< Date: Mon, 18 Mar 2013 13:44:27 GMT
< Content-Length: 295
< Connection: close
< 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<HTML>
  <HEAD><TITLE>Bad Request</TITLE></HEAD>
  <BODY>
    <H1>Bad Request</H1>
    bad URI `http://www.google.de'.
    <HR>
    <ADDRESS>
     WEBrick/1.3.1 (Ruby/1.9.3/2012-10-12) at
     23tuxmb.local:8888
    </ADDRESS>
  </BODY>
</HTML>
* Closing connection #0

curl --version returns on my Mac OS X 10.8

curl 7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smtp smtps telnet tftp 
Features: AsynchDNS GSS-Negotiate IPv6 Largefile NTLM NTLM_WB SSL libz

I can't find out where the error is, and I tried that piece of code a couple of weeks ago, and I can remember that it worked.

The weird thing is, that when I configure my Mac to globally use that proxy (inside the System Settings -> Network -> Advanced -> Proxies -> Web Proxy), everything works. A request with Chrome or any other application is routed through the proxy (and I see this inside the Terminal log of the proxy).

So, can anyone reproduce this issue? Is it a curl bug? Or a Webrick related issue?

EDIT

More information: The output of the ruby script itself when curl tries to connect is

[2013-03-18 17:16:32] ERROR bad URI `http://www.amazon.de'.
localhost - - [18/Mar/2013:17:16:32 CET] "GET http://www.amazon.de HTTP/1.1" 400 286
- -> http://www.amazon.de

thx!

Was it helpful?

Solution

If you add a trailing slash to the URL you request, does it work then? Ie a command line like this:

curl --proxy localhost:8888 http://www.google.de/ -v

(this is a curl bug reported in bug #1206, and fixed in git and next release...)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top