Skip to content

Commit

Permalink
Merge branch 'release/v1.6.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
jirenius committed Sep 10, 2020
2 parents c6377af + 34793cc commit 8fb65f9
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 14 deletions.
2 changes: 2 additions & 0 deletions docs/res-protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
* [Models](#models)
* [Collections](#collections)
* [Values](#values)
* [Primitives](#primitives)
* [Resource references](#resource-references)
* [Data values](#data-values)
* [Messaging system](#messaging-system)
* [Services](#services)
* [Gateways](#gateways)
Expand Down
17 changes: 10 additions & 7 deletions docs/res-service-protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ It has the following structure:

`<type>.<resourceName>.<method>`

* type - the request type. May be either `access`, `get`, `call`, or `auth`.
* resourceName - the resource name of the [resource ID](res-protocol.md#resource-ids).
* method - the request method. Only used for `call` or `auth` type requests.
* *type* - the request type. May be either `access`, `get`, `call`, or `auth`.
* *resourceName* - the resource name of the [resource ID](res-protocol.md#resource-ids).
* *method* - the request method. Only used for `call` or `auth` type requests.

## Request payload

Expand Down Expand Up @@ -121,9 +121,11 @@ It should contain the following key:

**timeout**
Sets the request timeout. The value is the new timeout in milliseconds calculated from when the requester receives the pre-response. The requester should honor this timeout.
Example payload (15 second timeout):
`timeout:"15000"`
Example payload (15 second timeout):

```text
timeout:"15000"
```

# Request types

Expand Down Expand Up @@ -486,7 +488,7 @@ Payload is defined by the service, and will be passed to the client without alte

# Connection events

Connection events are sent for specific [connection ID's (cid)](#res-protocol.md#connection-ids), and are listened to by the gateways. These events allow for the services to control the state of the connections.
Connection events are sent for specific [connection ID's (cid)](res-protocol.md#connection-ids), and are listened to by the gateways. These events allow for the services to control the state of the connections.

## Connection token event

Expand Down Expand Up @@ -545,7 +547,8 @@ May be omitted.

### Resource name pattern
A resource name pattern is a string used for matching resource names.
The pattern may use the following wild cards:
The pattern may use the following wild cards:

* The asterisk (`*`) matches any part at any level of the resource name.
Eg. `userService.user.*.roles` - Pattern that matches the roles collection of all users.
* The greater than symbol (`>`) matches one or more parts at the end of a resource name, and must be the last part.
Expand Down
6 changes: 3 additions & 3 deletions examples/edit-text/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions examples/hello-world/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions server/apiHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ func (s *Service) apiHandler(w http.ResponseWriter, r *http.Request) {
err := s.setCommonHeaders(w, r)
if r.Method == "OPTIONS" {
w.Header().Set("Access-Control-Allow-Methods", s.cfg.allowMethods)
reqHeaders := r.Header["Access-Control-Request-Headers"]
if len(reqHeaders) > 0 {
w.Header().Set("Access-Control-Allow-Headers", strings.Join(reqHeaders, ", "))
}
return
}
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion server/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "time"

const (
// Version is the current version for the server.
Version = "1.6.0"
Version = "1.6.1"

// ProtocolVersion is the implemented RES protocol version.
ProtocolVersion = "1.2.1"
Expand Down
29 changes: 29 additions & 0 deletions test/21http_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,32 @@ func TestHTTPOptions_AllowOrigin_ExpectedResponseHeaders(t *testing.T) {
})
}
}

func TestHTTPOptions_RequestHeaders_ExpectedResponseHeaders(t *testing.T) {
tbl := []struct {
RequestHeaders []string // Request's Origin header. Empty means no Origin header.
ExpectedHeaders map[string]string // Expected response Headers
ExpectedMissingHeaders []string // Expected response headers not to be included
}{
{[]string{"Content-Type"}, map[string]string{"Access-Control-Allow-Headers": "Content-Type"}, nil},
{[]string{"X-PINGOTHER", "Content-Type"}, map[string]string{"Access-Control-Allow-Headers": "X-PINGOTHER, Content-Type"}, nil},
{[]string{"X-PINGOTHER", "Content-Type", "Authorization"}, map[string]string{"Access-Control-Allow-Headers": "X-PINGOTHER, Content-Type, Authorization"}, nil},
{nil, nil, []string{"Access-Control-Allow-Headers"}},
}

for i, l := range tbl {
l := l
runNamedTest(t, fmt.Sprintf("#%d", i+1), func(s *Session) {
hreq := s.HTTPRequest("OPTIONS", "/api/test/model", nil, func(req *http.Request) {
if len(l.RequestHeaders) > 0 {
req.Header["Access-Control-Request-Headers"] = l.RequestHeaders
}
})
// Validate http response
hreq.GetResponse(t).
Equals(t, http.StatusOK, nil).
AssertHeaders(t, l.ExpectedHeaders).
AssertMissingHeaders(t, l.ExpectedMissingHeaders)
})
}
}

0 comments on commit 8fb65f9

Please sign in to comment.