I have a file that contains a HTTP request,
GET /xxx.php
Host: xxx
Content-Type: xxx
...
I would like to ask PHP cli to parse the HTTP request from a file, and
setup $_FILES, $_POST, $_SERVER etc.
What should I do? I'm familiar with PHP extensions, so I'm capable of
modifying SAPI myself.
So far I've found sapi_post_entry, but I couldn't get the whole
picture. Where's the entry point of request parsing?
--
Best Regards,
Aaron Lewis - PGP: 0x13714D33 - http://pgp.mit.edu/
Finger Print: 9F67 391B B770 8FF6 99DC D92D 87F6 2602 1371 4D33
Morning,
Ordinarily, we don't parse that stuff, because the server communicates via
CGI/FCGI or some other server specific interface (apache).
The CLI server does though, I'd look there for inspiration ... there's also
an HTTP parser included in there ...
Cheers
Joe
On Wed, Nov 16, 2016 at 10:50 AM, Aaron Lewis the.warl0ck.1989@gmail.com
wrote:
I have a file that contains a HTTP request,
GET /xxx.php Host: xxx Content-Type: xxx ...
I would like to ask PHP cli to parse the HTTP request from a file, and
setup $_FILES, $_POST, $_SERVER etc.
What should I do? I'm familiar with PHP extensions, so I'm capable of
modifying SAPI myself.So far I've found sapi_post_entry, but I couldn't get the whole
picture. Where's the entry point of request parsing?--
Best Regards,
Aaron Lewis - PGP: 0x13714D33 - http://pgp.mit.edu/
Finger Print: 9F67 391B B770 8FF6 99DC D92D 87F6 2602 1371 4D33
I'm referring to PHP-FPM, what about that?
Morning,
Ordinarily, we don't parse that stuff, because the server communicates via
CGI/FCGI or some other server specific interface (apache).The CLI server does though, I'd look there for inspiration ... there's also
an HTTP parser included in there ...Cheers
JoeOn Wed, Nov 16, 2016 at 10:50 AM, Aaron Lewis the.warl0ck.1989@gmail.com
wrote:I have a file that contains a HTTP request,
GET /xxx.php Host: xxx Content-Type: xxx ...
I would like to ask PHP cli to parse the HTTP request from a file, and
setup $_FILES, $_POST, $_SERVER etc.
What should I do? I'm familiar with PHP extensions, so I'm capable of
modifying SAPI myself.So far I've found sapi_post_entry, but I couldn't get the whole
picture. Where's the entry point of request parsing?--
Best Regards,
Aaron Lewis - PGP: 0x13714D33 - http://pgp.mit.edu/
Finger Print: 9F67 391B B770 8FF6 99DC D92D 87F6 2602 1371 4D33--
--
Best Regards,
Aaron Lewis - PGP: 0x13714D33 - http://pgp.mit.edu/
Finger Print: 9F67 391B B770 8FF6 99DC D92D 87F6 2602 1371 4D33
Maybe something like https://github.com/guzzle/psr7/blob/master/README.md?
There are additional middlewares that can extract from a request and
populate super-globals for legacy app support purposes.
I have a file that contains a HTTP request,
GET /xxx.php Host: xxx Content-Type: xxx ...
I would like to ask PHP cli to parse the HTTP request from a file, and
setup $_FILES, $_POST, $_SERVER etc.
What should I do? I'm familiar with PHP extensions, so I'm capable of
modifying SAPI myself.So far I've found sapi_post_entry, but I couldn't get the whole
picture. Where's the entry point of request parsing?--
Best Regards,
Aaron Lewis - PGP: 0x13714D33 - http://pgp.mit.edu/
Finger Print: 9F67 391B B770 8FF6 99DC D92D 87F6 2602 1371 4D33
Thanks Marco.
But I'm looking for the C implementation ..
Maybe something like https://github.com/guzzle/psr7/blob/master/README.md?
There are additional middlewares that can extract from a request and
populate super-globals for legacy app support purposes.I have a file that contains a HTTP request,
GET /xxx.php Host: xxx Content-Type: xxx ...
I would like to ask PHP cli to parse the HTTP request from a file, and
setup $_FILES, $_POST, $_SERVER etc.
What should I do? I'm familiar with PHP extensions, so I'm capable of
modifying SAPI myself.So far I've found sapi_post_entry, but I couldn't get the whole
picture. Where's the entry point of request parsing?--
Best Regards,
Aaron Lewis - PGP: 0x13714D33 - http://pgp.mit.edu/
Finger Print: 9F67 391B B770 8FF6 99DC D92D 87F6 2602 1371 4D33--
--
Best Regards,
Aaron Lewis - PGP: 0x13714D33 - http://pgp.mit.edu/
Finger Print: 9F67 391B B770 8FF6 99DC D92D 87F6 2602 1371 4D33
One question then: why?
Working userland impl, just use it.
Thanks Marco.
But I'm looking for the C implementation ..
Maybe something like https://github.com/guzzle/
psr7/blob/master/README.md?
There are additional middlewares that can extract from a request and
populate super-globals for legacy app support purposes.I have a file that contains a HTTP request,
GET /xxx.php Host: xxx Content-Type: xxx ...
I would like to ask PHP cli to parse the HTTP request from a file, and
setup $_FILES, $_POST, $_SERVER etc.
What should I do? I'm familiar with PHP extensions, so I'm capable of
modifying SAPI myself.So far I've found sapi_post_entry, but I couldn't get the whole
picture. Where's the entry point of request parsing?--
Best Regards,
Aaron Lewis - PGP: 0x13714D33 - http://pgp.mit.edu/
Finger Print: 9F67 391B B770 8FF6 99DC D92D 87F6 2602 1371 4D33--
--
Best Regards,
Aaron Lewis - PGP: 0x13714D33 - http://pgp.mit.edu/
Finger Print: 9F67 391B B770 8FF6 99DC D92D 87F6 2602 1371 4D33
I have a file that contains a HTTP request,
GET /xxx.php Host: xxx Content-Type: xxx ...
I would like to ask PHP cli to parse the HTTP request from a file, and
setup $_FILES, $_POST, $_SERVER etc.
What should I do? I'm familiar with PHP extensions, so I'm capable of
modifying SAPI myself.
The Ultimate Web Scraper Toolkit over on GitHub can get you about 75% of
the way there in pure userland in a few lines of application code with
the WebServer class:
https://github.com/cubiclesoft/ultimate-web-scraper/
Possible approach:
$fp = fopen("/path/to/file.txt", "rb");
stream_set_blocking($fp, 0);
$server = new WebServer();
// If you want to allow gzipped/deflated input.
//$server->EnableCompression(true);
// If you are actually processing file input...
//$server->SetCacheDir("/path/to/cache/");
$client = $server->InitNewClient();
$client->fp = $fp;
do
{
$result = $server->Wait();
if (count($result["removed"]))
{
// File contains an invalid request.
// Maybe bail out more gently?
echo "Invalid request.\n";
exit();
}
} while (!$client->requestcomplete);
// Now use $client's public variables 'cookievars' and 'requestvars' to
load various superglobals. There isn't a pure structure though for
$_GET and $_POST.
...
is_uploaded_file()
, move_uploaded_file()
, sesssions, and other useful
built-ins might also not work as expected. Hence the 75% metric from
earlier.
--
Thomas Hruska
CubicleSoft President
I've got great, time saving software that you will find useful.