@@ -62,6 +62,8 @@ func (s *HttpServer) Start(ctx context.Context) {
62
62
handler := http .NewServeMux ()
63
63
handler .HandleFunc (s .payloadBasePath (), s .handleByPayloadCid )
64
64
handler .HandleFunc (s .pieceBasePath (), s .handleByPieceCid )
65
+ handler .HandleFunc ("/" , s .handleIndex )
66
+ handler .HandleFunc ("/index.html" , s .handleIndex )
65
67
s .server = & http.Server {
66
68
Addr : listenAddr ,
67
69
Handler : handler ,
@@ -84,6 +86,40 @@ func (s *HttpServer) Stop() error {
84
86
return s .server .Close ()
85
87
}
86
88
89
+ const idxPage = `
90
+ <html>
91
+ <body>
92
+ <h4>Booster HTTP Server</h4>
93
+ Endpoints:
94
+ <table>
95
+ <tbody>
96
+ <tr>
97
+ <td>
98
+ Download a CAR file by payload CID
99
+ </td>
100
+ <td>
101
+ <a href="/payload/payloadcid">/payload/<payload cid></a>
102
+ </td>
103
+ </tr>
104
+ <tr>
105
+ <td>
106
+ Download a CAR file by piece CID
107
+ </td>
108
+ <td>
109
+ <a href="/piece/piececid">/piece/<piece cid></a>
110
+ </td>
111
+ </tr>
112
+ </tbody>
113
+ </table>
114
+ </body>
115
+ </html>
116
+ `
117
+
118
+ func (s * HttpServer ) handleIndex (w http.ResponseWriter , r * http.Request ) {
119
+ w .WriteHeader (http .StatusOK )
120
+ w .Write ([]byte (idxPage )) //nolint:errcheck
121
+ }
122
+
87
123
func (s * HttpServer ) handleByPayloadCid (w http.ResponseWriter , r * http.Request ) {
88
124
prefixLen := len (s .payloadBasePath ())
89
125
if len (r .URL .Path ) <= prefixLen {
@@ -92,7 +128,8 @@ func (s *HttpServer) handleByPayloadCid(w http.ResponseWriter, r *http.Request)
92
128
return
93
129
}
94
130
95
- payloadCidStr := r .URL .Path [prefixLen :]
131
+ fileName := r .URL .Path [prefixLen :]
132
+ payloadCidStr := strings .Replace (fileName , ".car" , "" , 1 )
96
133
payloadCid , err := cid .Parse (payloadCidStr )
97
134
if err != nil {
98
135
msg := fmt .Sprintf ("parsing payload CID '%s': %s" , payloadCidStr , err .Error ())
0 commit comments