Permalink
Browse files

constant for X-Betamax header

  • Loading branch information...
1 parent 3e926e0 commit b1f62381cb664565d82cf76d2b8c06b093ea0ade Rob Fletcher committed Sep 28, 2012
@@ -1,11 +1,9 @@
package co.freeside.betamax.proxy.handler
-import co.freeside.betamax.Recorder
-import co.freeside.betamax.message.Request
-import co.freeside.betamax.message.Response
-
import java.util.logging.Logger
-
+import co.freeside.betamax.Recorder
+import co.freeside.betamax.message.*
+import static co.freeside.betamax.proxy.jetty.BetamaxProxy.X_BETAMAX
import static java.net.HttpURLConnection.HTTP_FORBIDDEN
import static java.util.logging.Level.INFO
/**
@@ -29,7 +27,7 @@ class TapeReader extends ChainedHttpHandler {
} else if (tape.readable && tape.seek(request)) {
log.log INFO, "Playing back from '$tape.name'"
def response = tape.play(request)
- response.addHeader('X-Betamax', 'PLAY')
+ response.addHeader(X_BETAMAX, 'PLAY')
response
} else if (tape.writable) {
chain(request)
@@ -1,11 +1,9 @@
package co.freeside.betamax.proxy.handler
-import co.freeside.betamax.Recorder
-import co.freeside.betamax.message.Request
-import co.freeside.betamax.message.Response
-
import java.util.logging.Logger
-
+import co.freeside.betamax.Recorder
+import co.freeside.betamax.message.*
+import static co.freeside.betamax.proxy.jetty.BetamaxProxy.X_BETAMAX
import static java.net.HttpURLConnection.HTTP_FORBIDDEN
import static java.util.logging.Level.INFO
@@ -31,7 +29,7 @@ class TapeWriter extends ChainedHttpHandler {
log.log INFO, "Recording to '$tape.name'"
tape.record(request, response)
- response.addHeader('X-Betamax', 'REC')
+ response.addHeader(X_BETAMAX, 'REC')
response
}
@@ -1,22 +1,19 @@
package co.freeside.betamax.proxy.jetty
+import java.util.logging.Logger
+import javax.servlet.http.*
import co.freeside.betamax.message.Response
import co.freeside.betamax.message.servlet.ServletRequestAdapter
-import co.freeside.betamax.proxy.handler.HttpHandler
-import co.freeside.betamax.proxy.handler.ProxyException
+import co.freeside.betamax.proxy.handler.*
import org.eclipse.jetty.server.Request
import org.eclipse.jetty.server.handler.AbstractHandler
-
-import javax.servlet.http.HttpServletRequest
-import javax.servlet.http.HttpServletResponse
-import java.util.logging.Logger
-
import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR
import static java.util.logging.Level.SEVERE
import static org.apache.http.HttpHeaders.VIA
class BetamaxProxy extends AbstractHandler {
+ public static final String X_BETAMAX = 'X-Betamax'
public static final String VIA_HEADER = 'Betamax'
private HttpHandler handlerChain
@@ -17,17 +17,13 @@
package co.freeside.betamax.tape
import co.freeside.betamax.TapeMode
-import co.freeside.betamax.message.Request
-import co.freeside.betamax.message.Response
-import co.freeside.betamax.message.tape.RecordedRequest
-import co.freeside.betamax.message.tape.RecordedResponse
+import co.freeside.betamax.message.*
+import co.freeside.betamax.message.tape.*
import org.yaml.snakeyaml.reader.StreamReader
-
import static TapeMode.READ_WRITE
-import static co.freeside.betamax.MatchRule.method
-import static co.freeside.betamax.MatchRule.uri
+import static co.freeside.betamax.MatchRule.*
+import static co.freeside.betamax.proxy.jetty.BetamaxProxy.X_BETAMAX
import static org.apache.http.HttpHeaders.VIA
-
/**
* Represents a set of recorded HTTP interactions that can be played back or appended to.
*/
@@ -124,7 +120,7 @@ class MemoryTape implements Tape {
def clone = new RecordedResponse()
clone.status = response.status
response.headers.each {
- if (!(it.key in [VIA, 'X-Betamax'])) {
+ if (!(it.key in [VIA, X_BETAMAX])) {
clone.headers[it.key] = it.value
}
}
@@ -5,11 +5,8 @@ import co.freeside.betamax.proxy.jetty.SimpleServer
import co.freeside.betamax.util.server.EchoHandler
import groovyx.net.http.RESTClient
import org.junit.Rule
-import spock.lang.AutoCleanup
-import spock.lang.Shared
-import spock.lang.Specification
-import spock.lang.Stepwise
-
+import spock.lang.*
+import static co.freeside.betamax.proxy.jetty.BetamaxProxy.X_BETAMAX
import static java.net.HttpURLConnection.HTTP_OK
import static org.apache.http.HttpHeaders.VIA
@@ -53,7 +50,7 @@ class AnnotationSpec extends Specification {
then:
response.status == HTTP_OK
response.getFirstHeader(VIA)?.value == 'Betamax'
- response.getFirstHeader('X-Betamax')?.value == 'REC'
+ response.getFirstHeader(X_BETAMAX)?.value == 'REC'
}
@Betamax(tape = 'annotation_spec')
@@ -64,7 +61,7 @@ class AnnotationSpec extends Specification {
then:
response.status == HTTP_OK
response.getFirstHeader(VIA)?.value == 'Betamax'
- response.getFirstHeader('X-Betamax')?.value == 'PLAY'
+ response.getFirstHeader(X_BETAMAX)?.value == 'PLAY'
}
void 'can make unproxied request after using annotation'() {
@@ -5,7 +5,7 @@ import co.freeside.betamax.proxy.jetty.SimpleServer
import co.freeside.betamax.util.server.EchoHandler
import groovyx.net.http.RESTClient
import org.junit.*
-
+import static co.freeside.betamax.proxy.jetty.BetamaxProxy.X_BETAMAX
import static java.net.HttpURLConnection.HTTP_OK
import static org.apache.http.HttpHeaders.VIA
@@ -57,7 +57,7 @@ class AnnotationTest {
assert response.status == HTTP_OK
assert response.getFirstHeader(VIA)?.value == 'Betamax'
- assert response.getFirstHeader('X-Betamax')?.value == 'REC'
+ assert response.getFirstHeader(X_BETAMAX)?.value == 'REC'
}
@Test
@@ -67,7 +67,7 @@ class AnnotationTest {
assert response.status == HTTP_OK
assert response.getFirstHeader(VIA)?.value == 'Betamax'
- assert response.getFirstHeader('X-Betamax')?.value == 'PLAY'
+ assert response.getFirstHeader(X_BETAMAX)?.value == 'PLAY'
}
@Test

0 comments on commit b1f6238

Please sign in to comment.