@@ -58,7 +58,7 @@ struct ErrorMiddleware(Middleware):
5858 try :
5959 return self .next.call(context)
6060 except e:
61- return InternalServerError(e.as_bytes() )
61+ return InternalServerError(e)
6262
6363
6464# # Compression middleware compresses the response body.
@@ -164,7 +164,7 @@ struct StaticMiddleware(Middleware):
164164 with open (file , " r" ) as f:
165165 html = f.read()
166166
167- return OK (html.as_bytes() , " text/html" )
167+ return Success (html, " text/html" )
168168 except e:
169169 return self .next.call(context)
170170
@@ -208,46 +208,46 @@ struct RouterMiddleware(Middleware):
208208@value
209209struct NotFoundMiddleware (Middleware ):
210210 fn call (self , context : Context) -> HTTPResponse:
211- return NotFound(String( " Not Found" ).as_bytes() )
211+ return NotFound(" Not Found" )
212212
213213
214214
215215# ## Helper functions to create HTTP responses
216- fn OK (body : Bytes ) -> HTTPResponse:
217- return OK (body, String(" text/plain" ))
216+ fn Success (body : String ) -> HTTPResponse:
217+ return Success (body, String(" text/plain" ))
218218
219- fn OK (body : Bytes , content_type : String) -> HTTPResponse:
219+ fn Success (body : String , content_type : String) -> HTTPResponse:
220220 return HTTPResponse(
221- ResponseHeader(True , 200 , String(" OK " ).as_bytes(), content_type.as_bytes()),
222- body,
221+ ResponseHeader(True , 200 , String(" Success " ).as_bytes(), content_type.as_bytes()),
222+ body.as_bytes() ,
223223 )
224224
225- fn NotFound (body : Bytes ) -> HTTPResponse:
225+ fn NotFound (body : String ) -> HTTPResponse:
226226 return NotFound(body, String(" text/plain" ))
227227
228- fn NotFound (body : Bytes , content_type : String) -> HTTPResponse:
228+ fn NotFound (body : String , content_type : String) -> HTTPResponse:
229229 return HTTPResponse(
230230 ResponseHeader(True , 404 , String(" Not Found" ).as_bytes(), content_type.as_bytes()),
231- body,
231+ body.as_bytes() ,
232232 )
233233
234- fn InternalServerError (body : Bytes ) -> HTTPResponse:
234+ fn InternalServerError (body : String ) -> HTTPResponse:
235235 return InternalServerErrorResponse(body, String(" text/plain" ))
236236
237- fn InternalServerError (body : Bytes , content_type : String) -> HTTPResponse:
237+ fn InternalServerError (body : String , content_type : String) -> HTTPResponse:
238238 return HTTPResponse(
239239 ResponseHeader(True , 500 , String(" Internal Server Error" ).as_bytes(), content_type.as_bytes()),
240- body,
240+ body.as_bytes() ,
241241 )
242242
243- fn Unauthorized (body : Bytes ) -> HTTPResponse:
243+ fn Unauthorized (body : String ) -> HTTPResponse:
244244 return UnauthorizedResponse(body, String(" text/plain" ))
245245
246- fn Unauthorized (body : Bytes , content_type : String) -> HTTPResponse:
246+ fn Unauthorized (body : String , content_type : String) -> HTTPResponse:
247247 var header = ResponseHeader(True , 401 , String(" Unauthorized" ).as_bytes(), content_type.as_bytes())
248248 header.headers[" WWW-Authenticate" ] = " Basic realm=\" Login Required\" "
249249
250250 return HTTPResponse(
251251 header,
252- body,
252+ body.as_bytes() ,
253253 )
0 commit comments