@@ -481,6 +481,18 @@ class _HTTPServer: CustomStringConvertible {
481481 " \r \n " ) . data ( using: . utf8) !
482482 try tcpSocket. writeRawData ( responseData)
483483 }
484+
485+ func respondWithAcceptEncoding( request: _HTTPRequest ) throws {
486+ var responseData : Data
487+ if let acceptEncoding = request. getHeader ( for: " Accept-Encoding " ) {
488+ let content = acceptEncoding. data ( using: . utf8) !
489+ responseData = " HTTP/1.1 200 OK \r \n Content-Type: text/html; charset=ISO-8859-1 \r \n Content-Length: \( content. count) \r \n \r \n " . data ( using: . utf8) !
490+ responseData. append ( content)
491+ } else {
492+ responseData = " HTTP/1.1 200 OK \r \n Content-Type: text/html; charset=ISO-8859-1 \r \n Content-Length: 0 \r \n \r \n " . data ( using: . utf8) !
493+ }
494+ try tcpSocket. writeRawData ( responseData)
495+ }
484496}
485497
486498struct _HTTPRequest : CustomStringConvertible {
@@ -690,6 +702,8 @@ public class TestURLSessionServer: CustomStringConvertible {
690702 try httpServer. respondWithUnauthorizedHeader ( )
691703 } else if req. uri. hasPrefix ( " /web-socket " ) {
692704 try handleWebSocketRequest ( req)
705+ } else if req. uri. hasPrefix ( " /accept-encoding " ) {
706+ try httpServer. respondWithAcceptEncoding ( request: req)
693707 } else {
694708 let response = try getResponse ( request: req)
695709 try httpServer. respond ( with: response)
@@ -852,6 +866,16 @@ public class TestURLSessionServer: CustomStringConvertible {
852866 " Content-Encoding: gzip " ] . joined ( separator: _HTTPUtils. CRLF) ,
853867 bodyData: helloWorld)
854868 }
869+
870+ if uri == " /brotli-response " {
871+ // This is "Hello World!" brotli encoded.
872+ let helloWorld = Data ( [ 0x8B , 0x05 , 0x80 , 0x48 , 0x65 , 0x6C , 0x6C , 0x6F ,
873+ 0x20 , 0x57 , 0x6F , 0x72 , 0x6C , 0x64 , 0x21 , 0x03 ] )
874+ return _HTTPResponse ( response: . OK,
875+ headers: [ " Content-Length: \( helloWorld. count) " ,
876+ " Content-Encoding: br " ] . joined ( separator: _HTTPUtils. CRLF) ,
877+ bodyData: helloWorld)
878+ }
855879
856880 if uri == " /echo-query " {
857881 let body = request. parameters. map { " \( $0. key) = \( $0. value) " } . joined ( separator: " & " )
0 commit comments