HttpRequest and HttpResponse consists of two parts, HttpMeta and HttpBody
HttpMeta is “Lazy loading”, which means that when generating the HttpMeta, it will just fetch all data as unparsed from the Buffered Reader and store it in a HashMap: <String, String>
.
Where when user tries to use the associated method, such as get_content_type()
, starberry will do the following things
(1): Check whether content_type has been cached (2): If it is being cached, directly return the cached data. IT WILL NOT CHECK WHETHER THE HASHMAP HAS BEEN MODIFIED, since the hashmap is designed to be write for only once, when it is initializing (3): If not, get the String data of content type from the hashmap, and convert it into HttpContentType. Cache it and return the data
The same design is introduced in HttpBody also. The response will not be automatically being parsed. When you call the body getting method such as Rc::form()
or Rc::json()
, it first reads the buffer then store the compiled data into cache.
Since 0.5, the Response and Request shares the same HttpBody and HttpMeta. However in 0.4 these attributes only applies to Request side