(self, event: events.Event)
| 846 | |
| 847 | @expect(RequestData, RequestEndOfMessage, events.Event) |
| 848 | def passthrough(self, event: events.Event) -> layer.CommandGenerator[None]: |
| 849 | assert self.flow.response |
| 850 | assert self.child_layer |
| 851 | # HTTP events -> normal connection events |
| 852 | if isinstance(event, RequestData): |
| 853 | event = events.DataReceived(self.context.client, event.data) |
| 854 | elif isinstance(event, ResponseData): |
| 855 | event = events.DataReceived(self.context.server, event.data) |
| 856 | elif isinstance(event, RequestEndOfMessage): |
| 857 | event = events.ConnectionClosed(self.context.client) |
| 858 | elif isinstance(event, ResponseEndOfMessage): |
| 859 | event = events.ConnectionClosed(self.context.server) |
| 860 | |
| 861 | for command in self.child_layer.handle_event(event): |
| 862 | # normal connection events -> HTTP events |
| 863 | if isinstance(command, commands.SendData): |
| 864 | if command.connection == self.context.client: |
| 865 | yield SendHttp( |
| 866 | ResponseData(self.stream_id, command.data), self.context.client |
| 867 | ) |
| 868 | elif ( |
| 869 | command.connection == self.context.server |
| 870 | and self.flow.response.status_code == 101 |
| 871 | ): |
| 872 | # there only is a HTTP server connection if we have switched protocols, |
| 873 | # not if a connection is established via CONNECT. |
| 874 | yield SendHttp( |
| 875 | RequestData(self.stream_id, command.data), self.context.server |
| 876 | ) |
| 877 | else: |
| 878 | yield command |
| 879 | elif isinstance(command, commands.CloseConnection): |
| 880 | if command.connection == self.context.client: |
| 881 | yield SendHttp( |
| 882 | ResponseProtocolError( |
| 883 | self.stream_id, "EOF", ErrorCode.PASSTHROUGH_CLOSE |
| 884 | ), |
| 885 | self.context.client, |
| 886 | ) |
| 887 | elif ( |
| 888 | command.connection == self.context.server |
| 889 | and self.flow.response.status_code == 101 |
| 890 | ): |
| 891 | yield SendHttp( |
| 892 | RequestProtocolError( |
| 893 | self.stream_id, "EOF", ErrorCode.PASSTHROUGH_CLOSE |
| 894 | ), |
| 895 | self.context.server, |
| 896 | ) |
| 897 | else: |
| 898 | # If we are running TCP over HTTP we want to be consistent with half-closes. |
| 899 | # The easiest approach for this is to just always full close for now. |
| 900 | # Alternatively, we could signal that we want a half close only through ResponseProtocolError, |
| 901 | # but that is more complex to implement. |
| 902 | if isinstance(command, commands.CloseTcpConnection): |
| 903 | command = commands.CloseConnection(command.connection) |
| 904 | yield command |
| 905 | else: |
nothing calls this directly
no test coverage detected