Lines 61-67
Link Here
|
61 |
{ |
61 |
{ |
62 |
} |
62 |
} |
63 |
|
63 |
|
64 |
void header::read_header(function<bool(string*)> f) |
64 |
void header::read_header(pfi::lang::function<bool(string*)> f) |
65 |
{ |
65 |
{ |
66 |
string line, key, val; |
66 |
string line, key, val; |
67 |
if (!f(&line)) |
67 |
if (!f(&line)) |
Lines 124-130
Link Here
|
124 |
return sock->getline(*str, line_limit); |
124 |
return sock->getline(*str, line_limit); |
125 |
} |
125 |
} |
126 |
|
126 |
|
127 |
header::header(shared_ptr<stream_socket> sock) |
127 |
header::header(pfi::lang::shared_ptr<stream_socket> sock) |
128 |
{ |
128 |
{ |
129 |
read_header(bind(&socket_getline, sock.get(), _1, line_limit)); |
129 |
read_header(bind(&socket_getline, sock.get(), _1, line_limit)); |
130 |
} |
130 |
} |
Lines 211-217
Link Here
|
211 |
return dat.end(); |
211 |
return dat.end(); |
212 |
} |
212 |
} |
213 |
|
213 |
|
214 |
void header::send(shared_ptr<stream_socket> sock) |
214 |
void header::send(pfi::lang::shared_ptr<stream_socket> sock) |
215 |
{ |
215 |
{ |
216 |
for (int i=0;i<(int)dat.size();i++){ |
216 |
for (int i=0;i<(int)dat.size();i++){ |
217 |
string line=dat[i].first+": "+dat[i].second+"\r\n"; |
217 |
string line=dat[i].first+": "+dat[i].second+"\r\n"; |
Lines 228-234
Link Here
|
228 |
public: |
228 |
public: |
229 |
typedef C char_type; |
229 |
typedef C char_type; |
230 |
|
230 |
|
231 |
basic_httpbody_chunked_streambuf(shared_ptr<stream_socket> sock) |
231 |
basic_httpbody_chunked_streambuf(pfi::lang::shared_ptr<stream_socket> sock) |
232 |
: sock(sock) |
232 |
: sock(sock) |
233 |
, chunk_rest(0) |
233 |
, chunk_rest(0) |
234 |
, buf(buf_size) |
234 |
, buf(buf_size) |
Lines 321-327
Link Here
|
321 |
iss>>hex>>chunk_rest; |
321 |
iss>>hex>>chunk_rest; |
322 |
} |
322 |
} |
323 |
|
323 |
|
324 |
shared_ptr<stream_socket> sock; |
324 |
pfi::lang::shared_ptr<stream_socket> sock; |
325 |
|
325 |
|
326 |
int chunk_rest; |
326 |
int chunk_rest; |
327 |
|
327 |
|
Lines 334-340
Link Here
|
334 |
public: |
334 |
public: |
335 |
typedef C char_type; |
335 |
typedef C char_type; |
336 |
|
336 |
|
337 |
basic_httpbody_streambuf(shared_ptr<stream_socket> sock, int length) |
337 |
basic_httpbody_streambuf(pfi::lang::shared_ptr<stream_socket> sock, int length) |
338 |
: sock(sock) |
338 |
: sock(sock) |
339 |
, rest(length) |
339 |
, rest(length) |
340 |
, buf(T::eof()){ |
340 |
, buf(T::eof()){ |
Lines 359-365
Link Here
|
359 |
} |
359 |
} |
360 |
|
360 |
|
361 |
private: |
361 |
private: |
362 |
shared_ptr<stream_socket> sock; |
362 |
pfi::lang::shared_ptr<stream_socket> sock; |
363 |
|
363 |
|
364 |
int rest; |
364 |
int rest; |
365 |
int buf; |
365 |
int buf; |
Lines 368-374
Link Here
|
368 |
template <class C, class T=char_traits<C> > |
368 |
template <class C, class T=char_traits<C> > |
369 |
class basic_httpbody_chunked_stream : public basic_iostream<C,T>{ |
369 |
class basic_httpbody_chunked_stream : public basic_iostream<C,T>{ |
370 |
public: |
370 |
public: |
371 |
basic_httpbody_chunked_stream(shared_ptr<stream_socket> sock) |
371 |
basic_httpbody_chunked_stream(pfi::lang::shared_ptr<stream_socket> sock) |
372 |
: basic_iostream<C,T>() |
372 |
: basic_iostream<C,T>() |
373 |
, buf(sock){ |
373 |
, buf(sock){ |
374 |
this->init(&buf); |
374 |
this->init(&buf); |
Lines 380-386
Link Here
|
380 |
template <class C, class T=char_traits<C> > |
380 |
template <class C, class T=char_traits<C> > |
381 |
class basic_httpbody_stream : public basic_iostream<C,T>{ |
381 |
class basic_httpbody_stream : public basic_iostream<C,T>{ |
382 |
public: |
382 |
public: |
383 |
basic_httpbody_stream(shared_ptr<stream_socket> sock, int len) |
383 |
basic_httpbody_stream(pfi::lang::shared_ptr<stream_socket> sock, int len) |
384 |
: basic_iostream<C,T>() |
384 |
: basic_iostream<C,T>() |
385 |
, buf(sock, len){ |
385 |
, buf(sock, len){ |
386 |
this->init(&buf); |
386 |
this->init(&buf); |
Lines 406-412
Link Here
|
406 |
{ |
406 |
{ |
407 |
} |
407 |
} |
408 |
|
408 |
|
409 |
request::request(shared_ptr<stream_socket> sock) |
409 |
request::request(pfi::lang::shared_ptr<stream_socket> sock) |
410 |
: method_("") |
410 |
: method_("") |
411 |
, uri_("/") |
411 |
, uri_("/") |
412 |
, version_(1,1) |
412 |
, version_(1,1) |
Lines 438-448
Link Here
|
438 |
|
438 |
|
439 |
// body |
439 |
// body |
440 |
if (cicmp(header_["Transfer-Encoding"],"chunked")) |
440 |
if (cicmp(header_["Transfer-Encoding"],"chunked")) |
441 |
stream=shared_ptr<iostream>(new basic_httpbody_chunked_stream<char>(sock)); |
441 |
stream=pfi::lang::shared_ptr<iostream>(new basic_httpbody_chunked_stream<char>(sock)); |
442 |
else if (header_["Content-Length"]!="") |
442 |
else if (header_["Content-Length"]!="") |
443 |
stream=shared_ptr<iostream>(new basic_httpbody_stream<char>(sock, lexical_cast<int>(header_["Content-Length"]))); |
443 |
stream=pfi::lang::shared_ptr<iostream>(new basic_httpbody_stream<char>(sock, lexical_cast<int>(header_["Content-Length"]))); |
444 |
else |
444 |
else |
445 |
stream=shared_ptr<iostream>(new socketstream(sock)); |
445 |
stream=pfi::lang::shared_ptr<iostream>(new socketstream(sock)); |
446 |
} |
446 |
} |
447 |
|
447 |
|
448 |
request::~request() |
448 |
request::~request() |
Lines 474-480
Link Here
|
474 |
return *stream; |
474 |
return *stream; |
475 |
} |
475 |
} |
476 |
|
476 |
|
477 |
void request::send(shared_ptr<stream_socket> sock) |
477 |
void request::send(pfi::lang::shared_ptr<stream_socket> sock) |
478 |
{ |
478 |
{ |
479 |
stringstream *ss=dynamic_cast<stringstream*>(stream.get()); |
479 |
stringstream *ss=dynamic_cast<stringstream*>(stream.get()); |
480 |
if (!ss) throw http_exception("body is not stringstream"); |
480 |
if (!ss) throw http_exception("body is not stringstream"); |
Lines 499-505
Link Here
|
499 |
if (sock->flush()>=0) |
499 |
if (sock->flush()>=0) |
500 |
throw http_exception("flush failed"); |
500 |
throw http_exception("flush failed"); |
501 |
if (dat.length()==0) |
501 |
if (dat.length()==0) |
502 |
stream=shared_ptr<iostream>(new socketstream(sock)); |
502 |
stream=pfi::lang::shared_ptr<iostream>(new socketstream(sock)); |
503 |
} |
503 |
} |
504 |
|
504 |
|
505 |
response::response() |
505 |
response::response() |
Lines 518-524
Link Here
|
518 |
{ |
518 |
{ |
519 |
} |
519 |
} |
520 |
|
520 |
|
521 |
response::response(shared_ptr<stream_socket> sock) |
521 |
response::response(pfi::lang::shared_ptr<stream_socket> sock) |
522 |
{ |
522 |
{ |
523 |
// status-line |
523 |
// status-line |
524 |
{ |
524 |
{ |
Lines 546-556
Link Here
|
546 |
|
546 |
|
547 |
// body |
547 |
// body |
548 |
if (cicmp(header_["Transfer-Encoding"],"chunked")) |
548 |
if (cicmp(header_["Transfer-Encoding"],"chunked")) |
549 |
stream=shared_ptr<iostream>(new basic_httpbody_chunked_stream<char>(sock)); |
549 |
stream=pfi::lang::shared_ptr<iostream>(new basic_httpbody_chunked_stream<char>(sock)); |
550 |
else if (header_["Content-Length"]!="") |
550 |
else if (header_["Content-Length"]!="") |
551 |
stream=shared_ptr<iostream>(new basic_httpbody_stream<char>(sock, lexical_cast<int>(header_["Content-Length"]))); |
551 |
stream=pfi::lang::shared_ptr<iostream>(new basic_httpbody_stream<char>(sock, lexical_cast<int>(header_["Content-Length"]))); |
552 |
else |
552 |
else |
553 |
stream=shared_ptr<iostream>(new socketstream(sock)); |
553 |
stream=pfi::lang::shared_ptr<iostream>(new socketstream(sock)); |
554 |
} |
554 |
} |
555 |
|
555 |
|
556 |
response::~response() |
556 |
response::~response() |
Lines 582-588
Link Here
|
582 |
return *stream; |
582 |
return *stream; |
583 |
} |
583 |
} |
584 |
|
584 |
|
585 |
void response::send(shared_ptr<stream_socket> sock) |
585 |
void response::send(pfi::lang::shared_ptr<stream_socket> sock) |
586 |
{ |
586 |
{ |
587 |
stringstream *ss=dynamic_cast<stringstream*>(stream.get()); |
587 |
stringstream *ss=dynamic_cast<stringstream*>(stream.get()); |
588 |
if (!ss) throw http_exception("body is not stringstream"); |
588 |
if (!ss) throw http_exception("body is not stringstream"); |
Lines 607-613
Link Here
|
607 |
if (sock->flush()>=0) |
607 |
if (sock->flush()>=0) |
608 |
throw http_exception("flush failed"); |
608 |
throw http_exception("flush failed"); |
609 |
if (dat.length()==0) |
609 |
if (dat.length()==0) |
610 |
stream=shared_ptr<iostream>(new socketstream(sock)); |
610 |
stream=pfi::lang::shared_ptr<iostream>(new socketstream(sock)); |
611 |
} |
611 |
} |
612 |
|
612 |
|
613 |
} // http |
613 |
} // http |