Last active
August 29, 2015 14:03
-
-
Save ngo/9267919dc12e6165e952 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from http_parser.parser import HttpParser as HttpParserC | |
from http_parser.pyparser import HttpParser as HttpParserPy | |
REQUEST = 'GET /hjs?m_mode=multipart&site=news®ion=US&lang=en-US&pagetype=contentb&&__r=1391585859471&post=%7B%22reqs%22%3A%5B%7B%22handler%22%3A%22cfg.maple_dali.handler.refresh%22%2C%22data%22%3A%7B%22maple%22%3A%7B%22module%22%3A%22p_30345826%22%2C%22ba%22%3A%7B%22_txnid%22%3A0%2C%22_mode%22%3A%22json%22%2C%22_id%22%3A%22p_30345826%22%2C%22_container%22%3A0%2C%22_action%22%3A%22show%22%2C%22_subAction%22%3A%22getButtons%22%2C%22noups%22%3A1%2C%22sec%22%3A%22td-strm-dr%22%2C%22layout%22%3A%22horizontal%22%2C%22title%22%3A%22Sign-in%20and%20we%27ll%20show%20you%20more%20like%20this%20in%20the%20future.%22%2C%22narrow%22%3A1%7D%7D%7D%2C%22txId%22%3A1%7D%5D%2C%22props%22%3A%7B%22dali%22%3A%7B%22crumb%22%3A%22q%2FSc0Cy2vZm%22%2C%22yuid%22%3A%22%22%2C%22loggedIn%22%3A%220%22%2C%22mLogin%22%3A0%7D%7D%7D HTTP/1.1\r\nHost: news.yahoo.com\r\nUser-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:26.0) Gecko/20100101 Firefox/26.0\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nAccept-Language: en-us,en;q=0.5\r\nAccept-Encoding: gzip, deflate\r\nDNT: 1\r\nX-Requested-With: XMLHttpRequest\r\nReferer: http://news.yahoo.com/blogs/oddnews/man-uses-his-first-class-ticket-to-eat-free-meals-everyday-for-nearly-a-year-230404032.html\r\nCookie: B=6193ab598nnb8&b=3&s=1l; AO=o=1&s=1&dnt=1; ywadp10001393120079=3250737235; fpc10001393120079=ZSGpDl01|t15KG1FNaa|fses10001393120079=|t15KG1FNaa|ZSGpDl01|fvis10001393120079=|8M781so8M0|8M781so8M0|8M781so8M0|8|8M781so8M0|8M781so8M0; ugccmt_comment_usortoptv1=highestRated; AO=o=1&s=1&dnt=1; RMBX=6193ab598nnb8&b=3&s=1l&t=34\r\nConnection: keep-alive\r\n\r\n' | |
print "REQUEST" | |
print REQUEST | |
print "==========================" | |
print "HttpParserPy" | |
p = HttpParserPy() | |
for i in xrange(0, len(REQUEST), 100): | |
chunk = REQUEST[i:i+100] | |
assert( p.execute(chunk, len(chunk)) == len(chunk)) | |
print "Headers complete: ", p.is_headers_complete() | |
print "Message complete: ", p.is_message_complete() | |
print "url: ", p.get_url() | |
print "==========================" | |
print "HttpParserC" | |
p = HttpParserC() | |
for i in xrange(0, len(REQUEST), 100): | |
chunk = REQUEST[i:i+100] | |
assert( p.execute(chunk, len(chunk)) == len(chunk)) | |
print "Headers complete: ", p.is_headers_complete() | |
print "Message complete: ", p.is_message_complete() | |
print "url: ", p.get_url() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REQUEST | |
GET /hjs?m_mode=multipart&site=news®ion=US&lang=en-US&pagetype=contentb&&__r=1391585859471&post=%7B%22reqs%22%3A%5B%7B%22handler%22%3A%22cfg.maple_dali.handler.refresh%22%2C%22data%22%3A%7B%22maple%22%3A%7B%22module%22%3A%22p_30345826%22%2C%22ba%22%3A%7B%22_txnid%22%3A0%2C%22_mode%22%3A%22json%22%2C%22_id%22%3A%22p_30345826%22%2C%22_container%22%3A0%2C%22_action%22%3A%22show%22%2C%22_subAction%22%3A%22getButtons%22%2C%22noups%22%3A1%2C%22sec%22%3A%22td-strm-dr%22%2C%22layout%22%3A%22horizontal%22%2C%22title%22%3A%22Sign-in%20and%20we%27ll%20show%20you%20more%20like%20this%20in%20the%20future.%22%2C%22narrow%22%3A1%7D%7D%7D%2C%22txId%22%3A1%7D%5D%2C%22props%22%3A%7B%22dali%22%3A%7B%22crumb%22%3A%22q%2FSc0Cy2vZm%22%2C%22yuid%22%3A%22%22%2C%22loggedIn%22%3A%220%22%2C%22mLogin%22%3A0%7D%7D%7D HTTP/1.1 | |
Host: news.yahoo.com | |
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:26.0) Gecko/20100101 Firefox/26.0 | |
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 | |
Accept-Language: en-us,en;q=0.5 | |
Accept-Encoding: gzip, deflate | |
DNT: 1 | |
X-Requested-With: XMLHttpRequest | |
Referer: http://news.yahoo.com/blogs/oddnews/man-uses-his-first-class-ticket-to-eat-free-meals-everyday-for-nearly-a-year-230404032.html | |
Cookie: B=6193ab598nnb8&b=3&s=1l; AO=o=1&s=1&dnt=1; ywadp10001393120079=3250737235; fpc10001393120079=ZSGpDl01|t15KG1FNaa|fses10001393120079=|t15KG1FNaa|ZSGpDl01|fvis10001393120079=|8M781so8M0|8M781so8M0|8M781so8M0|8|8M781so8M0|8M781so8M0; ugccmt_comment_usortoptv1=highestRated; AO=o=1&s=1&dnt=1; RMBX=6193ab598nnb8&b=3&s=1l&t=34 | |
Connection: keep-alive | |
========================== | |
HttpParserPy | |
Headers complete: True | |
Message complete: False | |
url: /hjs?m_mode=multipart&site=news®ion=US&lang=en-US&pagetype=contentb&&__r=1391585859471&post=%7B%22reqs%22%3A%5B%7B%22handler%22%3A%22cfg.maple_dali.handler.refresh%22%2C%22data%22%3A%7B%22maple%22%3A%7B%22module%22%3A%22p_30345826%22%2C%22ba%22%3A%7B%22_txnid%22%3A0%2C%22_mode%22%3A%22json%22%2C%22_id%22%3A%22p_30345826%22%2C%22_container%22%3A0%2C%22_action%22%3A%22show%22%2C%22_subAction%22%3A%22getButtons%22%2C%22noups%22%3A1%2C%22sec%22%3A%22td-strm-dr%22%2C%22layout%22%3A%22horizontal%22%2C%22title%22%3A%22Sign-in%20and%20we%27ll%20show%20you%20more%20like%20this%20in%20the%20future.%22%2C%22narrow%22%3A1%7D%7D%7D%2C%22txId%22%3A1%7D%5D%2C%22props%22%3A%7B%22dali%22%3A%7B%22crumb%22%3A%22q%2FSc0Cy2vZm%22%2C%22yuid%22%3A%22%22%2C%22loggedIn%22%3A%220%22%2C%22mLogin%22%3A0%7D%7D%7D | |
========================== | |
HttpParserC | |
Headers complete: True | |
Message complete: True | |
url: 7D |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment