Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example-shttp-fileserver #156

Merged
merged 2 commits into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ build: scion-bat \
scion-sensorfetcher scion-sensorserver \
scion-ssh scion-sshd \
example-helloworld \
example-shttp-client example-shttp-server example-shttp-proxy
example-shttp-client example-shttp-server example-shttp-fileserver example-shttp-proxy

clean:
go clean ./...
Expand Down Expand Up @@ -98,6 +98,10 @@ example-shttp-client:
example-shttp-server:
go build -o $(BIN)/$@ ./_examples/shttp/server

.PHONY: example-shttp-fileserver
example-shttp-fileserver:
go build -o $(BIN)/$@ ./_examples/shttp/fileserver

.PHONY: example-shttp-proxy
example-shttp-proxy:
go build -o $(BIN)/$@ ./_examples/shttp/proxy
34 changes: 34 additions & 0 deletions _examples/shttp/fileserver/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2020 ETH Zurich
//
// 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.

// example-shttp-fileserver is a simple HTTP fileserver that serves all files
// and subdirectories under the current working directory.
package main

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

"github.com/netsec-ethz/scion-apps/pkg/shttp"
)

func main() {
port := flag.Uint("p", 443, "port the server listens on")
flag.Parse()

handler := http.FileServer(http.Dir(""))
log.Fatal(shttp.ListenAndServe(fmt.Sprintf(":%d", *port), handler, nil))
}