Browse Source

Default to raw response for curl

Les De Ridder 2 years ago
parent
commit
06a85be7da
No known key found for this signature in database
1 changed files with 11 additions and 2 deletions
  1. 11
    2
      app/Http/Controllers/PasteController.php

+ 11
- 2
app/Http/Controllers/PasteController.php View File

@@ -50,7 +50,16 @@ class PasteController extends Controller
50 50
 
51 51
 	public function view(Request $request, Paste $paste)
52 52
 	{
53
-		$format = $request->input('format', 'html'); //TODO: Use HTTP content negotiation for the default format
53
+		//TODO: Use HTTP content negotiation for the default format
54
+		$userAgent = $request->header('User-Agent');
55
+		if(substr($userAgent, 0, 4) == 'curl')
56
+		{
57
+			$format = $request->input('format', 'raw'); //default to raw format for curl
58
+		}
59
+		else
60
+		{
61
+			$format = $request->input('format', 'html'); //default to html format for other user agents
62
+		}
54 63
 
55 64
 		switch($format)
56 65
 		{
@@ -59,7 +68,7 @@ class PasteController extends Controller
59 68
 			case 'raw':
60 69
 				return $this->view_raw($paste);
61 70
 			case 'json':
62
-				return $this->view_json($paste); 
71
+				return $this->view_json($paste);
63 72
 			case 'latex':
64 73
 				return $this->view_latex($paste);
65 74
 			case 'png':

Loading…
Cancel
Save