@@ -72,15 +72,15 @@ private async Task ReadRequestBody()
7272            if  ( ( WebSession . Request . Method . ToUpper ( )  !=  "POST"  &&  WebSession . Request . Method . ToUpper ( )  !=  "PUT" ) ) 
7373            { 
7474                throw  new  BodyNotFoundException ( "Request don't have a body."  + 
75-                                                 "Please verify that this request is a Http POST/PUT and request content length is greater than zero before accessing the body." ) ; 
75+                                                 "Please verify that this request is a Http POST/PUT and request "  + 
76+                                                 "content length is greater than zero before accessing the body." ) ; 
7677            } 
7778
7879            //Caching check 
7980            if  ( WebSession . Request . RequestBody  ==  null ) 
8081            { 
8182
8283                //If chunked then its easy just read the whole body with the content length mentioned in the request header 
83- 
8484                using  ( var  requestBodyStream  =  new  MemoryStream ( ) ) 
8585                { 
8686                    //For chunked request we need to read data as they arrive, until we reach a chunk end symbol 
@@ -94,13 +94,17 @@ private async Task ReadRequestBody()
9494                        if  ( WebSession . Request . ContentLength  >  0 ) 
9595                        { 
9696                            //If not chunked then its easy just read the amount of bytes mentioned in content length header of response 
97-                             await  this . ProxyClient . ClientStreamReader . CopyBytesToStream ( bufferSize ,  requestBodyStream ,  WebSession . Request . ContentLength ) ; 
97+                             await  this . ProxyClient . ClientStreamReader . CopyBytesToStream ( bufferSize ,  requestBodyStream ,  
98+                                 WebSession . Request . ContentLength ) ; 
9899
99100                        } 
100101                        else  if  ( WebSession . Request . HttpVersion . Major  ==  1  &&  WebSession . Request . HttpVersion . Minor  ==  0 ) 
102+                         { 
101103                            await  WebSession . ServerConnection . StreamReader . CopyBytesToStream ( bufferSize ,  requestBodyStream ,  long . MaxValue ) ; 
104+                         } 
102105                    } 
103-                     WebSession . Request . RequestBody  =  await  GetDecompressedResponseBody ( WebSession . Request . ContentEncoding ,  requestBodyStream . ToArray ( ) ) ; 
106+                     WebSession . Request . RequestBody  =  await  GetDecompressedResponseBody ( WebSession . Request . ContentEncoding ,  
107+                         requestBodyStream . ToArray ( ) ) ; 
104108                } 
105109
106110                //Now set the flag to true 
@@ -130,14 +134,18 @@ private async Task ReadResponseBody()
130134                        if  ( WebSession . Response . ContentLength  >  0 ) 
131135                        { 
132136                            //If not chunked then its easy just read the amount of bytes mentioned in content length header of response 
133-                             await  WebSession . ServerConnection . StreamReader . CopyBytesToStream ( bufferSize ,  responseBodyStream ,  WebSession . Response . ContentLength ) ; 
137+                             await  WebSession . ServerConnection . StreamReader . CopyBytesToStream ( bufferSize ,  responseBodyStream ,  
138+                                 WebSession . Response . ContentLength ) ; 
134139
135140                        } 
136141                        else  if  ( WebSession . Response . HttpVersion . Major  ==  1  &&  WebSession . Response . HttpVersion . Minor  ==  0 ) 
142+                         { 
137143                            await  WebSession . ServerConnection . StreamReader . CopyBytesToStream ( bufferSize ,  responseBodyStream ,  long . MaxValue ) ; 
144+                         } 
138145                    } 
139146
140-                     WebSession . Response . ResponseBody  =  await  GetDecompressedResponseBody ( WebSession . Response . ContentEncoding ,  responseBodyStream . ToArray ( ) ) ; 
147+                     WebSession . Response . ResponseBody  =  await  GetDecompressedResponseBody ( WebSession . Response . ContentEncoding , 
148+                         responseBodyStream . ToArray ( ) ) ; 
141149
142150                } 
143151                //set this to true for caching 
@@ -154,7 +162,9 @@ public async Task<byte[]> GetRequestBody()
154162            if  ( ! WebSession . Request . RequestBodyRead ) 
155163            { 
156164                if  ( WebSession . Request . RequestLocked ) 
165+                 { 
157166                    throw  new  Exception ( "You cannot call this function after request is made to server." ) ; 
167+                 } 
158168
159169                await  ReadRequestBody ( ) ; 
160170            } 
@@ -169,7 +179,9 @@ public async Task<string> GetRequestBodyAsString()
169179            if  ( ! WebSession . Request . RequestBodyRead ) 
170180            { 
171181                if  ( WebSession . Request . RequestLocked ) 
182+                 { 
172183                    throw  new  Exception ( "You cannot call this function after request is made to server." ) ; 
184+                 } 
173185
174186                await  ReadRequestBody ( ) ; 
175187            } 
@@ -184,7 +196,9 @@ public async Task<string> GetRequestBodyAsString()
184196        public  async  Task  SetRequestBody ( byte [ ]  body ) 
185197        { 
186198            if  ( WebSession . Request . RequestLocked ) 
199+             { 
187200                throw  new  Exception ( "You cannot call this function after request is made to server." ) ; 
201+             } 
188202
189203            //syphon out the request body from client before setting the new body 
190204            if  ( ! WebSession . Request . RequestBodyRead ) 
@@ -195,9 +209,13 @@ public async Task SetRequestBody(byte[] body)
195209            WebSession . Request . RequestBody  =  body ; 
196210
197211            if  ( WebSession . Request . IsChunked  ==  false ) 
212+             { 
198213                WebSession . Request . ContentLength  =  body . Length ; 
214+             } 
199215            else 
216+             { 
200217                WebSession . Request . ContentLength  =  - 1 ; 
218+             } 
201219        } 
202220
203221        /// <summary> 
@@ -207,7 +225,9 @@ public async Task SetRequestBody(byte[] body)
207225        public  async  Task  SetRequestBodyString ( string  body ) 
208226        { 
209227            if  ( WebSession . Request . RequestLocked ) 
228+             { 
210229                throw  new  Exception ( "You cannot call this function after request is made to server." ) ; 
230+             } 
211231
212232            //syphon out the request body from client before setting the new body 
213233            if  ( ! WebSession . Request . RequestBodyRead ) 
@@ -226,7 +246,9 @@ public async Task SetRequestBodyString(string body)
226246        public  async  Task < byte [ ] >  GetResponseBody ( ) 
227247        { 
228248            if  ( ! WebSession . Request . RequestLocked ) 
249+             { 
229250                throw  new  Exception ( "You cannot call this function before request is made to server." ) ; 
251+             } 
230252
231253            await  ReadResponseBody ( ) ; 
232254            return  WebSession . Response . ResponseBody ; 
@@ -239,11 +261,14 @@ public async Task<byte[]> GetResponseBody()
239261        public  async  Task < string >  GetResponseBodyAsString ( ) 
240262        { 
241263            if  ( ! WebSession . Request . RequestLocked ) 
264+             { 
242265                throw  new  Exception ( "You cannot call this function before request is made to server." ) ; 
266+             } 
243267
244268            await  GetResponseBody ( ) ; 
245269
246-             return  WebSession . Response . ResponseBodyString  ??  ( WebSession . Response . ResponseBodyString  =  WebSession . Response . Encoding . GetString ( WebSession . Response . ResponseBody ) ) ; 
270+             return  WebSession . Response . ResponseBodyString  ??  
271+                 ( WebSession . Response . ResponseBodyString  =  WebSession . Response . Encoding . GetString ( WebSession . Response . ResponseBody ) ) ; 
247272        } 
248273
249274        /// <summary> 
@@ -253,7 +278,9 @@ public async Task<string> GetResponseBodyAsString()
253278        public  async  Task  SetResponseBody ( byte [ ]  body ) 
254279        { 
255280            if  ( ! WebSession . Request . RequestLocked ) 
281+             { 
256282                throw  new  Exception ( "You cannot call this function before request is made to server." ) ; 
283+             } 
257284
258285            //syphon out the response body from server before setting the new body 
259286            if  ( WebSession . Response . ResponseBody  ==  null ) 
@@ -265,9 +292,13 @@ public async Task SetResponseBody(byte[] body)
265292
266293            //If there is a content length header update it 
267294            if  ( WebSession . Response . IsChunked  ==  false ) 
295+             { 
268296                WebSession . Response . ContentLength  =  body . Length ; 
297+             } 
269298            else 
299+             { 
270300                WebSession . Response . ContentLength  =  - 1 ; 
301+             } 
271302        } 
272303
273304        /// <summary> 
@@ -277,7 +308,9 @@ public async Task SetResponseBody(byte[] body)
277308        public  async  Task  SetResponseBodyString ( string  body ) 
278309        { 
279310            if  ( ! WebSession . Request . RequestLocked ) 
311+             { 
280312                throw  new  Exception ( "You cannot call this function before request is made to server." ) ; 
313+             } 
281314
282315            //syphon out the response body from server before setting the new body 
283316            if  ( WebSession . Response . ResponseBody  ==  null ) 
@@ -308,10 +341,14 @@ private async Task<byte[]> GetDecompressedResponseBody(string encodingType, byte
308341        public  async  Task  Ok ( string  html ) 
309342        { 
310343            if  ( WebSession . Request . RequestLocked ) 
344+             { 
311345                throw  new  Exception ( "You cannot call this function after request is made to server." ) ; 
346+             } 
312347
313348            if  ( html  ==  null ) 
349+             { 
314350                html  =  string . Empty ; 
351+             } 
315352
316353            var  result  =  Encoding . Default . GetBytes ( html ) ; 
317354
@@ -341,7 +378,7 @@ public async Task Redirect(string url)
341378            var  response  =  new  RedirectResponse ( ) ; 
342379
343380            response . HttpVersion  =  WebSession . Request . HttpVersion ; 
344-             response . ResponseHeaders . Add ( new  Models . HttpHeader ( "Location" ,  url ) ) ; 
381+             response . ResponseHeaders . Add ( "Location" ,   new  Models . HttpHeader ( "Location" ,  url ) ) ; 
345382            response . ResponseBody  =  Encoding . ASCII . GetBytes ( string . Empty ) ; 
346383
347384            await  Respond ( response ) ; 
0 commit comments