Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/speakeasy-api/speakeasy-api-test-service/internal/middleware"
"github.com/speakeasy-api/speakeasy-api-test-service/internal/pagination"
"github.com/speakeasy-api/speakeasy-api-test-service/internal/readonlywriteonly"
"github.com/speakeasy-api/speakeasy-api-test-service/internal/redirects"
"github.com/speakeasy-api/speakeasy-api-test-service/internal/reflect"
"github.com/speakeasy-api/speakeasy-api-test-service/internal/responseHeaders"
"github.com/speakeasy-api/speakeasy-api-test-service/internal/retries"
Expand Down Expand Up @@ -86,6 +87,8 @@ func main() {
r.HandleFunc("/method/post", method.HandlePost).Methods(http.MethodPost)
r.HandleFunc("/method/put", method.HandlePut).Methods(http.MethodPut)
r.HandleFunc("/method/trace", method.HandleTrace).Methods(http.MethodTrace)
r.HandleFunc("/followRedirect/oldPage", redirects.HandleRedirectOldPage).Methods(http.MethodGet)
r.HandleFunc("/followRedirect/newPage", redirects.HandleRedirectNewPage).Methods(http.MethodGet)

oauth2router := r.NewRoute().Subrouter()
oauth2router.Use(middleware.OAuth2)
Expand Down
29 changes: 29 additions & 0 deletions internal/redirects/service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package redirects

import (
"encoding/json"
"net/http"
)

// HandleRedirectOldPage handles the /followRedirect endpoint that returns a 302 redirect
func HandleRedirectOldPage(w http.ResponseWriter, r *http.Request) {
// Set the Location header to the redirect target
w.Header().Set("Location", "/followRedirect/newPage")
// Return 302 Found status
w.WriteHeader(http.StatusFound)
}

// HandleRedirectNewPage handles the /followRedirect/newPage endpoint that returns a 200 with JSON
func HandleRedirectNewPage(w http.ResponseWriter, r *http.Request) {
// Set content type to application/json
w.Header().Set("Content-Type", "application/json")

// Create the response object according to the OpenAPI spec
response := map[string]string{
"name": "John Doe",
}

// Encode and send the JSON response
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(response)
}
Loading