web: Change /rpc to /webrpc

master
Harshavardhana 9 years ago
parent bad2f2afbb
commit fbd02d530d
  1. 2
      server-main.go
  2. 4
      vendor/vendor.json
  3. 65
      web-handlers.go
  4. 6
      web-router.go

@ -148,7 +148,7 @@ func initServerConfig(c *cli.Context) {
// Check server arguments.
func checkServerSyntax(c *cli.Context) {
if !c.Args().Present() || c.Args().First() == "help" {
if c.Args().First() == "help" {
cli.ShowCommandHelpAndExit(c, "server", 1)
}
if len(c.Args()) > 2 {

@ -89,8 +89,8 @@
},
{
"path": "github.com/minio/miniobrowser",
"revision": "baa867d829a5c61a9f347500fc625e3eca78b0f0",
"revisionTime": "2016-04-02T15:35:59-07:00"
"revision": "248ebb823950963e302096cdb0bb8a515eb21161",
"revisionTime": "2016-04-08T01:34:18-07:00"
},
{
"path": "github.com/mitchellh/go-homedir",

@ -51,13 +51,13 @@ func isJWTReqAuthenticated(req *http.Request) bool {
return token.Valid
}
// GenericArgs - empty struct for calls that don't accept arguments
// WebGenericArgs - empty struct for calls that don't accept arguments
// for ex. ServerInfo, GenerateAuth
type GenericArgs struct{}
type WebGenericArgs struct{}
// GenericRep - reply structure for calls for which reply is success/failure
// WebGenericRep - reply structure for calls for which reply is success/failure
// for ex. RemoveObject MakeBucket
type GenericRep struct {
type WebGenericRep struct {
UIVersion string `json:"uiVersion"`
}
@ -71,7 +71,7 @@ type ServerInfoRep struct {
}
// ServerInfo - get server info.
func (web *webAPI) ServerInfo(r *http.Request, args *GenericArgs, reply *ServerInfoRep) error {
func (web *webAPI) ServerInfo(r *http.Request, args *WebGenericArgs, reply *ServerInfoRep) error {
if !isJWTReqAuthenticated(r) {
return &json2.Error{Message: "Unauthorized request"}
}
@ -106,7 +106,7 @@ type DiskInfoRep struct {
}
// DiskInfo - get disk statistics.
func (web *webAPI) DiskInfo(r *http.Request, args *GenericArgs, reply *DiskInfoRep) error {
func (web *webAPI) DiskInfo(r *http.Request, args *WebGenericArgs, reply *DiskInfoRep) error {
if !isJWTReqAuthenticated(r) {
return &json2.Error{Message: "Unauthorized request"}
}
@ -125,7 +125,7 @@ type MakeBucketArgs struct {
}
// MakeBucket - make a bucket.
func (web *webAPI) MakeBucket(r *http.Request, args *MakeBucketArgs, reply *GenericRep) error {
func (web *webAPI) MakeBucket(r *http.Request, args *MakeBucketArgs, reply *WebGenericRep) error {
if !isJWTReqAuthenticated(r) {
return &json2.Error{Message: "Unauthorized request"}
}
@ -152,7 +152,7 @@ type WebBucketInfo struct {
}
// ListBuckets - list buckets api.
func (web *webAPI) ListBuckets(r *http.Request, args *GenericArgs, reply *ListBucketsRep) error {
func (web *webAPI) ListBuckets(r *http.Request, args *WebGenericArgs, reply *ListBucketsRep) error {
if !isJWTReqAuthenticated(r) {
return &json2.Error{Message: "Unauthorized request"}
}
@ -237,7 +237,7 @@ type RemoveObjectArgs struct {
}
// RemoveObject - removes an object.
func (web *webAPI) RemoveObject(r *http.Request, args *RemoveObjectArgs, reply *GenericRep) error {
func (web *webAPI) RemoveObject(r *http.Request, args *RemoveObjectArgs, reply *WebGenericRep) error {
if !isJWTReqAuthenticated(r) {
return &json2.Error{Message: "Unauthorized request"}
}
@ -283,7 +283,7 @@ type GenerateAuthReply struct {
UIVersion string `json:"uiVersion"`
}
func (web webAPI) GenerateAuth(r *http.Request, args *GenericArgs, reply *GenerateAuthReply) error {
func (web webAPI) GenerateAuth(r *http.Request, args *WebGenericArgs, reply *GenerateAuthReply) error {
if !isJWTReqAuthenticated(r) {
return &json2.Error{Message: "Unauthorized request"}
}
@ -344,7 +344,7 @@ type GetAuthReply struct {
}
// GetAuth - return accessKey and secretKey credentials.
func (web *webAPI) GetAuth(r *http.Request, args *GenericArgs, reply *GetAuthReply) error {
func (web *webAPI) GetAuth(r *http.Request, args *WebGenericArgs, reply *GetAuthReply) error {
if !isJWTReqAuthenticated(r) {
return &json2.Error{Message: "Unauthorized request"}
}
@ -387,6 +387,7 @@ func (web *webAPI) Download(w http.ResponseWriter, r *http.Request) {
writeWebErrorResponse(w, errInvalidToken)
return
}
// Add content disposition.
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", filepath.Base(object)))
objReader, err := web.ObjectAPI.GetObject(bucket, object, 0)
@ -402,47 +403,35 @@ func (web *webAPI) Download(w http.ResponseWriter, r *http.Request) {
// writeWebErrorResponse - set HTTP status code and write error description to the body.
func writeWebErrorResponse(w http.ResponseWriter, err error) {
// Handle invalid token as a special case.
if err == errInvalidToken {
w.WriteHeader(http.StatusForbidden)
w.Write([]byte(err.Error()))
return
}
// Convert error type to api error code.
var apiErrCode APIErrorCode
switch err.(type) {
case RootPathFull:
apiErr := getAPIError(ErrRootPathFull)
w.WriteHeader(apiErr.HTTPStatusCode)
w.Write([]byte(apiErr.Description))
apiErrCode = ErrRootPathFull
case BucketNotFound:
apiErr := getAPIError(ErrNoSuchBucket)
w.WriteHeader(apiErr.HTTPStatusCode)
w.Write([]byte(apiErr.Description))
apiErrCode = ErrNoSuchBucket
case BucketNameInvalid:
apiErr := getAPIError(ErrInvalidBucketName)
w.WriteHeader(apiErr.HTTPStatusCode)
w.Write([]byte(apiErr.Description))
apiErrCode = ErrInvalidBucketName
case BadDigest:
apiErr := getAPIError(ErrBadDigest)
w.WriteHeader(apiErr.HTTPStatusCode)
w.Write([]byte(apiErr.Description))
apiErrCode = ErrBadDigest
case IncompleteBody:
apiErr := getAPIError(ErrIncompleteBody)
w.WriteHeader(apiErr.HTTPStatusCode)
w.Write([]byte(apiErr.Description))
apiErrCode = ErrIncompleteBody
case ObjectExistsAsPrefix:
apiErr := getAPIError(ErrObjectExistsAsPrefix)
w.WriteHeader(apiErr.HTTPStatusCode)
w.Write([]byte(apiErr.Description))
apiErrCode = ErrObjectExistsAsPrefix
case ObjectNotFound:
apiErr := getAPIError(ErrNoSuchKey)
w.WriteHeader(apiErr.HTTPStatusCode)
w.Write([]byte(apiErr.Description))
apiErrCode = ErrNoSuchKey
case ObjectNameInvalid:
apiErr := getAPIError(ErrNoSuchKey)
w.WriteHeader(apiErr.HTTPStatusCode)
w.Write([]byte(apiErr.Description))
apiErrCode = ErrNoSuchKey
default:
apiErr := getAPIError(ErrInternalError)
w.WriteHeader(apiErr.HTTPStatusCode)
w.Write([]byte(apiErr.Description))
apiErrCode = ErrInternalError
}
apiErr := getAPIError(apiErrCode)
w.WriteHeader(apiErr.HTTPStatusCode)
w.Write([]byte(apiErr.Description))
}

@ -62,7 +62,7 @@ func registerWebRouter(mux *router.Router, web *webAPI) {
// Initialize a new json2 codec.
codec := json2.NewCodec()
// Minio rpc router
// Minio browser router.
webBrowserRouter := mux.NewRoute().PathPrefix(reservedBucket).Subrouter()
// Initialize json rpc handlers.
@ -71,8 +71,8 @@ func registerWebRouter(mux *router.Router, web *webAPI) {
webRPC.RegisterCodec(codec, "application/json; charset=UTF-8")
webRPC.RegisterService(web, "Web")
// RPC handler at URI - /minio/rpc
webBrowserRouter.Methods("POST").Path("/rpc").Handler(webRPC)
// RPC handler at URI - /minio/webrpc
webBrowserRouter.Methods("POST").Path("/webrpc").Handler(webRPC)
webBrowserRouter.Methods("PUT").Path("/upload/{bucket}/{object:.+}").HandlerFunc(web.Upload)
webBrowserRouter.Methods("GET").Path("/download/{bucket}/{object:.+}").Queries("token", "").HandlerFunc(web.Download)

Loading…
Cancel
Save