I am recently working on some cookie related stuff, and made a small tool for myself. maybe it would help you in some way.

This tool captures html packets, and is capable to extra Set-Cookies.

To use it just make your browser point to this script as a proxy: localhost, 8080. This script requires one parameter to specify action, "r" for recording, and "d" for extract cookies. You can add more function, actually I just started with it yesterday, and will add more functions, if you are interested, I can send you a new version next week, or I can post it somewhere on perlmonks.

browser(user agent) <==> script <==> server

use IO::Socket::INET; use strict; my $action = $ARGV[0]; my $old_cookies = {}; my $new_cookies = {}; my $client = new IO::Socket::INET(Proto => "tcp", LocalPort => 8080, Listen => 10, Reuse => 1, Timeout => 2000) || die "failed"; if ($action eq "r") { while (1) { my $c = $client->accept(); my $request = get_request($c); logmsg($request."\n"); my $response = get_response($request); logmsg($response."\n"); print $c $response; close($c); } } if ($action eq "d") { my $request_file; open($request_file, "<", "result"); while (<$request_file>) { get_cookie($_, $old_cookies); } close($request_file); } sub get_response { my ($request, $new_cookies) = @_; my $s = new IO::Socket::INET(Proto => "tcp", PeerPort => 8080, PeerAddr => "yourrealproxy")#set this + to your real proxy || die "failed to connect to ofg\n"; print $s $request; my $response = ""; my $piece; while (1) { sysread($s, $piece, 1000); $response .= $piece; last if ($piece eq ""); }; close($s); my @lines = split(/\r\n\r\n/, $response); @lines = split(/\r\n/, $lines[0]); foreach my $line (@lines) { get_cookie($line, $new_cookies); } return $response; } sub get_request { my $c = shift; my $piece; my $request = ""; do { sysread($c, $piece, 1000); $request .= $piece; } until ($request =~ m/\r\n\r\n$/); return $request; } sub get_request_from_file { my ($request_file, $old_cookies) = @_; my $request = ""; my $found = 0; while (<$request_file>) { if (!$found) { if (m/^GET/) { $found = 1; $request .= $_; } else { get_cookie($_, $old_cookies); } } else { $request .= $_; last if (m/^\r\n$/); } } return $request; } sub logmsg { my $log = shift; my $result_file; open($result_file, ">>", "result"); print $result_file $log; close($result_file); } sub get_cookie { my ($response, $cookie_hash) = @_; $response =~ m/Set-Cookie:\s*(.*?)=(.*?)[;]/i; if ($1 && $2) { print "[$1, $2]\n"; $cookie_hash->{$1} = $2; } }

In reply to Re: CGI Cookie Problems by pg
in thread CGI Cookie Problems by michellem

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.