예제 #1
0
def write_frame(server, frame):
    server.wfile.write(b'--FRAME\r\n')
    server.send_header('Content-Type', 'image/jpeg')
    server.send_header('Content-Length', len(frame))
    server.end_headers()
    server.wfile.write(frame)
    server.wfile.write(b'\r\n')
 def waitForResponse(server):
 #tampilan menunggu hasil scrape
 #khusus untuk ditampilkan jika endpoint diakses melalui web browser
     server.send_response(200)
     server.send_header("Content-type","application/json")
     server.send_header("Access-Control-Allow-Origin", "*")
     server.end_headers()
     wait_message = {'Feedback': 'Account ID not found on database','Message':'Please wait until scraping is finished (2-3 minutes), then reload the page'}
     server.wfile.write(json.dumps(wait_message).encode())
예제 #3
0
def success_header(server, content_type):
    server.send_response(200)
    server.send_header('Age', 0)
    server.send_header('Cache-Control', 'no-cache, private')
    server.send_header('Pragma', 'no-cache')
    server.send_header('Content-Type', content_type)
    server.end_headers()
예제 #4
0
def fetch_img(server, parsed_query):
    img_id = parsed_query['id'][0]
    img = Image.open('img/%s.jpg' % img_id)

    # create file-object in memory
    img_bytes = io.BytesIO()

    # Save jpeg file into bytes buffer
    img.save(img_bytes, 'jpeg')

    # Move to beginning of buffer and write to client.
    img_bytes.seek(0)
    server.send_response(200)
    server.send_header('Content-Type', 'image/jpeg')
    server.end_headers()
    server.wfile.write(img_bytes.read())
예제 #5
0
            def do_POST(server):
                content_type = server.headers.get("Content-Type")
                content_length = server.headers.get("Content-Length")
                if content_type.lower().find("json") == -1:
                    body = cgi.FieldStorage(fp=server.rfile, environ={
                        "REQUEST_METHOD": "POST",
                        "CONTENT_TYPE": content_type,
                        "CONTENT_LENGTH": content_length
                    })
                else:
                    body = json.loads(
                        ensure_str(server.rfile.read(int(content_length))))

                self.received_body = body

                server.send_response(http.server.HTTPStatus.OK)
                server.send_header("Content-Length", "13")
                server.send_header("Content-Type", "text/plain")
                server.end_headers()
                server.wfile.write(b"Hello, World!")
예제 #6
0
 def do_GET(server):
     self.assertEqual(server.request_version, http_version)
     if has_link_args:
         self.assertEqual(server.path, "/get_test/?a=b")
     else:
         self.assertEqual(server.path, "/get_test/")
     if response_by_chunk:
         server.wfile.write(b"HTTP/1.1 200 OK\r\n")
     else:
         server.send_response(http.server.HTTPStatus.OK)
     if not response_by_chunk:
         server.send_header("Content-Length", "13")
     else:
         server.send_header("Transfer-Encoding", "Chunked")
     server.send_header("Content-Type", "text/plain")
     server.end_headers()
     if not response_by_chunk:
         server.wfile.write(b"Hello, World!")
     else:
         server.wfile.write(
             b"7\r\nHello, \r\n6\r\nWorld!\r\n0\r\n\r\n")