Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cdn-origin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
easrng
cdn-origin
Commits
d426aae7
Commit
d426aae7
authored
7 years ago
by
Dean
Browse files
Options
Downloads
Patches
Plain Diff
return a Content-Length with file requests
For some reason I forgot to do this or assumed it was done automatically.
parent
b47c9d3c
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cdn-origin.go
+6
-1
6 additions, 1 deletion
cdn-origin.go
weed/seaweed.go
+5
-5
5 additions, 5 deletions
weed/seaweed.go
with
11 additions
and
6 deletions
cdn-origin.go
+
6
−
1
View file @
d426aae7
...
@@ -21,6 +21,9 @@ import (
...
@@ -21,6 +21,9 @@ import (
// version is the current version of cdn-origin.
// version is the current version of cdn-origin.
const
version
=
"0.2.0"
const
version
=
"0.2.0"
// Default SeaweedFS fetch parameters.
const
defaultSeaweedFSQueryParameters
=
""
// HTTP header strings.
// HTTP header strings.
const
(
const
(
accept
=
"accept"
accept
=
"accept"
...
@@ -382,7 +385,7 @@ func requestHandler(ctx *fasthttp.RequestCtx) {
...
@@ -382,7 +385,7 @@ func requestHandler(ctx *fasthttp.RequestCtx) {
}
}
// TODO: ?thumbnail query parameter for images
// TODO: ?thumbnail query parameter for images
statusCode
,
err
:=
seaweed
.
Get
(
ctx
,
backend_file_id
.
String
,
""
)
statusCode
,
contentSize
,
err
:=
seaweed
.
Get
(
ctx
,
backend_file_id
.
String
,
defaultSeaweedFSQueryParameters
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
WithField
(
"err"
,
err
)
.
Warn
(
"failed to retrieve file from SeaweedFS volume server"
)
log
.
WithField
(
"err"
,
err
)
.
Warn
(
"failed to retrieve file from SeaweedFS volume server"
)
ctx
.
SetStatusCode
(
fasthttp
.
StatusInternalServerError
)
ctx
.
SetStatusCode
(
fasthttp
.
StatusInternalServerError
)
...
@@ -398,7 +401,9 @@ func requestHandler(ctx *fasthttp.RequestCtx) {
...
@@ -398,7 +401,9 @@ func requestHandler(ctx *fasthttp.RequestCtx) {
ctx
.
SetStatusCode
(
fasthttp
.
StatusInternalServerError
)
ctx
.
SetStatusCode
(
fasthttp
.
StatusInternalServerError
)
ctx
.
SetContentType
(
"text/plain; charset=utf8"
)
ctx
.
SetContentType
(
"text/plain; charset=utf8"
)
fmt
.
Fprint
(
ctx
,
"500 Internal Server Error"
)
fmt
.
Fprint
(
ctx
,
"500 Internal Server Error"
)
return
}
}
ctx
.
Response
.
Header
.
SetContentLength
(
contentSize
)
case
1
:
// redirect
case
1
:
// redirect
if
!
dest_url
.
Valid
{
if
!
dest_url
.
Valid
{
...
...
This diff is collapsed.
Click to expand it.
weed/seaweed.go
+
5
−
5
View file @
d426aae7
...
@@ -55,10 +55,10 @@ func New(masterURI string, lookupTimeout time.Duration) *Seaweed {
...
@@ -55,10 +55,10 @@ func New(masterURI string, lookupTimeout time.Duration) *Seaweed {
}
}
}
}
func
(
s
*
Seaweed
)
Get
(
writer
io
.
Writer
,
fid
string
,
query
string
)
(
int
,
error
)
{
func
(
s
*
Seaweed
)
Get
(
writer
io
.
Writer
,
fid
string
,
query
string
)
(
int
,
int
,
error
)
{
volumeURL
:=
s
.
lookupVolume
(
strings
.
Split
(
fid
,
","
)[
0
])
volumeURL
:=
s
.
lookupVolume
(
strings
.
Split
(
fid
,
","
)[
0
])
if
volumeURL
==
""
{
if
volumeURL
==
""
{
return
50
0
,
errors
.
New
(
"failed to retrieve volume URL"
)
return
fasthttp
.
StatusInternalServerError
,
0
,
errors
.
New
(
"failed to retrieve volume URL"
)
}
}
requestURL
:=
volumeURL
requestURL
:=
volumeURL
if
!
strings
.
HasPrefix
(
requestURL
,
"http://"
)
&&
!
strings
.
HasPrefix
(
requestURL
,
"https://"
)
{
if
!
strings
.
HasPrefix
(
requestURL
,
"http://"
)
&&
!
strings
.
HasPrefix
(
requestURL
,
"https://"
)
{
...
@@ -85,15 +85,15 @@ func (s *Seaweed) Get(writer io.Writer, fid string, query string) (int, error) {
...
@@ -85,15 +85,15 @@ func (s *Seaweed) Get(writer io.Writer, fid string, query string) (int, error) {
// Perform request
// Perform request
err
:=
fasthttp
.
Do
(
req
,
res
)
err
:=
fasthttp
.
Do
(
req
,
res
)
if
err
!=
nil
{
if
err
!=
nil
{
return
0
,
err
return
0
,
0
,
err
}
}
if
res
.
StatusCode
()
==
fasthttp
.
StatusOK
{
if
res
.
StatusCode
()
==
fasthttp
.
StatusOK
{
if
err
:=
res
.
BodyWriteTo
(
writer
);
err
!=
nil
{
if
err
:=
res
.
BodyWriteTo
(
writer
);
err
!=
nil
{
log
.
WithField
(
"err"
,
err
)
.
Warn
(
"failed to set body writer for response"
)
log
.
WithField
(
"err"
,
err
)
.
Warn
(
"failed to set body writer for response"
)
return
fasthttp
.
StatusInternalServerError
,
err
return
fasthttp
.
StatusInternalServerError
,
0
,
err
}
}
}
}
return
fasthttp
.
StatusOK
,
err
return
fasthttp
.
StatusOK
,
res
.
Header
.
ContentLength
(),
err
}
}
func
(
s
*
Seaweed
)
Ping
()
error
{
func
(
s
*
Seaweed
)
Ping
()
error
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment