 HTTPϢΥХ
Content-Encoding: gzip
Transfer-Encoding: chunked
responseμ갷˥Х褦ʵ뢪äѤꤤ
괺н򤷤ŪˤϥХäƤ롣
gzipإåĹ(û10Х)ûchunkȤgzipإåʬ
䤵Ƥˡ롣




 Cookieܤ˿٤ˤĤ

ɬפʵǽ
1.Set-CookieإåƤᤷϿ(HTTPCookiesHTTPCookieǲ
ʬϤܼۤ)
2.Ϳ줿Cookieξsave/load
եޥåȡXMLSQLite(mozilla firefoxο)
3.Ϳ줿Cookieξ󷲤椫顢HTTPΥꥯȤ˴Ϣ
Ф
괺HTTPꥯȤhostCookiedomain˴˥ޥå
Ĥ򸫤ȤͤǼƤߤ褦2chʤ餳ưϤ

äԤơ
HTTPCookies˾Τ֤Τ϶ڤͽޤHTTP*饹
libochushaˤäƤ̰ơlibochusha¸򸺤餷Ƥ
cookie_manager.cc, cookie_manager.hɲäʬϤ
˼٤ʡ
̯ġġhttp_cookies.cchttp_cookies.hƤϡ
ʳhttp_*ե뷲ƤȤϳؤۤʤȸ
ɤ⡣षhttp_cookies.cchttp_cookies.hۤȤ̤
Τޤްव٤
Set-CookieparseΤݤʤΤǡѤ饹
HTTPCookie饹http_cookies.cchttp_cookies.h
˻Ĥ¾cookie_manager.cccookie_manager.h˰ܹԤ롣
̤櫤ȯޤHTTPHeadersλͤlibghttpλͤ
Ʊ̾Υإå٤˰Ĥʤ褦ˤʤäƤ뤻ǡ
̯ʤȤˤʤäƤ롣äSet-Cookieʣ뤳ȤϳǧѤʤΤ
","ѤŪ˾˷礷ƸⲽƤ뤬ϻߤ٤
HTTPHeadersλͤθ¾ͤɬפ
ʤ


firefoxcookies.sqlite
CREATE TABLE moz_cookies (id INTEGER PRIMARY KEY, name TEXT, value
TEXT, host TEXT, path TEXT, expiry INTEGER, lastAccessed INTEGER,
isSecure INTEGER, isHttpOnly INTEGER)


*Ѥtable
CREATE TABLE IF NOT EXISTS ochusha_cookies (
id INTEGER PRIMARY KEY,
name TEXT,
value TEXT,
domain TEXT,
path TEXT,
expiry INTEGER,
comment TEXT,
commentURL TEXT,
version INTEGER,
port TEXT,
lastAccessed INTEGER,
isSecure INTEGER
);



CookieˤĤ

CookieϢλͤʣƤġġ
Netscape
http://wp.netscape.com/newsref/std/cookie_spec.html

RFC2109(Set-Cookie/Cookie)
http://www.faqs.org/rfcs/rfc2109.html

RFC2965(Set-Cookie2/Cookie2)
http://www.faqs.org/rfcs/rfc2965.html

ͤΤNetscapeͤä褦ʵ롣

¤ƤSet-Cookie򸫤ȡͤäƲäƴġġ
ѡϡ˻ͤꤷƤ餽˱äƲϤʤʳѤ
н褹ˡϤʤ


Set-Cookie: NAME=VALUE; expires=DATE; path=PATH; domain=DOMAIN_NAME; secure

NAME=VALUE
  ɬܹ
  This string is a sequence of characters excluding semi-colon, comma
  and white space.

domain=DOMAIN_NAME
  The default value of `domain' is the host name of the server which
  generated the cookie response.

path=PATH
  The `path' attribute is used to specify the subset of URLs in a
  domain for which the cookie is valid.  If a cookie has already
  passed domain matching, then the pathname component of the URL is
  compared with the path attribute, and if there is a match, the
  cookie is considered valid and is sent along with the URL request.
  The path "/foo" would match "/foobar" and "/foo/bar.html".  The path
  "/" is the most general path.

  If the `path' is not specified, it as assumed to be the same path as
  the document being described by the header which contains the
  cookie.

secure
  If a cookie is marked `secure', it will only be transmitted if the
  communications channel with the host is a secure one.  Currently
  this means that secure cookies will only be sent to HTTPS(HTTP over
  SSL) servers.

  If `secure' is not specified, a cookie is considered safe to be sent
  in the clear over unsecured channels.


(Netscape)
expires=DATE
  DATEʸ񼰤ʼԡ
  Wdy, DD-Mon-YYYY HH:MM:SS GMT
    ΥޤԤ

(RFC2109/2965)
Comment=comment
  Because cookies can contain private information about a user, the
  Cookie attribute allows an origin server to document its intended
  use of a cookie.  The user can inspect the information to decide
  whether to initiate or continue a session with this cookie.


Max-Age=delta-seconds
  The Max-Age attribute defines the lifetime of the cookie, in
  seconds.  The delta-seconds value is a decimal non-negative
  integer.  After delta-seconds seconds elapse, the client should
  discard the cookie.  A value of zero means the cookie should be
  discarded immediately.

Version=version
  Required.  The Version attribute, a decimal integer, identifies to
  which version of the state management specification the cookie
  conforms.  For this specification, Version=1 applies.


(RFC2965: Set-Cookie2)
CommentURL="http_URL"
  Because cookies can be used to derive or store private information
  about a user, the CommentURL attribute allows an origin server to
  document how it intends to use the cookie.  The user can inspect the
  information identified by the URL to decide whether to initiate or
  continue a session with this cookie.

Discard
  The Discard attribute instructs the user agent to discard the cookie
  unconditionally when the user agent terminates.

Port[="portlist"]
  The Port attribute restricts the port to which a cookie may be
  returned in a Cookie request header.  Note that the syntax REQUIREs
  quotes around the OPTIONAL portlist even if there is only one
  portnum in portlist.


 ͤ뤫ƤSet-Cookieإå
Set-Cookie: PON=CLIENT-HOST; expires=Friday, 01-Jan-2010 00:00:00 GMT; path=/
Set-Cookie: HAP=DIGITS; expires=Friday, 01-Jan-2010 00:00:00 GMT; path=/
Set-Cookie: hana=mogera; expires=Friday, 01-Jan-2010 00:00:00 GMT; path=/
ν񼰤äơʤ̯͡
Friday,ʤFri,ǤʤȻͤȿƤ櫡


 BeƤtext/javascriptʥե
<html><head><META http-equiv="Content-Type" content="text/html; charset=euc-jp"><title>Be</title>
<script type='text/javascript'>
<!--

document.cookie = 'MDMD=SERVER-DEFINED-OCTETS ; expires=Thu,05-Jan-30 00:00:01 GMT; domain=2ch.net; path=/;';

document.cookie = 'DMDM=' + 'USER-ID' + ' ; expires=Thu,05-Jan-30 00:00:01 GMT;path=/; domain=2ch.net;';

// -->
</script>
</head><body>λ
<hr>餫<a href="/">Ǽ</a>äƤ

ǤäΤϡWdy,θΥڡάƤꡢYEARä




 polling intervalĴˤĤ

HTTP_POLICY_HIGH_THROUGHPUTξϡHTTP_POLICY_LOW_LATENCYξ10
ܤäƤȤɤΤȤ롣

writeΤintervalϼ괺Ȥ롣̤ˤϡᤫ
Ƥʤ


intervalϺǽ1Ϥ롣

poll()̥ǡɤˤʤȡHTTPHandle
HTTPTransport connection;ˤĤơ

connection.read_into_buffer(length);
롣

lengthξ̵(0)ξǤȽǤδѤäƤ뤬
ŪintervalɤäɤȤǤ롣

 length̵ꡢ⤷ϡio_bufΥ礭
read()ηio_bufäѤˤʤäƤ
  io_bufĥǤ
intervalɤä
ᤤäѤޤǳĥξ
intervalĹ

read()ηio_bufʤä顢
intervalû
ġĤȽǤ롣

 lengthꡢġio_bufΥ꾮
read()ηlengthʬɤ߽ФƤ
intervalɤäʤ̿λξ礬¿ġġˡ
  lengthʬɤ߽ФƤʤä顢
intervalû
ġĤȽǤ롣

ʾ¸뤿λŹϺѤϡ
int HTTPHandle::get_prefered_polling_interval_millisec();
֤ͤѤƳ٤ֳ֤褦ˡPollEventManager
NetworkAgentѹɤ

int HTTPHandle::get_poll_event_mask();
ѰդΤǡNetworkAgentHTTPHandle::get_current_proc()ä
νƤ롣̿ξΤ餻륷ʥŬڤȯ
Ԥ뤿ˡNetworkAgentǤ٤stateΤȡɬ
פʥ᥽åɤHTTPHandleʤɤɲäɬפ롣

㤨С
bool HTTPHandle::is_status_available();
bool HTTPHandle::is_headers_available();

NetworkAgentǴ٤stateget_current_proc()֤ƤΤƱ
٤ΤΤˤʤɬפϤʤ



ΤΥ⢭


 libghttpΤƼΤƥץ

 HTTP request
OPTIONS/POST/PUTentity-bodyäɤ
Ƥ椦entity-bodyäƤϤʤ᥽åɤƤ
ġġ
TRACEǤ϶ػߡ
̯


chunked encodingɤ߹߻ξ

0. (chunklast-chunkԤ)
   2 or 3

1. ͥåȥǡɤ߹֤Ǽchunklast-chunkԤ
   ֡
   4 or 5


2. Τޤޤincoming bufferǼchunklast-chunkΥإåĤ
   ֡ʤΤޤޤincoming bufferchunkΥǡɤ
   ⤦Ȥ֡
   8 or 9


3. Τޤޤincoming bufferǤϼchunklast-chunkΥإåĤ
   ʤ
   ͥåȥ塢1


4. ͥåȥǡɤǼchunklast-chunkΥإåĤ
   ֡
   7


5. ͥåȥǡɤǤ⼡chunklast-chunkΥإå
   ʤä֡
   return HTTP_NOT_DONE; 0饹ȡ


7. ͥåȥǡɤ塢chunkΥǡɤ߹⤦Ȥ
   ֡
   10 or 11


8. Τޤޤincoming bufferǸߤchunkΥǡɤ߽֡
   chunkΥĤCRLFޤɤ߽顢0


9. Τޤޤincoming bufferǤϸߤchunkɤ߽ʤᡢͥ
   ȥΥǡɤ߹٤֡
   ͥåȥ塢7


10. ͥåȥǡɤǸߤchunkΥǡɤ߽֡
   chunkΥĤCRLFޤɤ߽顢1


11. ͥåȥǡɤǤ⸽ߤchunkΥǡɤ߽
   ä֡
   return HTTP_NOT_DONE; 9饹ȡ


12. λ(last-chunkޤɤ߽)
13. 顼


 äѤgzipإåäƼǥåʤʤΡ
inflateInit(&zstream);

inflate(&zstream, Z_SYNC_FLUSH);

Z_DATA_ERROR, "incorrect header check"
Ȥʤäġġ



ȼ¤äƤȤϤlibghttpؤʤȤ⤢Τ
κC++ǽľlibochusha˼⤦


 libghttp
  - async⡼ɤǻȤˤ̤ƤʤлȤޤ
    connect()ƥॳ뤬λޤǤNONBLOCKåȤˤǤ
    ʤΤǡФ̵ʾsocketΥॢȤ֤
    롣ϱ¤Τconnect()NONBLOCKˤǤ롣
  - ǤХåեԡ1;ʬɬפˤʤ롣
  - Content-Length32bitɽʤ褦̿¿ʬԲǽ
  - Ʊ̾ʣΥإå˴ؤǸΰİʳΤƤƤޤᡢ
    cookieΰˤʤ餶ʤ
  - ad-hocɲähttpsϢʬȤˤ㤨СϢΥ
    顼б륳ɤ򥯥饤¦ǽ񤳤ȻפäƤǤʤ
    줬¸Ǥ褦libghttp¤ΤϡɤƤcallback١
    ˤʤΤǡAPIʣˤʤ᤮롣



 libghttp
  - ʲ¤ǤȤϤ˴¸ΤΤʤΤǡȯμ֤ʤ롣
  - ɤݲǡץϤʤ˽񤭤䤹



 libghttp򿿻٤ʬ
  - ghttp_request¤Τ濴֤APIŪˤʳϴΤ
    ץߥ󥰤Ǥ롣



 libmodifiedghttpΤƼΤƥץȤˡġ

ʬäƤȤΤǡƧޤ
libmodifiedghttpλȤƹͤ

ǽ˥ݥȤޤȤƤ

1. ٤˼ǡŬ˷ƤΥñ̤
   blockingread()Ԥasync⡼ɤȤΤǽŪˤ˾ޤ
   O_NONBLOCKasync⡼ɥϡǡ̤ˤ˺ڤǡ
   ɤळȤˤʤꡢƥॳ٤ޤꡢηǽ˰
   ƶͿ롣ǽO_NONBLOCK椫O_NONBLOCKѤΤϡ
   ߥ󥰤ˤΤ⤷ʤԲǽäݤconnect()ľ
   O_NONBLOCK᤹ȤΤϡޤƤʤʤȤread()
   ǤϤ⤦ʤ褦

2. Թʻ֤ˤ3ढ롣
   (a) ̾Ǥʤ
   (b) connect()˼Ԥ롣
   (c) ǡžڤʤɤTCPΥॢȤԤ롣

   Ǥ(a)ǰ®ǼԤǤʤ䡹Ԥ
   礬ˤؤ餺ʥߥ󥰤ǥॢȤ
   ñʼʤʤ餯ޡ̤ѰդƥʥФȤ
   getaddrinfo()EAI_SYSTEMerrno=EINTRʼԤ򤵤뤯餤
   ̵꤯Ԥɤʬʤġġ

   (b)O_NONBLOCKconnect()ȯԤƤpoll()writeǽˤʤ
   ԤƤɤpoll()Ǽ˥ॢȤǤ롣

   (c)O_NONBLOCKʤpoll()Ǽ˥ॢȤ롣

   (a)̯ΤǸ󤷤ˤȤơ(b)(c)Թʻ֤褹
   뤿O_NONBLOCKsocketȤ̾ǽ򾷤Τ
   ʤ

   ͤȻפäƤΤϡO_NONBLOCKǥ֥åΤ
   礷Ĥasync⡼ɤǥ뤬˥ॢȻ֤
   ƥॢȤ򶵤Ƥ륹å(PollEventManagerΥå)
   ΥॢȻο񤤤Ȥƥ֥åƤsocketΥեǥ
   ץclose()ƤޤȤʡ֥åƤƤ⡢
   close()줿饨顼ǻߤޤäƤ

3. ͥåȥ򤹤륹åɤϥͥ1Ĥˤ٤
   åɥסǻȤ륹åɿ¤Ƥȡ
   ǿʤͥ󤬥åɿȤϴطʤ³ǽ롣
   ȡåɤȤ꥽˴ؤƵ˴٤ǽ
   롣O_NONBLOCKǥʤ顢֥åϥ
   ɤôʤΤǡϼ˲Ǥ
   դ٤ϡåɿ¤Ʊĥ륳ͥξ¤
   뤳Ȥˤʤȸȡ餯ΤΤ褦ˡåɤ⤷ϥ
   ֤ͥ٤դ褦ˤ٤
