@@ -457,10 +457,55 @@ incoming events and the `BasicService` we created above.
457
457
458
458
We can now run our new sink.
459
459
460
- Let's run a test HTTP server to accept the responses our sink sends:
460
+ Here is a potential ` simple_http_server.py ` server to accept the responses our sink sends:
461
+
462
+ ``` python
463
+ import http.server
464
+ import socketserver
465
+
466
+
467
+ class RequestHandler (http .server .BaseHTTPRequestHandler ):
468
+ def do_GET (self ):
469
+ # Print the request line and headers
470
+ print (f " Request Line: { self .requestline} " )
471
+ print (" Headers:" )
472
+ for header, value in self .headers.items():
473
+ print (f " { header} : { value} " )
474
+
475
+ # Send a response
476
+ self .send_response(200 )
477
+ self .send_header(' Content-type' , ' text/html' )
478
+ self .end_headers()
479
+ self .wfile.write(b ' GET request received' )
480
+
481
+ def do_POST (self ):
482
+ print (f " Request Line: { self .requestline} " )
483
+ print (" Headers:" )
484
+ for header, value in self .headers.items():
485
+ print (f " { header} : { value} " )
486
+
487
+ content_length = int (self .headers[' Content-Length' ])
488
+ post_data = self .rfile.read(content_length)
489
+ print (f " Body: { post_data.decode(' utf-8' )} " )
490
+
491
+ self .send_response(200 )
492
+ self .send_header(' Content-type' , ' text/html' )
493
+ self .end_headers()
494
+ self .wfile.write(b ' POST request received' )
495
+
496
+
497
+ PORT = 3000
498
+ Handler = RequestHandler
499
+
500
+ with socketserver.TCPServer((" " , PORT ), Handler) as httpd:
501
+ print (f " Serving HTTP on port { PORT } ... " )
502
+ httpd.serve_forever()
503
+ ```
504
+
505
+ Run the server:
461
506
462
507
``` sh
463
- docker run -p 3000:3000 plork/httpdump
508
+ python3 simple_http_server.py
464
509
```
465
510
466
511
Our sink has a new configuration field for the endpoint. Update it to look like:
0 commit comments