forked from joewalnes/websocketd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request joewalnes#61 from asergeyev/originchecks
Originchecks per joewalnes#20, closes joewalnes#58 too... --origin and --sameorigin flags added, code refactored to separate some logical parts
- Loading branch information
Showing
17 changed files
with
595 additions
and
262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
|
||
|
||
while true; do | ||
cnt=0 | ||
while read -t 0.01 line; do | ||
cnt=$(($cnt + 1)) | ||
done | ||
|
||
echo `date` "($cnt line(s) received)" | ||
sleep $((RANDOM % 10 + 1)) & wait | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package libwebsocketd | ||
|
||
import ( | ||
"strconv" | ||
"testing" | ||
"time" | ||
) | ||
|
||
var eol_tests = []string{ | ||
"", "\n", "\r\n", "ok\n", "ok\n", | ||
"quite long string for our test\n", | ||
"quite long string for our test\r\n", | ||
} | ||
|
||
var eol_answers = []string{ | ||
"", "", "", "ok", "ok", | ||
"quite long string for our test", "quite long string for our test", | ||
} | ||
|
||
func TestTrimEOL(t *testing.T) { | ||
for n := 0; n < len(eol_tests); n++ { | ||
answ := trimEOL(eol_tests[n]) | ||
if answ != eol_answers[n] { | ||
t.Errorf("Answer '%s' did not match predicted '%s'", answ, eol_answers[n]) | ||
} | ||
} | ||
} | ||
|
||
func BenchmarkTrimEOL(b *testing.B) { | ||
for n := 0; n < b.N; n++ { | ||
trimEOL(eol_tests[n%len(eol_tests)]) | ||
} | ||
} | ||
|
||
type TestEndpoint struct { | ||
limit int | ||
prefix string | ||
c chan string | ||
result []string | ||
} | ||
|
||
func (e *TestEndpoint) StartReading() { | ||
go func() { | ||
for i := 0; i < e.limit; i++ { | ||
e.c <- e.prefix + strconv.Itoa(i) | ||
} | ||
time.Sleep(time.Millisecond) // should be enough for smaller channel to catch up with long one | ||
close(e.c) | ||
}() | ||
} | ||
|
||
func (e *TestEndpoint) Terminate() { | ||
} | ||
|
||
func (e *TestEndpoint) Output() chan string { | ||
return e.c | ||
} | ||
|
||
func (e *TestEndpoint) Send(msg string) bool { | ||
e.result = append(e.result, msg) | ||
return true | ||
} | ||
|
||
func TestEndpointPipe(t *testing.T) { | ||
one := &TestEndpoint{2, "one:", make(chan string), make([]string, 0)} | ||
two := &TestEndpoint{4, "two:", make(chan string), make([]string, 0)} | ||
PipeEndpoints(one, two) | ||
if len(one.result) != 4 || len(two.result) != 2 { | ||
t.Errorf("Invalid lengths, should be 4 and 2: %v %v", one.result, two.result) | ||
} else if one.result[0] != "two:0" || two.result[0] != "one:0" { | ||
t.Errorf("Invalid first results, should be two:0 and one:0: %#v %#v", one.result[0], two.result[0]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.