MCPcopy Index your code
hub / github.com/aptly-dev/aptly / serveHTTP

Method serveHTTP

s3/server_test.go:142–200  ·  view source on GitHub ↗

serveHTTP serves the S3 protocol.

(w http.ResponseWriter, req *http.Request)

Source from the content-addressed store, hash-verified

140
141// serveHTTP serves the S3 protocol.
142func (srv *Server) serveHTTP(w http.ResponseWriter, req *http.Request) {
143 // ignore error from ParseForm as it's usually spurious.
144 _ = req.ParseForm()
145
146 srv.mu.Lock()
147 defer srv.mu.Unlock()
148
149 if debug {
150 log.Printf("s3test %q %q", req.Method, req.URL)
151 }
152 srv.Requests = append(srv.Requests, Request{req.Method, req.RequestURI})
153 a := &action{
154 srv: srv,
155 w: w,
156 req: req,
157 reqID: fmt.Sprintf("%09X", srv.reqID),
158 }
159 srv.reqID++
160
161 var r resource
162 defer func() {
163 switch err := recover().(type) {
164 case *s3Error:
165 switch r := r.(type) {
166 case objectResource:
167 err.BucketName = r.bucket.name
168 case bucketResource:
169 err.BucketName = r.name
170 }
171 err.RequestID = a.reqID
172 // TODO HostId
173 w.Header().Set("Content-Type", `xml version="1.0" encoding="UTF-8"`)
174 w.WriteHeader(err.statusCode)
175 xmlMarshal(w, err)
176 case nil:
177 default:
178 panic(err)
179 }
180 }()
181
182 r = srv.resourceForURL(req.URL)
183
184 var resp interface{}
185 switch req.Method {
186 case "PUT":
187 resp = r.put(a)
188 case "GET", "HEAD":
189 resp = r.get(a)
190 case "DELETE":
191 resp = r.delete(a)
192 case "POST":
193 resp = r.post(a)
194 default:
195 fatalError(400, "MethodNotAllowed", "unknown http request method %q", req.Method)
196 }
197 if resp != nil && req.Method != "HEAD" {
198 xmlMarshal(w, resp)
199 }

Callers 1

NewServerFunction · 0.95

Calls 9

resourceForURLMethod · 0.95
putMethod · 0.95
getMethod · 0.95
deleteMethod · 0.95
postMethod · 0.95
xmlMarshalFunction · 0.85
fatalErrorFunction · 0.85
PrintfMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected