Skip to content

Commit

Permalink
Merge pull request #2 from orkunkaraduman/develop
Browse files Browse the repository at this point in the history
v0.2.0
  • Loading branch information
orkunkaraduman authored Aug 4, 2023
2 parents c847ae5 + ca3e814 commit 713a127
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Contributing

under development
47 changes: 46 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,46 @@
# oscdn
# oscdn - Open Source Content Delivery Network

[![Go Reference](https://pkg.go.dev/badge/github.com/orkunkaraduman/oscdn.svg)](https://pkg.go.dev/github.com/orkunkaraduman/oscdn)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=orkunkaraduman_oscdn&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=orkunkaraduman_oscdn)

oscdn is an open-source Content Delivery Network (CDN) software designed to optimize website performance by efficiently
delivering static assets to users worldwide. It supports HTTP/2, partial content serving, and rate limiting, making it
a powerful and versatile solution for content delivery needs.

## Features

- HTTP/2 Support: oscdn leverages the latest HTTP/2 protocol to improve the loading speed and performance of websites,
reducing latency and increasing concurrent connections.

- Partial Content Serving: oscdn allows clients to request only parts of a resource, making it ideal for large files
like videos, audio, or images. This feature enhances the overall user experience and saves bandwidth.

- Rate Limiting: Control and manage traffic flow with rate limiting. oscdn provides configurable rate limits to prevent
abuse and ensure fair usage of resources.

## Getting Started

Follow the steps below to get oscdn up and running on your server:

1. Prerequisites: Ensure you have go with version 1.20 installed on your system.

2. Installation: Install oscdn by running the following command: `go get github.com/orkunkaraduman/oscdn@latest`

3. Configuration: You can view command-line flags and `config.yaml` at this time.

4. Start the Server: Launch the oscdn server by running the following command: `oscdn --store-path=/example/store/path`

## Contributing

We welcome contributions from the community to improve and expand oscdn's capabilities. If you find a bug, have a
feature request, or want to contribute code, please follow our guidelines for contributing (CONTRIBUTING.md) and submit
a pull request.

## License

oscdn is open-source software released under the [BSD 3-Clause License](https://opensource.org/licenses/BSD-3-Clause).

## Acknowledgments

We would like to thank the open-source community and the developers of the libraries and tools that oscdn depends on.
Your contributions help make oscdn a reliable and powerful CDN solution.
9 changes: 8 additions & 1 deletion cdn/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
type Handler struct {
Logger *logng.Logger
Store *store.Store
ServerHeader string
GetHostConfig func(scheme, host string) *HostConfig
}

Expand Down Expand Up @@ -50,6 +51,11 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
return
}

w.Header().Set("Server", "oscdn")
if h.ServerHeader != "" {
w.Header().Set("Server", h.ServerHeader)
}

if (req.URL.Scheme != "http" && req.URL.Scheme != "https") ||
req.URL.Opaque != "" ||
req.URL.User != nil ||
Expand All @@ -73,6 +79,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, req *http.Request) {

contentRange, err := getContentRange(req.Header)
if err != nil {
err = fmt.Errorf("invalid content range: %w", err)
logger.V(1).Error(err)
http.Error(w, "invalid content range", http.StatusBadRequest)
return
Expand Down Expand Up @@ -106,7 +113,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
if hostConfig.HttpsRedirectPort > 0 && hostConfig.HttpsRedirectPort != 443 {
storeURL.Host = fmt.Sprintf("%s:%d", domain, hostConfig.HttpsRedirectPort)
}
//http.Redirect(w, req, storeURL.String(), http.StatusFound)
w.Header().Set("Location", storeURL.String())
http.Error(w, http.StatusText(http.StatusFound), http.StatusFound)
return
}
Expand Down
2 changes: 1 addition & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ origins:
speed.hetzner.de:
useHttps: true
maxSize: 0
maxAge: 60s
maxAge: 5m
downloadBurst: 0
downloadRate: 0

Expand Down
1 change: 1 addition & 0 deletions internal/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type _Flags struct {
StorePath string `default:""`
MaxIdleConns int `default:"100"`
UserAgent string `default:"oscdn"`
ServerHeader string `default:"oscdn"`
Http string `default:":8080"`
Https string `default:":8443"`
Mgmt string `default:":8000"`
Expand Down
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ func main() {
}(_store)

handler := &cdn.Handler{
Logger: logng.WithFieldKeyVals("logger", "cdn handler"),
Store: _store,
Logger: logng.WithFieldKeyVals("logger", "cdn handler"),
Store: _store,
ServerHeader: flags.Flags.ServerHeader,
GetHostConfig: func(scheme, host string) *cdn.HostConfig {
domain, _, _ := httputil.SplitHostPort(host)
d, ok := _config.Domains[domain]
Expand Down

0 comments on commit 713a127

Please sign in to comment.