wagnerc has asked for the wisdom of the Perl Monks concerning the following question:

Greets fellow monks. Either there has been an oversight in LWP and HTTP::* or I am committing an oversight.

I can't seem to find any way of setting the HTTP protocol version when creating an LWP, WWW Mechanize, or HTTP Request request. I looked through the source code and even didn't see anything. The only place I found anything about it was in Net::HTTP. It let's u set the version and URI. Of course, this creates a big problem if I have to do this to set them.

So:
Need to set HTTP Version to 1.0, 999, anything I want.
Need to control the request URI to anything I want. e.g. GET bob, rather than GET /bob as URL parsing would produce.

Thanks.

Replies are listed 'Best First'.
Re: Setting HTTP Protocol Version
by moritz (Cardinal) on Aug 26, 2009 at 14:41 UTC
    I don't know if this reply is going to be helpful to you, because I'm not going to explain how it's done, but rather why it's (normally) not done.

    HTTP is a protocol defined by various RFCs. The LWP modules and and HTTP::* modules aim to implement that protocol. There is a version 1.0 and a version 1.1 of that protocol, both are in common use. Depending on the version, the headers must be constructed differently, and the user agent has to act in different ways.

    Now you can't just say "set version to 999" and expect it to behave reasonably, because LWP::* doesn't implement any logic for HTTP 999 - heck, it's not even specified.

    Likewise there's no point trying to pass a relative URL to a HTTP server, because it violates the spec

    There is an exception though: If your objective is to test that a HTTP server behaves reasonably with malformed requests, you might want such a behavior. If that's what you are after, I recommend talking to the Mojo developers - they did such things recently.

    Perl 6 projects - links to (nearly) everything that is Perl 6.
      Thanks for replying but ur first sentence is the operative one from ur post. ;)

      Of course it is off spec. I need to communicate with a degenerate web interface. A leading slash on the URI causes the server to throw a 500 error. There is no option to change the server.

Re: Setting HTTP Protocol Version
by ambrus (Abbot) on Aug 26, 2009 at 16:08 UTC

    Maybe LWP doesn't implement HTTP/1.0?

    You may try looking at one of the modules using libcurl, as libcurl for one knows both HTTP versions, eg. WWW::Curl or LWP::Curl. Possibly add the interface to set the HTTP version if they don't provide it already.

Re: Setting HTTP Protocol Version
by Anonymous Monk on Aug 26, 2009 at 17:00 UTC
      Can u elaborate? I don't see anything in that module's documentation on how to make ur $ua object speak HTTP 1.0 or set the request URI.

      update: After staring at it for a while, could u be referring to the implementor function?

      use LWP; LWP::Protocol::implementor("http", "LWP::Protocol::http10"); print LWP::Protocol::implementor("http"); ^D LWP::Protocol::http10
        I said copy LWP::Protocol::http10. You then modify it as you see fit (see ->protocol), register as the implementor, and you're finished.
        The words are spelt "you" and "your". The rest of your message is obviously intelligent, so please don't try to make yourself look like an idiot - you're not very good at it :-)