Skip to content

Commit

Permalink
feat: Add Lilypad version HTTP header (#408)
Browse files Browse the repository at this point in the history
* feat: Add X-Lilypad-Version header

* chore: Log version header on add resource offer requests
  • Loading branch information
bgins authored Oct 18, 2024
1 parent a8febc0 commit b4e56e3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/http/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/ecdsa"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"io"
stdlog "log"
Expand All @@ -13,6 +14,7 @@ import (
"strings"

"github.com/hashicorp/go-retryablehttp"
"github.com/lilypad-tech/lilypad/pkg/system"
"github.com/lilypad-tech/lilypad/pkg/web3"
"github.com/rs/zerolog/log"
)
Expand All @@ -24,6 +26,9 @@ const X_LILYPAD_USER_HEADER = "X-Lilypad-User"
// this is the signature of the message
const X_LILYPAD_SIGNATURE_HEADER = "X-Lilypad-Signature"

// the version run by the client or service
const X_LILYPAD_VERSION_HEADER = "X-Lilypad-Version"

// the context name we keep the address
const CONTEXT_ADDRESS = "address"

Expand Down Expand Up @@ -100,6 +105,7 @@ func AddHeaders(
}
req.Header.Add(X_LILYPAD_USER_HEADER, userPayload)
req.Header.Add(X_LILYPAD_SIGNATURE_HEADER, userSignature)
req.Header.Add(X_LILYPAD_VERSION_HEADER, system.Version)
return nil
}

Expand Down Expand Up @@ -161,6 +167,14 @@ func GetAddressFromHeaders(req *http.Request) (string, error) {
return signatureAddress, nil
}

func GetVersionFromHeaders(req *http.Request) (string, error) {
versionHeader := req.Header.Get(X_LILYPAD_VERSION_HEADER)
if versionHeader == "" {
return "", errors.New("missing version header")
}
return versionHeader, nil
}

func CorsMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
res.Header().Set("Access-Control-Allow-Origin", "*")
Expand Down
3 changes: 3 additions & 0 deletions pkg/solver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ func (solverServer *solverServer) addJobOffer(jobOffer data.JobOffer, res coreht
}

func (solverServer *solverServer) addResourceOffer(resourceOffer data.ResourceOffer, res corehttp.ResponseWriter, req *corehttp.Request) (*data.ResourceOfferContainer, error) {
versionHeader, _ := http.GetVersionFromHeaders(req)
log.Debug().Msgf("resource provider adding offer with version header %s", versionHeader)

signerAddress, err := http.GetAddressFromHeaders(req)
if err != nil {
log.Error().Err(err).Msgf("have error parsing user address")
Expand Down

0 comments on commit b4e56e3

Please sign in to comment.