@@ -82,7 +82,7 @@ Tuple<string, string> Header(int i)
8282 /// <summary>
8383 /// Get the HTTP response cache content
8484 /// </summary>
85- public byte [ ] Cache { get { return _cache . Data ; } }
85+ public Buffer Cache { get { return _cache ; } }
8686
8787 /// <summary>
8888 /// Get string from the current HTTP response
@@ -468,8 +468,8 @@ public HttpResponse SetCookie(string name, string value, int maxAge = 86400, str
468468 /// <summary>
469469 /// Set the HTTP response body
470470 /// </summary>
471- /// <param name="body">Body binary content</param>
472- public HttpResponse SetBody ( byte [ ] body )
471+ /// <param name="body">Body string content (default is "") </param>
472+ public HttpResponse SetBody ( string body = "" )
473473 {
474474 // Append content length header
475475 SetHeader ( "Content-Length" , body . Length . ToString ( ) ) ;
@@ -490,8 +490,8 @@ public HttpResponse SetBody(byte[] body)
490490 /// <summary>
491491 /// Set the HTTP response body
492492 /// </summary>
493- /// <param name="body">Body content (default is "") </param>
494- public HttpResponse SetBody ( string body = "" )
493+ /// <param name="body">Body binary content </param>
494+ public HttpResponse SetBody ( byte [ ] body )
495495 {
496496 // Append content length header
497497 SetHeader ( "Content-Length" , body . Length . ToString ( ) ) ;
@@ -509,6 +509,28 @@ public HttpResponse SetBody(string body = "")
509509 return this ;
510510 }
511511
512+ /// <summary>
513+ /// Set the HTTP response body
514+ /// </summary>
515+ /// <param name="body">Body buffer content</param>
516+ public HttpResponse SetBody ( Buffer body )
517+ {
518+ // Append content length header
519+ SetHeader ( "Content-Length" , body . Size . ToString ( ) ) ;
520+
521+ _cache . Append ( "\r \n " ) ;
522+
523+ int index = ( int ) _cache . Size ;
524+
525+ // Append the HTTP response body
526+ _cache . Append ( body . Data , body . Offset , body . Size ) ;
527+ _bodyIndex = index ;
528+ _bodySize = ( int ) body . Size ;
529+ _bodyLength = ( int ) body . Size ;
530+ _bodyLengthProvided = true ;
531+ return this ;
532+ }
533+
512534 /// <summary>
513535 /// Set the HTTP response body length
514536 /// </summary>
@@ -572,7 +594,7 @@ public HttpResponse MakeHeadResponse()
572594 /// <summary>
573595 /// Make GET response
574596 /// </summary>
575- /// <param name="body">Body content (default is "")</param>
597+ /// <param name="body">Body string content (default is "")</param>
576598 public HttpResponse MakeGetResponse ( string body = "" )
577599 {
578600 Clear ( ) ;
@@ -582,6 +604,32 @@ public HttpResponse MakeGetResponse(string body = "")
582604 return this ;
583605 }
584606
607+ /// <summary>
608+ /// Make GET response
609+ /// </summary>
610+ /// <param name="body">Body binary content</param>
611+ public HttpResponse MakeGetResponse ( byte [ ] body )
612+ {
613+ Clear ( ) ;
614+ SetBegin ( 200 ) ;
615+ SetHeader ( "Content-Type" , "text/html; charset=UTF-8" ) ;
616+ SetBody ( body ) ;
617+ return this ;
618+ }
619+
620+ /// <summary>
621+ /// Make GET response
622+ /// </summary>
623+ /// <param name="body">Body buffer content</param>
624+ public HttpResponse MakeGetResponse ( Buffer body )
625+ {
626+ Clear ( ) ;
627+ SetBegin ( 200 ) ;
628+ SetHeader ( "Content-Type" , "text/html; charset=UTF-8" ) ;
629+ SetBody ( body ) ;
630+ return this ;
631+ }
632+
585633 /// <summary>
586634 /// Make OPTIONS response
587635 /// </summary>
@@ -598,7 +646,7 @@ public HttpResponse MakeOptionsResponse(string allow = "HEAD,GET,POST,PUT,DELETE
598646 /// <summary>
599647 /// Make TRACE response
600648 /// </summary>
601- /// <param name="request">Request content</param>
649+ /// <param name="request">Request string content</param>
602650 public HttpResponse MakeTraceResponse ( string request )
603651 {
604652 Clear ( ) ;
@@ -608,6 +656,32 @@ public HttpResponse MakeTraceResponse(string request)
608656 return this ;
609657 }
610658
659+ /// <summary>
660+ /// Make TRACE response
661+ /// </summary>
662+ /// <param name="request">Request binary content</param>
663+ public HttpResponse MakeTraceResponse ( byte [ ] request )
664+ {
665+ Clear ( ) ;
666+ SetBegin ( 200 ) ;
667+ SetHeader ( "Content-Type" , "message/http" ) ;
668+ SetBody ( request ) ;
669+ return this ;
670+ }
671+
672+ /// <summary>
673+ /// Make TRACE response
674+ /// </summary>
675+ /// <param name="request">Request buffer content</param>
676+ public HttpResponse MakeTraceResponse ( Buffer request )
677+ {
678+ Clear ( ) ;
679+ SetBegin ( 200 ) ;
680+ SetHeader ( "Content-Type" , "message/http" ) ;
681+ SetBody ( request ) ;
682+ return this ;
683+ }
684+
611685 // HTTP response status phrase
612686 private int _statusPhraseIndex ;
613687 private int _statusPhraseSize ;
0 commit comments