Skip to content

Commit

Permalink
Init web server and test
Browse files Browse the repository at this point in the history
  • Loading branch information
wille committed Jan 17, 2017
1 parent e13aad7 commit 03a111b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
31 changes: 31 additions & 0 deletions web/web.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package main

import (
"fmt"
"log"
"net/http"
)

func main() {
http.HandleFunc("/upload", handleUpload)

log.Fatal(http.ListenAndServe(":1312", nil))

}

func reject(w http.ResponseWriter, r *http.Request) {
fmt.Println("Rejecting ", r.RemoteAddr)
w.WriteHeader(http.StatusNotFound)
fmt.Fprint(w, http.StatusText(http.StatusNotFound))
}

func handleUpload(w http.ResponseWriter, r *http.Request) {
key := r.PostFormValue("k")

if r.Method != "POST" || key == "" {
reject(w, r)
return
}

fmt.Println(key)
}
4 changes: 3 additions & 1 deletion web_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import (
"testing"
)

const Endpoint = "http://localhost/upload"
const Endpoint = "http://localhost:1312/upload"

func TestWeb(t *testing.T) {
priv := Generate()
key := Stringify(priv)

fmt.Println(key)

_, err := http.PostForm(Endpoint, url.Values{"k": {key}})

if err != nil {
Expand Down

0 comments on commit 03a111b

Please sign in to comment.