@@ -481,6 +481,18 @@ class _HTTPServer: CustomStringConvertible {
481
481
" \r \n " ) . data ( using: . utf8) !
482
482
try tcpSocket. writeRawData ( responseData)
483
483
}
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
+ }
484
496
}
485
497
486
498
struct _HTTPRequest : CustomStringConvertible {
@@ -690,6 +702,8 @@ public class TestURLSessionServer: CustomStringConvertible {
690
702
try httpServer. respondWithUnauthorizedHeader ( )
691
703
} else if req. uri. hasPrefix ( " /web-socket " ) {
692
704
try handleWebSocketRequest ( req)
705
+ } else if req. uri. hasPrefix ( " /accept-encoding " ) {
706
+ try httpServer. respondWithAcceptEncoding ( request: req)
693
707
} else {
694
708
let response = try getResponse ( request: req)
695
709
try httpServer. respond ( with: response)
@@ -852,6 +866,16 @@ public class TestURLSessionServer: CustomStringConvertible {
852
866
" Content-Encoding: gzip " ] . joined ( separator: _HTTPUtils. CRLF) ,
853
867
bodyData: helloWorld)
854
868
}
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
+ }
855
879
856
880
if uri == " /echo-query " {
857
881
let body = request. parameters. map { " \( $0. key) = \( $0. value) " } . joined ( separator: " & " )
0 commit comments