Compare commits
1 commit
| Author | SHA1 | Date | |
|---|---|---|---|
| 12a595ed74 |
4 changed files with 22 additions and 8 deletions
1
main.go
1
main.go
|
|
@ -117,6 +117,7 @@ func main() {
|
||||||
"server_mode", serverMode,
|
"server_mode", serverMode,
|
||||||
// Generic OBS
|
// Generic OBS
|
||||||
"obs_bucket", defaultObsOpts.BucketName,
|
"obs_bucket", defaultObsOpts.BucketName,
|
||||||
|
"obs_remove_bucket_name", defaultObsOpts.RemoveBucketName,
|
||||||
"obs_redirect_secure", defaultObsOpts.RedirectSecure,
|
"obs_redirect_secure", defaultObsOpts.RedirectSecure,
|
||||||
"obs_host_redirect", defaultObsOpts.HostRedirect,
|
"obs_host_redirect", defaultObsOpts.HostRedirect,
|
||||||
"obs_redirect_code", defaultObsOpts.RedirectCode,
|
"obs_redirect_code", defaultObsOpts.RedirectCode,
|
||||||
|
|
|
||||||
13
obs.go
13
obs.go
|
|
@ -16,11 +16,14 @@ type obsOptions struct {
|
||||||
RedirectCode int // HTTP redirect status code
|
RedirectCode int // HTTP redirect status code
|
||||||
URLExpiry time.Duration
|
URLExpiry time.Duration
|
||||||
HostRedirect string
|
HostRedirect string
|
||||||
|
|
||||||
|
RemoveBucketName bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var defaultObsOpts = obsOptions{
|
var defaultObsOpts = obsOptions{
|
||||||
URLExpiry: maxURLExpiry,
|
URLExpiry: maxURLExpiry,
|
||||||
RedirectCode: http.StatusMovedPermanently, // 301
|
RedirectCode: http.StatusMovedPermanently, // 301
|
||||||
|
RemoveBucketName: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (opts *obsOptions) Bind(fs *flag.FlagSet) (err error) {
|
func (opts *obsOptions) Bind(fs *flag.FlagSet) (err error) {
|
||||||
|
|
@ -64,5 +67,11 @@ func (opts *obsOptions) Bind(fs *flag.FlagSet) (err error) {
|
||||||
vObsUrlExpiry = obsUrlExpiry
|
vObsUrlExpiry = obsUrlExpiry
|
||||||
}
|
}
|
||||||
fs.DurationVar(&opts.URLExpiry, "obs-url-expiry", vObsUrlExpiry, "OBS Redirection URL expiry")
|
fs.DurationVar(&opts.URLExpiry, "obs-url-expiry", vObsUrlExpiry, "OBS Redirection URL expiry")
|
||||||
|
|
||||||
|
var vObsRemoveBucketName = opts.RemoveBucketName
|
||||||
|
if sObsRemoveBucketName := os.Getenv("OBS_REMOVE_BUCKET_NAME"); sObsRemoveBucketName != "" {
|
||||||
|
vObsRemoveBucketName, _ = strconv.ParseBool(sObsRemoveBucketName)
|
||||||
|
}
|
||||||
|
fs.BoolVar(&opts.RemoveBucketName, "obs-remove-bucket-name", vObsRemoveBucketName, "OBS Remove Bucket name from prefix")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -73,9 +73,11 @@ func (s *serverS3) handle(ctx *fasthttp.RequestCtx) {
|
||||||
|
|
||||||
path := ctx.Path()
|
path := ctx.Path()
|
||||||
_path := bytes.TrimLeft(path, "/")
|
_path := bytes.TrimLeft(path, "/")
|
||||||
if _, _pathWithoutBucketName, found := bytes.Cut(_path, []byte(`/`)); found {
|
if s.opts.RemoveBucketName {
|
||||||
// no need to check `isVirtualHostStyle` since this is our own implementation of handling request URI
|
if _, _pathWithoutBucketName, found := bytes.Cut(_path, []byte(`/`)); found {
|
||||||
_path = _pathWithoutBucketName
|
// no need to check `isVirtualHostStyle` since this is our own implementation of handling request URI
|
||||||
|
_path = _pathWithoutBucketName
|
||||||
|
}
|
||||||
}
|
}
|
||||||
objectName := unsafeByteSliceToString(_path)
|
objectName := unsafeByteSliceToString(_path)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -62,9 +62,11 @@ func (s *serverStorj) handle(ctx *fasthttp.RequestCtx) {
|
||||||
bucketName := s.opts.BucketName
|
bucketName := s.opts.BucketName
|
||||||
path := ctx.Path()
|
path := ctx.Path()
|
||||||
_path := bytes.TrimLeft(path, "/")
|
_path := bytes.TrimLeft(path, "/")
|
||||||
if _, _pathWithoutBucketName, found := bytes.Cut(_path, []byte(`/`)); found {
|
if s.opts.RemoveBucketName {
|
||||||
// no need to check `isVirtualHostStyle` since this is our own implementation of handling request URI
|
if _, _pathWithoutBucketName, found := bytes.Cut(_path, []byte(`/`)); found {
|
||||||
_path = _pathWithoutBucketName
|
// no need to check `isVirtualHostStyle` since this is our own implementation of handling request URI
|
||||||
|
_path = _pathWithoutBucketName
|
||||||
|
}
|
||||||
}
|
}
|
||||||
objectName := unsafeByteSliceToString(_path)
|
objectName := unsafeByteSliceToString(_path)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue