Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Help with converting HTTP::Request to Plack::Request

by Your Mother (Archbishop)
on Feb 10, 2020 at 07:56 UTC ( [id://11112721]=note: print w/replies, xml ) Need Help??


in reply to Help with converting HTTP::Request to Plack::Request

I echo anonymonk’s request for clarification. Plack/PSGI is server side. It doesn’t, so far, make sense to answer your question with Plack code. Here is some more complete stuff for anyone to play with. I would suggest that the URI object’s methods are superior to URI::Split, so I include them after the split. One thing you might consider, and who knows, might be leading to your problem, the server doesn’t get the fragment (I mention it partly because it was an issue for me once and you present it in code dealing with server responses). Only the client knows about fragments; you can scan the YAML dump and see everything the server code gets.

# Server plackup -MYAML -e 'sub { warn Dump(+shift), $/; [ 200, [], [ "OHAI" ]] + }' HTTP::Server::PSGI: Accepting connections at http://0:5000/
# Client use 5.16.2; use strict; use HTTP::Request; use LWP::UserAgent; use URI::Split "uri_split"; my $uri = 'http://user:pass@localhost:5000/some/path?o=hai#frag'; my $request = HTTP::Request->new( GET => $uri ); my $user_agent = LWP::UserAgent->new; my $response = $user_agent->request($request); if ( $response->is_success ) { my $uri = $response->request->uri; my ( $scheme, $auth, $path, $query, $frag ) = uri_split($uri); say join " + ", $scheme, $auth, $path, $query, $frag; for my $method (qw/ authority host port path fragment query /) { printf "%12s -> %s\n", $method, $uri->$method; } }

Replies are listed 'Best First'.
Re^2: Help with converting HTTP::Request to Plack::Request
by knox (Sexton) on Feb 10, 2020 at 20:15 UTC

    The context: I had a working local FCGI script that i was converting to Plack step by step. It was going smoothly until it got to the posted code. For some reason I couldn't get an error code or line number, just: "failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: polyneura.local, request: "POST /index.cgi HTTP/1.1", upstream: "http://127.0.0.1:5000". I should have posted it here.

    Plack/PSGI is server side. It doesn’t, so far, make sense to answer your question with Plack code.

    This was really helpful, it wasn't obvious to me until you mentioned it. While it didn't directly solve my problem, it was a light bulb moment for me as I thought that every type of request had to wrapped up in some sort of Plack handler.

    Only the client knows about fragments; you can scan the YAML dump and see everything the server code gets.

    This is cool, thanks! After further testing, I found that LWP::Protocol::https was not installed. This confused me, because it was working on my local fcgi script (I'll check this later). So I went through the process of installing LWP::Protocol::https which yielded more errors:

    ! Installing the dependencies failed: Module 'Net::SSLeay' is not inst +alled ! Bailing out the installation for IO-Socket-SSL-2.066.

    ! tail /home/<userhome>/.cpanm/work/1581360095.6546/build.log ^ rm -f blib/arch/auto/Net/SSLeay/SSLeay.so LD_RUN_PATH="/usr/lib/x86_64-linux-gnu:/lib/x86_64-linux-gnu" cc -sha +red -O2 -L/usr -L/usr/lib -L/usr/local/lib -fstack-protector-strong +SSLeay.o -o blib/arch/auto/Net/SSLeay/SSLeay.so \ -L/usr -L/usr/lib -lssl -lcrypto -lz \ /usr/bin/ld: cannot find -lz collect2: error: ld returned 1 exit status Makefile:493: recipe for target 'blib/arch/auto/Net/SSLeay/SSLeay.so' +failed make: *** [blib/arch/auto/Net/SSLeay/SSLeay.so] Error 1 -> FAIL Installing Net::SSLeay failed. See /home/<userhome>/.cpanm/wor +k/1581360095.6546/build.log for details. Retry with --force to force +install it.

    I found this: https://stackoverflow.com/questions/3373995/usr-bin-ld-cannot-find-lz and installed sudo apt-get install zlib1g-dev. I haven't got around to changing to URI yet, but I will make some changes soon. Thanks for that. Apologies if this was long winded, but I figure someone out there could learn from my mistakes.

    A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11112721]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-04-20 01:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found