Suggest you put the user indication to header not body. Then you can use stream to reach your requirements.
NOTE: Next code is base on python2, you can change http server related to python3 related api if you like.
server.py:
import BaseHTTPServer
import time
class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
Page = "Main content here."
def do_GET(self):
self.send_response(200)
self.send_header("Content-Type", "text/html")
self.send_header("Content-Length", str(len(self.Page)))
self.send_header("User-Information", "Fetching module X. Please wait")
self.end_headers()
time.sleep(10)
self.wfile.write(self.Page)
if __name__ == '__main__':
serverAddress = ('', 8080)
server = BaseHTTPServer.HTTPServer(serverAddress, RequestHandler)
server.serve_forever()
client.py:
import requests
r = requests.get('http://127.0.0.1:8080', stream=True)
print(r.headers['User-Information'])
print(r.content)
Explain:
If use stream, the header information will still be fetched by client at once, so you can print it to user at once with print(r.headers['User-Information'])
But with stream, the body information will not transmit, it's be delayed until client use r.content to require it(Response.iter_lines() or Response.iter_content() also ok), so when you do print(r.content), it will need 10 seconds to see the main content as it cost 10s in server code.
Output: (The first line will be shown to user at once, but the second line will be shown 10 seconds later)
Fetching module X. Please wait
Main content here.
Attach the guide for your reference, hope it helpful.