Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. function new = () => ({
  2. _struct: "Conn",
  3. host: null,
  4. path: null,
  5. port: null,
  6. scheme: null,
  7. params: {},
  8. requestHeaders: [],
  9. responseHeaders: [],
  10. responseBody: {},
  11. status: null
  12. })
  13.  
  14. function putHost = (conn, host) => ({...user, name: name})
  15.  
  16. function putRequestHeaders = (conn, ...headers) => ({...conn, requestHeaders: [...conn.requestHeaders, ...headers})
  17.  
  18. function putPath = (conn, path) => ({...conn, path: path})
  19.  
  20. function putPort = (conn, port) => ({...conn, port: port})
  21.  
  22. function putScheme = (conn, scheme) => ({...conn, scheme: scheme})
  23.  
  24. function putParams = (conn, params) => ({...conn, params: params})
  25.  
  26. function putStatus = (conn, status) => ({...conn, status: status})
  27.  
  28. function putResponseHeaders = (conn, ...headers) => ({...conn, responseHeaders: [...conn.responseHeaders, ...headers]})
  29.  
  30. function putResponseBody = (conn, body) => ({...conn, responseBody: body})
  31.  
  32. function getHost = (conn) => conn.host
  33.  
  34. function getPath = (conn) => conn.path
  35.  
  36. function getPort = (conn) => conn.port
  37.  
  38. function getScheme = (conn) => conn.scheme
  39.  
  40. function getParams = (conn) => conn.params
  41.  
  42. function getStatus = (conn) => conn.status
  43.  
  44. function getRequestHeaders = (conn) => conn.requestHeaders.reduce((acc, [key, val]) => ({...acc, [key]: val}), {})
  45.  
  46. function getResponseHeaders = (conn) => conn.responseHeaders.reduce((acc, [key, val]) => ({...acc, [key]: val}), {})
  47.  
  48. function getResponseBody = (conn) => conn.responseBody
  49.  
  50. export default {
  51. new,
  52. putHost,
  53. putPath,
  54. putPort,
  55. putScheme,
  56. putParams,
  57. putRequestHeaders,
  58. putResponseHeaders,
  59. putResponseBody,
  60. putStatus,
  61. getHost,
  62. getPath,
  63. getPort,
  64. getScheme,
  65. getParams,
  66. getStatus,
  67. getRequestHeaders,
  68. getResponseHeaders,
  69. getResponseBody
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement