PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
happyhttp::Response Class Reference

#include <happyhttp.h>

Public Member Functions

const char * getheader (const char *name) const
 
bool completed () const
 
int getstatus () const
 
const char * getreason () const
 
bool willclose () const
 

Protected Member Functions

 Response (const char *method, Connection &conn)
 
int pump (const unsigned char *data, int datasize)
 
void notifyconnectionclosed ()
 

Friends

class Connection
 

Detailed Description

Definition at line 244 of file happyhttp.h.

Constructor & Destructor Documentation

◆ Response()

happyhttp::Response::Response ( const char *  method,
Connection conn 
)
protected

Definition at line 498 of file happyhttp.cpp.

498 :
499 m_Connection( conn ),
500 m_State( STATUSLINE ),
501 m_Method( method ),
502 m_Version( 0 ),
503 m_Status(0),
504 m_BytesRead(0),
505 m_Chunked(false),
506 m_ChunkLeft(0),
507 m_Length(-1),
508 m_WillClose(false)
509{
510}

Member Function Documentation

◆ completed()

bool happyhttp::Response::completed ( ) const
inline

Definition at line 252 of file happyhttp.h.

253 { return m_State == COMPLETE; }

Referenced by happyhttp::Connection::pump().

◆ getheader()

const char * happyhttp::Response::getheader ( const char *  name) const

Definition at line 513 of file happyhttp.cpp.

514{
515 std::string lname( name );
516// std::transform( lname.begin(), lname.end(), lname.begin(), tolower );
517
518 std::map< std::string, std::string >::const_iterator it = m_Headers.find( lname );
519 if( it == m_Headers.end() )
520 return 0;
521 else
522 return it->second.c_str();
523}

◆ getreason()

const char * happyhttp::Response::getreason ( ) const

Definition at line 534 of file happyhttp.cpp.

535{
536 // only valid once we've got the statusline
537 assert( m_State != STATUSLINE );
538 return m_Reason.c_str();
539}

Referenced by OnBegin().

◆ getstatus()

int happyhttp::Response::getstatus ( ) const

Definition at line 526 of file happyhttp.cpp.

527{
528 // only valid once we've got the statusline
529 assert( m_State != STATUSLINE );
530 return m_Status;
531}

Referenced by OnBegin().

◆ notifyconnectionclosed()

void happyhttp::Response::notifyconnectionclosed ( )
protected

Definition at line 544 of file happyhttp.cpp.

545{
546 if( m_State == COMPLETE )
547 return;
548
549 // eof can be valid...
550 if( m_State == BODY &&
551 !m_Chunked &&
552 m_Length == -1 )
553 {
554 Finish(); // we're all done!
555 }
556 else
557 {
558 throw Wobbly( "Connection closed unexpectedly" );
559 }
560}

Referenced by happyhttp::Connection::pump().

◆ pump()

int happyhttp::Response::pump ( const unsigned char *  data,
int  datasize 
)
protected

Definition at line 564 of file happyhttp.cpp.

565{
566 assert( datasize != 0 );
567 int count = datasize;
568
569 while( count > 0 && m_State != COMPLETE )
570 {
571 if( m_State == STATUSLINE ||
572 m_State == HEADERS ||
573 m_State == TRAILERS ||
574 m_State == CHUNKLEN ||
575 m_State == CHUNKEND )
576 {
577 // we want to accumulate a line
578 while( count > 0 )
579 {
580 char c = (char)*data++;
581 --count;
582 if( c == '\n' )
583 {
584 // now got a whole line!
585 switch( m_State )
586 {
587 case STATUSLINE:
588 ProcessStatusLine( m_LineBuf );
589 break;
590 case HEADERS:
591 ProcessHeaderLine( m_LineBuf );
592 break;
593 case TRAILERS:
594 ProcessTrailerLine( m_LineBuf );
595 break;
596 case CHUNKLEN:
597 ProcessChunkLenLine( m_LineBuf );
598 break;
599 case CHUNKEND:
600 // just soak up the crlf after body and go to next state
601 assert( m_Chunked == true );
602 m_State = CHUNKLEN;
603 break;
604 default:
605 break;
606 }
607 m_LineBuf.clear();
608 break; // break out of line accumulation!
609 }
610 else
611 {
612 if( c != '\r' ) // just ignore CR
613 m_LineBuf += c;
614 }
615 }
616 }
617 else if( m_State == BODY )
618 {
619 int bytesused = 0;
620 if( m_Chunked )
621 bytesused = ProcessDataChunked( data, count );
622 else
623 bytesused = ProcessDataNonChunked( data, count );
624 data += bytesused;
625 count -= bytesused;
626 }
627 }
628
629 // return number of bytes used
630 return datasize - count;
631}
int count
Definition test.cpp:12

References count.

Referenced by happyhttp::Connection::pump().

◆ willclose()

bool happyhttp::Response::willclose ( ) const
inline

Definition at line 263 of file happyhttp.h.

264 { return m_WillClose; }

Friends And Related Symbol Documentation

◆ Connection

friend class Connection
friend

Definition at line 246 of file happyhttp.h.


The documentation for this class was generated from the following files: