|
4 | 4 | "context" |
5 | 5 | "fmt" |
6 | 6 | "net/http" |
7 | | - "net/http/httputil" |
8 | 7 | "net/url" |
9 | 8 | "path/filepath" |
10 | 9 | "strings" |
@@ -424,63 +423,3 @@ func PutBuilds(c *gin.Context) { |
424 | 423 | "mappings": build.Mappings, |
425 | 424 | }) |
426 | 425 | } |
427 | | - |
428 | | -// ProxySymbol proxies presigned S3 URLs to an S3-like |
429 | | -// server. |
430 | | -// |
431 | | -// We parse the payload from the incoming request's query |
432 | | -// string, then construct a new URL by replacing the S3 origin. |
433 | | -// Next, we create a reverse proxy and configure it to pipe |
434 | | -// response back to the original caller. |
435 | | -// |
436 | | -// The original S3 origin used when constructing the presigned |
437 | | -// URL must match the proxied presigned URL. |
438 | | -func ProxySymbol(c *gin.Context) { |
439 | | - payload := c.Query("payload") |
440 | | - if payload == "" { |
441 | | - msg := `need payload for proxying to object store` |
442 | | - c.JSON(http.StatusBadRequest, gin.H{ |
443 | | - "error": msg, |
444 | | - }) |
445 | | - return |
446 | | - } |
447 | | - |
448 | | - config := server.Server.Config |
449 | | - presignedUrl := payload |
450 | | - |
451 | | - // if the payload already contains origin, then |
452 | | - // don't prepend the origin. |
453 | | - if !strings.HasPrefix(payload, config.AWSEndpoint) { |
454 | | - presignedUrl = config.AWSEndpoint + payload |
455 | | - } |
456 | | - |
457 | | - parsed, err := url.Parse(presignedUrl) |
458 | | - if err != nil { |
459 | | - msg := "failed to parse reconstructed presigned url" |
460 | | - fmt.Println(msg, err) |
461 | | - c.JSON(http.StatusInternalServerError, gin.H{ |
462 | | - "error": msg, |
463 | | - }) |
464 | | - return |
465 | | - } |
466 | | - |
467 | | - proxy := httputil.NewSingleHostReverseProxy(parsed) |
468 | | - proxy.Director = func(req *http.Request) { |
469 | | - req.URL.Scheme = parsed.Scheme |
470 | | - req.URL.Host = parsed.Host |
471 | | - req.URL.Path = parsed.Path |
472 | | - req.URL.RawQuery = parsed.RawQuery |
473 | | - req.Host = parsed.Host |
474 | | - |
475 | | - req.Header = c.Request.Header |
476 | | - } |
477 | | - |
478 | | - proxy.ModifyResponse = func(resp *http.Response) error { |
479 | | - if resp.StatusCode != http.StatusOK { |
480 | | - fmt.Printf("Symbol proxy http status: %s\n", resp.Status) |
481 | | - } |
482 | | - return nil |
483 | | - } |
484 | | - |
485 | | - proxy.ServeHTTP(c.Writer, c.Request) |
486 | | -} |
0 commit comments