| 60 | |
| 61 | class HeadMiddleware(object): |
| 62 | """ Make a sensible HEAD response """ |
| 63 | |
| 64 | def process_response(self, request, response): |
| 65 | """ |
| 66 | If the request method is HEAD and the response is 200 OK, set the |
| 67 | 'Content-Length' header, and remove the content body. |
| 68 | |
| 69 | It is expected that CommonMiddleware has already processed the response |
| 70 | and added the Content-Length header, which is desirable in the response |
| 71 | to a HEAD request. |
| 72 | """ |
| 73 | if request.method == 'HEAD': |
| 74 | # remove the content |
| 75 | response.content = '' |
| 76 | |
| 77 | return response |