Skip to content

Commit 7011490

Browse files
committed
refactor: remove api header and use only query
1 parent 8e3f97f commit 7011490

4 files changed

Lines changed: 23 additions & 39 deletions

File tree

openapi/Swarm.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2434,7 +2434,7 @@ paths:
24342434
summary: Connect to a pubsub topic via WebSocket
24352435
description: |
24362436
Opens a WebSocket connection to a pubsub topic. The connection acts as either a publisher (read+write)
2437-
or subscriber (read-only) depending on the presence of GSOC headers.
2437+
or subscriber (read-only) depending on the presence of GSOC query params.
24382438
24392439
**WebSocket protocol:**
24402440
- Inbound (client → node, publisher only): raw SOC payload `[sig:65B][span:8B][payload:N B]`

openapi/SwarmCommon.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,28 +1303,28 @@ components:
13031303
description: "ACT history Unix timestamp"
13041304

13051305
SwarmPubsubPeer:
1306-
in: header
1307-
name: swarm-pubsub-peer
1306+
in: query
1307+
name: peer
13081308
schema:
13091309
type: string
13101310
required: true
13111311
description: "Multiaddress of the broker peer to connect to for pubsub"
13121312

13131313
SwarmPubsubGsocEthAddress:
1314-
in: header
1315-
name: swarm-pubsub-gsoc-eth-address
1314+
in: query
1315+
name: gsoc-eth-address
13161316
schema:
13171317
$ref: "#/components/schemas/HexString"
13181318
required: false
1319-
description: "GSOC owner Ethereum address (20 bytes, hex-encoded) for publisher role. Required together with swarm-pubsub-gsoc-topic to upgrade to publisher."
1319+
description: "GSOC owner Ethereum address (20 bytes, hex-encoded) for publisher role. Required together with gsoc-topic to upgrade to publisher."
13201320

13211321
SwarmPubsubGsocTopic:
1322-
in: header
1323-
name: swarm-pubsub-gsoc-topic
1322+
in: query
1323+
name: gsoc-topic
13241324
schema:
13251325
$ref: "#/components/schemas/HexString"
13261326
required: false
1327-
description: "GSOC topic identifier (hex) for publisher role. Required together with swarm-pubsub-gsoc-eth-address to upgrade to publisher."
1327+
description: "GSOC topic identifier (hex) for publisher role. Required together with gsoc-eth-address to upgrade to publisher."
13281328

13291329
responses:
13301330
"200":

pkg/api/api.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,10 @@ const (
9494
SwarmActTimestampHeader = "Swarm-Act-Timestamp"
9595
SwarmActPublisherHeader = "Swarm-Act-Publisher"
9696
SwarmActHistoryAddressHeader = "Swarm-Act-History-Address"
97-
SwarmPubsubPeerHeader = "Swarm-Pubsub-Peer"
98-
SwarmPubsubGsocEthAddressHeader = "Swarm-Pubsub-Gsoc-Eth-Address"
99-
SwarmPubsubGsocTopicHeader = "Swarm-Pubsub-Gsoc-Topic"
100-
101-
ImmutableHeader = "Immutable"
102-
GasPriceHeader = "Gas-Price"
103-
GasLimitHeader = "Gas-Limit"
104-
ETagHeader = "ETag"
97+
ImmutableHeader = "Immutable"
98+
GasPriceHeader = "Gas-Price"
99+
GasLimitHeader = "Gas-Limit"
100+
ETagHeader = "ETag"
105101

106102
AuthorizationHeader = "Authorization"
107103
AcceptEncodingHeader = "Accept-Encoding"
@@ -590,7 +586,6 @@ func (s *Service) corsHandler(h http.Handler) http.Handler {
590586
SwarmRedundancyStrategyHeader, SwarmRedundancyFallbackModeHeader, SwarmChunkRetrievalTimeoutHeader, SwarmLookAheadBufferSizeHeader,
591587
SwarmFeedIndexHeader, SwarmFeedIndexNextHeader, SwarmSocSignatureHeader, SwarmOnlyRootChunk, GasPriceHeader, GasLimitHeader, ImmutableHeader,
592588
SwarmActHeader, SwarmActTimestampHeader, SwarmActPublisherHeader, SwarmActHistoryAddressHeader,
593-
SwarmPubsubPeerHeader, SwarmPubsubGsocEthAddressHeader, SwarmPubsubGsocTopicHeader,
594589
}
595590
allowedHeadersStr := strings.Join(allowedHeaders, ", ")
596591

pkg/api/pubsub.go

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,42 +38,31 @@ func (s *Service) pubsubWsHandler(w http.ResponseWriter, r *http.Request) {
3838
copy(topicAddr[:], h.Sum(nil))
3939
}
4040

41-
// Required: underlay multiaddr — accept from header or query param (browsers cannot set WS headers)
42-
peerHeader := r.Header.Get(SwarmPubsubPeerHeader)
43-
if peerHeader == "" {
44-
peerHeader = r.URL.Query().Get("swarm-pubsub-peer")
45-
}
46-
if peerHeader == "" {
47-
jsonhttp.BadRequest(w, "missing Swarm-Pubsub-Peer header")
41+
peerMultiaddr := r.URL.Query().Get("peer")
42+
if peerMultiaddr == "" {
43+
jsonhttp.BadRequest(w, "missing peer query param")
4844
return
4945
}
50-
underlay, err := ma.NewMultiaddr(peerHeader)
46+
underlay, err := ma.NewMultiaddr(peerMultiaddr)
5147
if err != nil {
52-
logger.Info("invalid peer multiaddr", "value", peerHeader, "error", err)
53-
jsonhttp.BadRequest(w, "invalid Swarm-Pubsub-Peer header")
48+
logger.Info("invalid peer multiaddr", "value", peerMultiaddr, "error", err)
49+
jsonhttp.BadRequest(w, "invalid peer query param")
5450
return
5551
}
5652

57-
// Optional: GSOC fields for Publisher upgrade — accept from header or query param
5853
var connectOpts pubsub.ConnectOptions
5954

60-
gsocEthAddrHex := r.Header.Get(SwarmPubsubGsocEthAddressHeader)
61-
if gsocEthAddrHex == "" {
62-
gsocEthAddrHex = r.URL.Query().Get("swarm-pubsub-gsoc-eth-address")
63-
}
64-
gsocTopicHex := r.Header.Get(SwarmPubsubGsocTopicHeader)
65-
if gsocTopicHex == "" {
66-
gsocTopicHex = r.URL.Query().Get("swarm-pubsub-gsoc-topic")
67-
}
55+
gsocEthAddrHex := r.URL.Query().Get("gsoc-eth-address")
56+
gsocTopicHex := r.URL.Query().Get("gsoc-topic")
6857
if gsocEthAddrHex != "" && gsocTopicHex != "" {
6958
gsocOwner, err := hex.DecodeString(gsocEthAddrHex)
7059
if err != nil {
71-
jsonhttp.BadRequest(w, "invalid Swarm-Pubsub-Gsoc-Eth-Address header")
60+
jsonhttp.BadRequest(w, "invalid gsoc-eth-address query param")
7261
return
7362
}
7463
gsocID, err := hex.DecodeString(gsocTopicHex)
7564
if err != nil {
76-
jsonhttp.BadRequest(w, "invalid Swarm-Pubsub-Gsoc-Topic header")
65+
jsonhttp.BadRequest(w, "invalid gsoc-topic query param")
7766
return
7867
}
7968
connectOpts.GsocOwner = gsocOwner

0 commit comments

Comments
 (0)