moved http.* into /internal | created upgrader interface in /upgrader
This commit is contained in:
parent
6c8afe8720
commit
a85e16e96a
|
@ -1,11 +1,11 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"git.xdrm.io/gws/upgrader"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"time"
|
||||
"git.xdrm.io/gws/http/upgrade/request"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -27,8 +27,6 @@ func main() {
|
|||
return
|
||||
}
|
||||
|
||||
fmt.Printf("+ new client\n")
|
||||
|
||||
go manageClient(sock)
|
||||
|
||||
}
|
||||
|
@ -43,26 +41,21 @@ func manageClient(sock net.Conn) {
|
|||
|
||||
for {
|
||||
|
||||
/* (1) Parse request */
|
||||
req, errRq := request.Parse(sock)
|
||||
if errRq != nil { fmt.Printf("Request parsing error: %s\n", errRq) }
|
||||
fmt.Printf("%v\n", req)
|
||||
fmt.Printf("+ new client\n")
|
||||
|
||||
/* (2) Build response */
|
||||
res := req.BuildResponse()
|
||||
fmt.Printf(" + upgrade\n")
|
||||
err := upgrader.Upgrade(sock)
|
||||
|
||||
/* (3) Write into socket */
|
||||
written, err := res.Send(sock)
|
||||
if err != nil {
|
||||
fmt.Printf("WRITE ERROR: %s\n", err);
|
||||
fmt.Printf(" + error: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("Written %d bytes\n", written)
|
||||
fmt.Printf(" + 2-way exchange\n")
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
fmt.Printf("Elapsed: %1.1f us\n", float32(time.Now().UnixNano()-startTime)/1e3)
|
||||
fmt.Printf("+ elapsed: %1.1f us\n", float32(time.Now().UnixNano()-startTime)/1e3)
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package request
|
||||
|
||||
import (
|
||||
"git.xdrm.io/gws/http/upgrade/response"
|
||||
"git.xdrm.io/gws/internal/http/upgrade/response"
|
||||
"git.xdrm.io/gws/internal/http/upgrade/request/parser/header"
|
||||
"fmt"
|
||||
"strconv"
|
|
@ -1,7 +1,7 @@
|
|||
package request
|
||||
|
||||
import (
|
||||
"git.xdrm.io/gws/http/upgrade/response"
|
||||
"git.xdrm.io/gws/internal/http/upgrade/response"
|
||||
"fmt"
|
||||
"git.xdrm.io/gws/internal/http/upgrade/request/parser/header"
|
||||
)
|
|
@ -1,7 +1,7 @@
|
|||
package request
|
||||
|
||||
import (
|
||||
"git.xdrm.io/gws/http/upgrade/response"
|
||||
"git.xdrm.io/gws/internal/http/upgrade/response"
|
||||
"git.xdrm.io/gws/internal/http/reader"
|
||||
"fmt"
|
||||
"io"
|
|
@ -1,7 +1,7 @@
|
|||
package request
|
||||
|
||||
import "git.xdrm.io/gws/internal/http/upgrade/request/parser/reqline"
|
||||
import "git.xdrm.io/gws/http/upgrade/response"
|
||||
import "git.xdrm.io/gws/internal/http/upgrade/response"
|
||||
|
||||
// T represents an HTTP Upgrade request
|
||||
type T struct {
|
|
@ -54,7 +54,6 @@ func (r T) Send(w io.Writer) (int, error) {
|
|||
raw := []byte(fmt.Sprintf("%s%s\r\n", responseLine, headers))
|
||||
|
||||
/* (4) Write */
|
||||
fmt.Printf("Upgrade Response\n----------------\n%s----------------\n", raw)
|
||||
written, err := w.Write(raw)
|
||||
|
||||
return written, err
|
|
@ -0,0 +1,26 @@
|
|||
package upgrader
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.xdrm.io/gws/internal/http/upgrade/request"
|
||||
"net"
|
||||
)
|
||||
|
||||
|
||||
func Upgrade(s net.Conn) error {
|
||||
|
||||
/* (1) Parse request */
|
||||
req, _ := request.Parse(s)
|
||||
|
||||
/* (2) Build response */
|
||||
res := req.BuildResponse()
|
||||
|
||||
/* (3) Write into socket */
|
||||
_, err := res.Send(s)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Socket write: %s", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
package upgrader
|
Loading…
Reference in New Issue