moved http.* into /internal | created upgrader interface in /upgrader

This commit is contained in:
xdrm-brackets 2018-04-25 21:51:53 +02:00
parent 6c8afe8720
commit a85e16e96a
10 changed files with 39 additions and 20 deletions

View File

@ -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)
}

View File

@ -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"

View File

@ -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"
)

View File

@ -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"

View File

@ -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 {

View File

@ -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

26
upgrader/public.go Normal file
View File

@ -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
}

1
upgrader/types.go Normal file
View File

@ -0,0 +1 @@
package upgrader