<commit_before># serve2 [![Join the chat at https://gitter.im/joushou/serve2](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/joushou/serve2?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![GoDoc](https://godoc.org/github.com/joushou/serve2?status.svg)](http://godoc.org/github.com/joushou/serve2) [![Build Status](https://travis-ci.org/joushou/serve2.svg?branch=master)](https://travis-ci.org/joushou/serve2)

A protocol detecting server library

serve2 accepts a connection, and runs it through the active ProtocolHandlers, reading the smallest amount of data necessary to identify the protocol. ProtocolHandlers do not need to be certain about how much data they need up front - they can ask for more as needed. A default ProtocolHandler can be used when the server fails to identify the protocol, or one can rely on the default behaviour that closes the socket.

ProtocolHandlers can implement transports themselves, by returning a new net.Conn that will be fed through the protocol detection mechanism again, allowing for transparent support of transports. HTTPS (for HTTP/1.1) is implemented in this manner simply by adding the TLS transport independent of HTTP, leaving HTTP completely unaware of TLS. This also allows for things like SSH over TLS, or any other protocol for that matter.

serve2 comes with a set of ProtocolHandlers ready for consumption, in the form of TLS, HTTP (consuming a http.Handler), ECHO and DISCARD. There is also a very convenient Proxy ProtocolHandler, which instead of managing the protocol itself simply checks for a predefined set of bytes, and when matched, dials a configured service, leaving the actual protocol up to someone else. This is useful for things like SSH.

Ensuring that the read bytes are fed back in is done by ProxyConn, a net.Conn-implementing type with a buffered Read.

# Why?
Well, I always kind of wanted to make something that could understand *everything*. I get those kinds of ideas occasionally. At one point I remembered that idea, and hving gotten caught by the Go fever, I thought I'd try it out in Go, which proved to be very suitable for the idea.

# Uses
Apart from how cool it is to be able to serve everything on any port, it also allows flexibility when firewall rules are present. Ever had to run SSH on port 80 to get through a firewall? You know, annoying corporate networks, or maybe difficulties with annoying ISP's and your home server. Well, now you can still have a nice web server on port 80 and still serve SSH. Or maybe you had a packet inspecting firewall that didn't think that was a good idea? Use openssl's s_client to open a TLS transport to port 443, and SSH to that then!

# Limitations<commit_msg>Add a link to the proto package docs<commit_after># serve2 [![Join the chat at https://gitter.im/joushou/serve2](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/joushou/serve2?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![GoDoc](https://godoc.org/github.com/joushou/serve2?status.svg)](http://godoc.org/github.com/joushou/serve2) [![Build Status](https://travis-ci.org/joushou/serve2.svg?branch=master)](https://travis-ci.org/joushou/serve2)

A protocol detecting server library. For examples. look at the docs for the github.com/joushou/serve2/proto package: [![GoDoc](https://godoc.org/github.com/joushou/serve2/proto?status.svg)](http://godoc.org/github.com/joushou/serve2/proto).

serve2 accepts a connection, and runs it through the active ProtocolHandlers, reading the smallest amount of data necessary to identify the protocol. ProtocolHandlers do not need to be certain about how much data they need up front - they can ask for more as needed. A default ProtocolHandler can be used when the server fails to identify the protocol, or one can rely on the default behaviour that closes the socket.

ProtocolHandlers can implement transports themselves, by returning a new net.Conn that will be fed through the protocol detection mechanism again, allowing for transparent support of transports. HTTPS (for HTTP/1.1) is implemented in this manner simply by adding the TLS transport independent of HTTP, leaving HTTP completely unaware of TLS. This also allows for things like SSH over TLS, or any other protocol for that matter.

serve2 comes with a set of ProtocolHandlers ready for consumption, in the form of TLS, HTTP (consuming a http.Handler), ECHO and DISCARD. There is also a very convenient Proxy ProtocolHandler, which instead of managing the protocol itself simply checks for a predefined set of bytes, and when matched, dials a configured service, leaving the actual protocol up to someone else. This is useful for things like SSH.

Ensuring that the read bytes are fed back in is done by ProxyConn, a net.Conn-implementing type with a buffered Read.

# Why?
Well, I always kind of wanted to make something that could understand *everything*. I get those kinds of ideas occasionally. At one point I remembered that idea, and hving gotten caught by the Go fever, I thought I'd try it out in Go, which proved to be very suitable for the idea.

# Uses
Apart from how cool it is to be able to serve everything on any port, it also allows flexibility when firewall rules are present. Ever had to run SSH on port 80 to get through a firewall? You know, annoying corporate networks, or maybe difficulties with annoying ISP's and your home server. Well, now you can still have a nice web server on port 80 and still serve SSH. Or maybe you had a packet inspecting firewall that didn't think that was a good idea? Use openssl's s_client to open a TLS transport to port 443, and SSH to that then!

# Limitations
{'fraction_non_alphanumeric': 0.06234632946961714, 'fraction_numerical': 0.007551808921671935, 'mean_word_length': 4.770010131712259, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 13, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3967954', 'n_tokens_mistral': 1535, 'n_tokens_neox': 1456, 'n_words': 803}