perkeep/server/go/blobserver/temp_testing.go

77 lines
1.8 KiB
Go

/*
Copyright 2011 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"camli/httputil"
"crypto/sha1"
"fmt"
"http"
"io"
)
func handleCamliForm(conn http.ResponseWriter, req *http.Request) {
fmt.Fprintf(conn, `
<html>
<body>
<form method='POST' enctype="multipart/form-data" action="/camli/testform">
<input type="hidden" name="имя" value="брэд" />
Text unix: <input type="file" name="file-unix"><br>
Text win: <input type="file" name="file-win"><br>
Text mac: <input type="file" name="file-mac"><br>
Image png: <input type="file" name="image-png"><br>
<input type=submit>
</form>
</body>
</html>
`)
}
func handleTestForm(conn http.ResponseWriter, req *http.Request) {
if !(req.Method == "POST" && req.URL.Path == "/camli/testform") {
httputil.BadRequestError(conn, "Inconfigured handler.")
return
}
multipart, err := req.MultipartReader()
if multipart == nil {
httputil.BadRequestError(conn, fmt.Sprintf("Expected multipart/form-data POST request; %v", err))
return
}
for {
part, err := multipart.NextPart()
if err != nil {
fmt.Println("Error reading:", err)
break
}
if part == nil {
break
}
formName := part.FormName()
fmt.Printf("New value [%s], part=%v\n", formName, part)
sha1 := sha1.New()
io.Copy(sha1, part)
fmt.Printf("Got part digest: %x\n", sha1.Sum())
}
fmt.Println("Done reading multipart body.")
}